File tree 3 files changed +19
-4
lines changed
lua/blink/cmp/sources/snippets
3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ function registry:get_snippets_for_ft(filetype)
46
46
for _ , f in ipairs (files ) do
47
47
local contents = utils .read_file (f )
48
48
if contents then
49
- local snippets = vim . json . decode ( contents )
49
+ local snippets = utils . parse_json_with_error_msg ( f , contents )
50
50
for _ , key in ipairs (vim .tbl_keys (snippets )) do
51
51
local snippet = utils .read_snippet (snippets [key ], key )
52
52
for snippet_name , snippet_def in pairs (snippet ) do
@@ -58,7 +58,7 @@ function registry:get_snippets_for_ft(filetype)
58
58
else
59
59
local contents = utils .read_file (files )
60
60
if contents then
61
- local snippets = vim . json . decode ( contents )
61
+ local snippets = utils . parse_json_with_error_msg ( files , contents )
62
62
for _ , key in ipairs (vim .tbl_keys (snippets )) do
63
63
local snippet = utils .read_snippet (snippets [key ], key )
64
64
for key , snippet in pairs (snippet ) do
Original file line number Diff line number Diff line change @@ -72,10 +72,10 @@ function scan.load_package_json(path)
72
72
local data = utils .read_file (file )
73
73
if not data then return end
74
74
75
- local pkg = vim .json .decode (data )
75
+ local pkg = require (' blink.cmp.sources.snippets.utils' ).parse_json_with_error_msg (file , data )
76
+
76
77
--- @type { path : string , language : string | string[] } []
77
78
local snippets = vim .tbl_get (pkg , ' contributes' , ' snippets' )
78
-
79
79
if not snippets then return end
80
80
81
81
local ret = {} --- @type table<string , string[]>
Original file line number Diff line number Diff line change 1
1
local utils = {}
2
2
3
+ --- Parses the json file and notifies the user if there's an error
4
+ --- @param path string
5
+ --- @param json string
6
+ function utils .parse_json_with_error_msg (path , json )
7
+ local ok , parsed = pcall (vim .json .decode , json )
8
+ if not ok then
9
+ vim .notify (
10
+ ' Failed to parse json file "' .. path .. ' " for blink.cmp snippets. Error: ' .. parsed ,
11
+ vim .log .levels .ERROR
12
+ )
13
+ return {}
14
+ end
15
+ return parsed
16
+ end
17
+
3
18
--- @type fun ( path : string ): string | nil
4
19
function utils .read_file (path )
5
20
local file = io.open (path , ' r' )
You can’t perform that action at this time.
0 commit comments