Skip to content

Commit 80cacc0

Browse files
committed
load config in .luarc.json
1 parent 98e3b26 commit 80cacc0

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

script/config/loader.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ end
1616

1717
local m = {}
1818

19+
function m.loadRCConfig(filename)
20+
local path = fs.path(workspace.getAbsolutePath(filename))
21+
local buf = fsu.loadFile(path)
22+
if not buf then
23+
return
24+
end
25+
local suc, res = pcall(json.decode, buf)
26+
if not suc then
27+
errorMessage(lang.script('CONFIG_LOAD_ERROR', res))
28+
return
29+
end
30+
return res
31+
end
32+
1933
function m.loadLocalConfig(filename)
2034
local path = fs.path(workspace.getAbsolutePath(filename))
2135
local buf = fsu.loadFile(path)

script/provider/provider.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ local function updateConfig()
2222
config.setSource 'path'
2323
log.debug('load config from local', CONFIGPATH)
2424
else
25-
new = cfgLoader.loadClientConfig()
26-
config.setSource 'client'
27-
log.debug('load config from client')
25+
new = cfgLoader.loadRCConfig('.luarc.json')
26+
if new then
27+
config.setSource 'luarc'
28+
log.debug('load config from luarc')
29+
else
30+
new = cfgLoader.loadClientConfig()
31+
config.setSource 'client'
32+
log.debug('load config from client')
33+
end
2834
end
2935
if not new then
3036
log.warn('load config failed!')

0 commit comments

Comments
 (0)