Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1165: insert mode lag #1552

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions autoload/UltiSnips.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ if exists("b:did_autoload_ultisnips")
endif
let b:did_autoload_ultisnips = 1

" Ensure snippets are loaded for current buffer
au UltiSnips_AutoTrigger FileType,BufEnter * call UltiSnips#CheckFiletype()

" Also import vim as we expect it to be imported in many places.
py3 import vim
py3 from UltiSnips import UltiSnips_Manager
Expand Down Expand Up @@ -183,6 +186,10 @@ function! UltiSnips#TrackChange() abort
py3 UltiSnips_Manager._track_change()
endfunction

function! UltiSnips#CheckFiletype() abort
py3 UltiSnips_Manager._check_filetype(vim.eval('&ft'))
endfunction

function! UltiSnips#RefreshSnippets() abort
py3 UltiSnips_Manager._refresh_snippets()
endfunction
Expand Down
1 change: 1 addition & 0 deletions pythonx/UltiSnips/snippet/source/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SnippetSource:
def __init__(self):
self._snippets = defaultdict(SnippetDictionary)
self._extends = defaultdict(set)
self.must_ensure = True

def ensure(self, filetypes):
"""Ensures that snippets are loaded."""
Expand Down
8 changes: 5 additions & 3 deletions pythonx/UltiSnips/snippet/source/file/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def __init__(self):
SnippetSource.__init__(self)

def ensure(self, filetypes):
for ft in self.get_deep_extends(filetypes):
if self._needs_update(ft):
self._load_snippets_for(ft)
if self.must_ensure:
for ft in self.get_deep_extends(filetypes):
if self._needs_update(ft):
self._load_snippets_for(ft)
self.must_ensure = False

def refresh(self):
self.__init__()
Expand Down
10 changes: 10 additions & 0 deletions pythonx/UltiSnips/snippet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def __init__(self, expand_trigger, forward_trigger, backward_trigger):
self._visual_content = VisualContentPreserver()

self._snippet_sources = []
self._filetypes = []

self._snip_expanded_in_action = False
self._inside_action = False
Expand Down Expand Up @@ -975,6 +976,15 @@ def _refresh_snippets(self):
source.refresh()


@err_to_scratch_buffer.wrap
def _check_filetype(self, ft):
"""Ensure snippets are loaded for the current filetype."""
if ft not in self._filetypes:
self._filetypes.append(ft)
for _, source in self._snippet_sources:
source.must_ensure = True


UltiSnips_Manager = SnippetManager( # pylint:disable=invalid-name
vim.eval("g:UltiSnipsExpandTrigger"),
vim.eval("g:UltiSnipsJumpForwardTrigger"),
Expand Down
Loading