@@ -37,7 +37,7 @@ local function read_json(fname)
37
37
end
38
38
end
39
39
40
- local function get_file_snippets (file )
40
+ local function get_file_snippets (lang , file )
41
41
local lang_snips = {}
42
42
local auto_lang_snips = {}
43
43
@@ -51,6 +51,14 @@ local function get_file_snippets(file)
51
51
local body = type (parts .body ) == " string" and parts .body
52
52
or table.concat (parts .body , " \n " )
53
53
54
+ -- Skip entire snippet if entry has `scope` field mismatching lang
55
+ -- This prevents snippets mapped by package.json to one language
56
+ -- to be used for another. This is not part of LSP Snippets! See:
57
+ -- https://code.visualstudio.com/docs/editor/userdefinedsnippets#_snippet-scope
58
+ if type (parts .scope ) == " string" and not (string.match (parts .scope , lang )) then
59
+ goto continue
60
+ end
61
+
54
62
-- There are still some snippets that fail while loading
55
63
pcall (function ()
56
64
-- Sometimes it's a list of prefixes instead of a single one
@@ -74,6 +82,8 @@ local function get_file_snippets(file)
74
82
end
75
83
end
76
84
end )
85
+
86
+ :: continue::
77
87
end
78
88
79
89
return lang_snips , auto_lang_snips
@@ -90,7 +100,7 @@ local function load_snippet_files(lang, files, add_opts)
90
100
auto_lang_snips = vim .deepcopy (cached_path .autosnippets )
91
101
cached_path .fts [lang ] = true
92
102
else
93
- lang_snips , auto_lang_snips = get_file_snippets (file )
103
+ lang_snips , auto_lang_snips = get_file_snippets (lang , file )
94
104
-- store snippets to prevent parsing the same file more than once.
95
105
cache .path_snippets [file ] = {
96
106
snippets = vim .deepcopy (lang_snips ),
@@ -99,7 +109,6 @@ local function load_snippet_files(lang, files, add_opts)
99
109
fts = { [lang ] = true },
100
110
}
101
111
end
102
-
103
112
ls .add_snippets (
104
113
lang ,
105
114
lang_snips ,
@@ -285,8 +294,9 @@ function M.lazy_load(opts)
285
294
opts = opts or {}
286
295
287
296
local ft_files = get_snippet_files (opts )
288
- local add_opts = loader_util . add_opts ( opts )
297
+ print ( vim . inspect ( ft_files ) )
289
298
299
+ local add_opts = loader_util .add_opts (opts )
290
300
loader_util .extend_ft_paths (cache .ft_paths , ft_files )
291
301
292
302
-- immediately load filetypes that have already been loaded.
0 commit comments