Skip to content

Commit f2c5ca3

Browse files
committed
refactor: write proper pcall
1 parent 79865d8 commit f2c5ca3

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

lua/cspell/helpers.lua

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,14 @@ M.create_merged_cspell_json = function(params, cspell_config_mapping)
9292
and cspell_config_path ~= ""
9393
and Path:new(cspell_config_path):exists()
9494
if path_exists then
95-
pcall(function()
96-
local cspell_config = vim.json.decode(Path:new(cspell_config_path):read())
97-
if
98-
cspell_config.language ~= nil
99-
and type(cspell_config.language) == "string"
100-
and cspell_config.language ~= ''
101-
then
102-
cspell_json.language = cspell_json.language .. "," .. cspell_config.language
103-
end
104-
end)
95+
local ok, cspell_config = pcall(vim.json.decode, Path:new(cspell_config_path):read())
96+
if ok
97+
and cspell_config.language ~= nil
98+
and type(cspell_config.language) == "string"
99+
and cspell_config.language ~= ''
100+
then
101+
cspell_json.language = cspell_json.language .. "," .. cspell_config.language
102+
end
105103
table.insert(cspell_config_paths, cspell_config_path)
106104
else
107105
local debug_message = M.format(

0 commit comments

Comments
 (0)