Skip to content

Commit

Permalink
Ensure snippets are loaded for current filetype
Browse files Browse the repository at this point in the history
Force a refresh also for the FileType autocommand.
  • Loading branch information
mg979 committed Mar 6, 2024
1 parent 7518f98 commit a44d35d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions autoload/UltiSnips.vim
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,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 plugin/UltiSnips.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ augroup UltiSnips_AutoTrigger
if exists('##TextChangedP')
au TextChangedP * call UltiSnips#TrackChange()
endif
au FileType * call UltiSnips#CheckFiletype()
augroup END

call UltiSnips#map_keys#MapKeys()
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.refresh()


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

0 comments on commit a44d35d

Please sign in to comment.