summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-01 20:18:58 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-01 20:18:58 +0800
commit9805559194e6d0a05b8094142b0b2d4389ea71f0 (patch)
treea1ee2b56db5f4ed4f8d1c680c3791c0617ea958e /script
parent71e3ff51d3fb21f3e78a3948809ce4ae92613de2 (diff)
downloadlua-language-server-9805559194e6d0a05b8094142b0b2d4389ea71f0.zip
cleanup
Diffstat (limited to 'script')
-rw-r--r--script/config/config.lua60
-rw-r--r--script/files.lua2
-rw-r--r--script/provider/provider.lua37
-rw-r--r--script/provider/semantic-tokens.lua2
-rw-r--r--script/workspace/workspace.lua2
5 files changed, 65 insertions, 38 deletions
diff --git a/script/config/config.lua b/script/config/config.lua
index c8f848f9..2f623920 100644
--- a/script/config/config.lua
+++ b/script/config/config.lua
@@ -18,7 +18,7 @@ end
local units = {}
-local function push(name, default, checker, loader, caller)
+local function register(name, default, checker, loader, caller)
units[name] = {
default = default,
checker = checker,
@@ -35,31 +35,31 @@ local Type = setmetatable({}, { __index = function (_, name)
return setmetatable(unit, mt)
end })
-push('Boolean', false, function (self, v)
+register('Boolean', false, function (self, v)
return type(v) == 'boolean'
end, function (self, v)
return v
end)
-push('Integer', 0, function (self, v)
+register('Integer', 0, function (self, v)
return type(v) == 'number'
end,function (self, v)
return math.floor(v)
end)
-push('String', '', function (self, v)
+register('String', '', function (self, v)
return type(v) == 'string'
end, function (self, v)
return tostring(v)
end)
-push('Nil', nil, function (self, v)
+register('Nil', nil, function (self, v)
return type(v) == 'nil'
end, function (self, v)
return nil
end)
-push('Array', {}, function (self, value)
+register('Array', {}, function (self, value)
return type(value) == 'table'
end, function (self, value)
local t = {}
@@ -73,7 +73,7 @@ end, function (self, sub)
self.sub = sub
end)
-push('Hash', {}, function (self, value)
+register('Hash', {}, function (self, value)
if type(value) == 'table' then
if #value == 0 then
for k, v in pairs(value) do
@@ -125,7 +125,7 @@ end, function (self, subkey, subvalue, sep)
self.sep = sep
end)
-push('Or', {}, function (self, value)
+register('Or', {}, function (self, value)
for _, sub in ipairs(self.subs) do
if sub:checker(value) then
return true
@@ -195,7 +195,7 @@ local Template = {
['Lua.telemetry.enable'] = Type.Or(Type.Boolean, Type.Nil),
['files.associations'] = Type.Hash(Type.String, Type.String),
['files.exclude'] = Type.Hash(Type.String, Type.Boolean),
- ['editor.semanticHighlighting'] = Type.Or(Type.Boolean, Type.String),
+ ['editor.semanticHighlighting.enabled'] = Type.Or(Type.Boolean, Type.String),
['editor.acceptSuggestionOnEnter'] = Type.String >> 'on',
}
@@ -219,12 +219,44 @@ function m.get(key)
return config[key]
end
-function m.copy()
- local t = {}
- for k, v in pairs(config) do
- t[k] = v
+function m.dump()
+ local dump = {}
+
+ local function expand(parent, key, value)
+ local left, right = key:match '([^%.]+)%.(.+)'
+ if left then
+ if not parent[left] then
+ parent[left] = {}
+ end
+ expand(parent[left], right, value)
+ else
+ parent[key] = value
+ end
end
- return t
+
+ for key, value in pairs(config) do
+ expand(dump, key, value)
+ end
+
+ return dump
+end
+
+function m.update(new)
+ local function expand(t, left)
+ for key, value in pairs(t) do
+ local fullKey = key
+ if left then
+ fullKey = left .. '.' .. key
+ end
+ if Template[fullKey] then
+ m.set(fullKey, value)
+ elseif type(value) == 'table' then
+ expand(value, fullKey)
+ end
+ end
+ end
+
+ expand(new)
end
for key in pairs(Template) do
diff --git a/script/files.lua b/script/files.lua
index 63499fe2..c09cef37 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -769,7 +769,7 @@ function m.getAssoc()
end
m.assocVersion = config.get 'version'
local patt = {}
- for k, v in pairs(config.get 'other.associations') do
+ for k, v in pairs(config.get 'files.associations') do
if m.eq(v, 'lua') then
patt[#patt+1] = k
end
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 54e3d2f4..351cd1a6 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -53,47 +53,42 @@ local function updateConfig()
return
end
- local updated = configs[1]
- local other = {
- associations = configs[2],
- exclude = configs[3],
- semantic = configs[4],
- acceptSuggestionOnEnter = configs[5],
- }
+ local new = configs[1]
+ new['files.associations'] = configs[2]
+ new['files.exclude'] = configs[3]
+ new['editor.semanticHighlighting.enabled'] = configs[4]
+ new['editor.acceptSuggestionOnEnter'] = configs[5]
- local oldConfig = util.deepCopy(config.get 'Lua')
- local oldOther = util.deepCopy(config.get 'other')
- config.get 'setConfig'(updated, other)
- local newConfig = config.get 'Lua'
- local newOther = config.get 'other'
+ local oldConfig = config.dump()
+ config.update(new)
+ local newConfig = config.dump()
- if not util.equal(oldConfig.runtime, newConfig.runtime) then
+ if not util.equal(oldConfig.Lua.runtime, newConfig.Lua.runtime) then
library.init()
workspace.reload()
semantic.refresh()
end
- if not util.equal(oldConfig.diagnostics, newConfig.diagnostics) then
+ if not util.equal(oldConfig.Lua.diagnostics, newConfig.Lua.diagnostics) then
diagnostics.diagnosticsAll()
end
- if not util.equal(oldConfig.workspace, newConfig.workspace)
- or not util.equal(oldOther.associations, newOther.associations)
- or not util.equal(oldOther.exclude, newOther.exclude)
+ if not util.equal(oldConfig.Lua.workspace, newConfig.Lua.workspace)
+ or not util.equal(oldConfig.files, newConfig.files)
then
workspace.reload()
semantic.refresh()
end
- if newConfig.completion.enable then
+ if newConfig.Lua.completion.enable then
completion.enable()
else
completion.disable()
end
- if newConfig.color.mode == 'Semantic' then
+ if newConfig.Lua.color.mode == 'Semantic' then
semantic.enable()
else
semantic.disable()
end
- if newConfig.window.statusBar then
+ if newConfig.Lua.window.statusBar then
proto.notify('$/status/show')
else
proto.notify('$/status/hide')
@@ -474,7 +469,7 @@ proto.on('textDocument/completion', function (params)
return nil
end
local triggerCharacter = params.context and params.context.triggerCharacter
- if config.get 'other.acceptSuggestionOnEnter' ~= 'off' then
+ if config.get 'editor.acceptSuggestionOnEnter' ~= 'off' then
if triggerCharacter == '\n'
or triggerCharacter == '{'
or triggerCharacter == ',' then
diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua
index 57c61afd..fa636381 100644
--- a/script/provider/semantic-tokens.lua
+++ b/script/provider/semantic-tokens.lua
@@ -47,7 +47,7 @@ local function enable()
},
}
})
- if config.get 'other.semantic' == 'configuredByTheme' and not dontShowAgain then
+ if config.get 'editor.semanticHighlighting.enabled' == 'configuredByTheme' and not dontShowAgain then
proto.request('window/showMessageRequest', {
type = define.MessageType.Info,
message = lang.script.WINDOW_CHECK_SEMANTIC,
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 8137a507..43057a45 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -82,7 +82,7 @@ function m.getNativeMatcher()
pattern[#pattern+1] = path
end
-- config.get 'files.exclude'
- for path, ignore in pairs(config.get 'other.exclude') do
+ for path, ignore in pairs(config.get 'files.exclude') do
if ignore then
log.info('Ignore by exclude:', path)
pattern[#pattern+1] = path