diff options
author | sumneko <sumneko@hotmail.com> | 2021-10-01 15:03:07 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2021-10-01 15:03:07 +0800 |
commit | 98e3b264a52738d79bc914f68207d7f3971ef9ae (patch) | |
tree | 1a8404658a86ff5a2c5d598351457ab2cd607153 /script | |
parent | 2183bf6e33a26216ecac691266462013a6359f68 (diff) | |
download | lua-language-server-98e3b264a52738d79bc914f68207d7f3971ef9ae.zip |
infer config type by content
Diffstat (limited to 'script')
-rw-r--r-- | script/config/loader.lua | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/script/config/loader.lua b/script/config/loader.lua index 436bbee9..9f15830d 100644 --- a/script/config/loader.lua +++ b/script/config/loader.lua @@ -18,20 +18,20 @@ local m = {} function m.loadLocalConfig(filename) local path = fs.path(workspace.getAbsolutePath(filename)) - local ext = path:extension():string():lower() local buf = fsu.loadFile(path) if not buf then errorMessage(lang.script('CONFIG_LOAD_FAILED', path:string())) return end - if ext == '.json' then + local firstChar = buf:match '%S' + if firstChar == '{' then local suc, res = pcall(json.decode, buf) if not suc then errorMessage(lang.script('CONFIG_LOAD_ERROR', res)) return end return res - elseif ext == '.lua' then + else local suc, res = pcall(function () return assert(load(buf, '@' .. path:string(), 't'))() end) @@ -40,9 +40,6 @@ function m.loadLocalConfig(filename) return end return res - else - errorMessage(lang.script('CONFIG_TYPE_ERROR', path:string())) - return end end |