File tree Expand file tree Collapse file tree 3 files changed +8
-5
lines changed Expand file tree Collapse file tree 3 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ function M.default_detect_language(path)
18
18
local abs_path = vim .fn .fnamemodify (path , " :p" )
19
19
local split = vim .split (abs_path , " [/.]" )
20
20
21
- local lang = nil
21
+ local lang = " unknown "
22
22
23
23
for _ , part in ipairs (vim .fn .reverse (split )) do
24
24
if LangSet [normalize_lang (part )] then
Original file line number Diff line number Diff line change 23
23
--- @return string | nil ライブラリの識別子
24
24
function M .detect_library (bufnr )
25
25
local root = M .get_workspace_root (bufnr )
26
- local package_json = root .. " /package.json"
27
26
28
- local package = vim .fn .json_decode (vim .fn .readfile (package_json ))
27
+ local ok , package_json = pcall (vim .fn .readfile , root .. " /package.json" )
28
+ if not ok then
29
+ return nil
30
+ end
29
31
32
+ local package = vim .fn .json_decode (package_json )
30
33
if package == nil then
31
34
return nil
32
35
end
Original file line number Diff line number Diff line change @@ -5,12 +5,12 @@ describe("js-i18n.config", function()
5
5
local tests = {
6
6
{ path = " /path/to/locals/en/trans.json" , expected = " en" },
7
7
{ path = " /path/to/locals/ja/trans.json" , expected = " ja" },
8
- { path = " /path/to/locals/hoge/trans.json" , expected = nil },
8
+ { path = " /path/to/locals/hoge/trans.json" , expected = " unknown " },
9
9
10
10
-- Test cases to verify that it is sufficient for the languagee name to be included somewhere.
11
11
{ path = " /path/to/locals/sub/en.json" , expected = " en" },
12
12
{ path = " /path/to/en/locals/trans.json" , expected = " en" },
13
- { path = " /path/to/locals/en-trans.json" , expected = nil },
13
+ { path = " /path/to/locals/en-trans.json" , expected = " unknown " },
14
14
15
15
-- Test cases for language names with any case and separating characters.
16
16
{ path = " /path/to/locals/en-us/trans.json" , expected = " en-us" },
You can’t perform that action at this time.
0 commit comments