summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-08 14:39:52 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-08 14:39:52 +0800
commit42f8519bb66c69230f105a1135b33259ca653f7e (patch)
tree6ec01ae62424783592a3de3f1421c50150080928 /script
parent428d32055f1b7b5bce8a0fd75eeedf4114f8a7ec (diff)
downloadlua-language-server-42f8519bb66c69230f105a1135b33259ca653f7e.zip
cleanup
Diffstat (limited to 'script')
-rw-r--r--script/config/config.lua6
-rw-r--r--script/library.lua42
-rw-r--r--script/provider/provider.lua3
-rw-r--r--script/workspace/workspace.lua8
4 files changed, 39 insertions, 20 deletions
diff --git a/script/config/config.lua b/script/config/config.lua
index e5552616..173899fc 100644
--- a/script/config/config.lua
+++ b/script/config/config.lua
@@ -218,6 +218,9 @@ function m.set(key, value)
if not unit then
return
end
+ if util.equal(rawConfig[key], value) then
+ return
+ end
if unit:checker(value) then
update(key, unit:loader(value), value)
else
@@ -236,6 +239,9 @@ function m.add(key, value)
end
local copyed = {}
for i, v in ipairs(list) do
+ if util.equal(v, value) then
+ return
+ end
copyed[i] = v
end
copyed[#copyed+1] = value
diff --git a/script/library.lua b/script/library.lua
index d4be539e..a6853042 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -195,6 +195,9 @@ local function loadMetaLocale(langID, result)
end
local function initBuiltIn()
+ if not m.inited then
+ return
+ end
local langID = lang.id
local version = config.get 'Lua.runtime.version'
local metaPath = fs.path(METAPATH) / config.get 'Lua.runtime.meta':gsub('%$%{(.-)%}', {
@@ -241,15 +244,14 @@ local function loadSingle3rdConfig(libraryDir)
end
local env = setmetatable({}, { __index = _G })
- assert(load(configText, '@' .. libraryDir:string(), 't', env))
+ assert(load(configText, '@' .. libraryDir:string(), 't', env))()
local cfg = {}
cfg.name = libraryDir:filename():string()
- local pluginPath = ('${3rd}/%s/plugin.lua'):format('cfg.name')
- if fs.exists(fs.path(pluginPath)) then
- cfg.plugin = pluginPath
+ if fs.exists(libraryDir / 'plugin.lua') then
+ cfg.plugin = true
end
for k, v in pairs(env) do
@@ -282,11 +284,19 @@ local function apply3rd(cfg)
if cfg.plugin then
changes[#changes+1] = {
- key = 'Lua.workspace.library',
+ key = 'Lua.runtime.plugin',
action = 'set',
- value = cfg.plugin,
+ value = ('${3rd}/%s/plugin.lua'):format(cfg.name),
}
end
+
+ changes[#changes+1] = {
+ key = 'Lua.workspace.library',
+ action = 'add',
+ value = ('${3rd}/%s/library.lua'):format(cfg.name),
+ }
+
+ client.setConfig(changes)
end
local hasAsked
@@ -302,13 +312,13 @@ local function askFor3rd(cfg)
if not result then
return nil
end
- client.setConfig {
- {
- key = 'Lua.workspace.checkThirdParty',
- action = 'set',
- value = false,
- },
- }
+ --client.setConfig {
+ -- {
+ -- key = 'Lua.workspace.checkThirdParty',
+ -- action = 'set',
+ -- value = false,
+ -- },
+ --}
if result == yes then
apply3rd(cfg)
end
@@ -321,7 +331,7 @@ local function check3rdByWords(text, configs)
for _, word in ipairs(cfg.words) do
await.delay()
if text:match(word) then
- askFor3rd()
+ askFor3rd(cfg)
return
end
end
@@ -366,6 +376,10 @@ files.watch(function (ev, uri)
end)
function m.init()
+ if m.inited then
+ return
+ end
+ m.inited = true
initBuiltIn()
end
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index ae389b70..a8ef2c68 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -109,6 +109,7 @@ proto.on('workspace/didChangeConfiguration', function ()
end)
proto.on('workspace/didChangeWatchedFiles', function (params)
+ workspace.awaitReady()
for _, change in ipairs(params.changes) do
local uri = change.uri
if not workspace.isWorkspaceUri(uri) then
@@ -191,6 +192,7 @@ proto.on('workspace/didRenameFiles', function (params)
end)
proto.on('textDocument/didOpen', function (params)
+ workspace.awaitReady()
local doc = params.textDocument
local uri = doc.uri
local text = doc.text
@@ -213,6 +215,7 @@ proto.on('textDocument/didClose', function (params)
end)
proto.on('textDocument/didChange', function (params)
+ workspace.awaitReady()
local doc = params.textDocument
local changes = params.contentChanges
local uri = doc.uri
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 72d7e4bb..9a17d2bf 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -125,9 +125,7 @@ function m.getNativeMatcher()
end
-- config.get 'workspace.library'
for path in pairs(config.get 'Lua.workspace.library') do
- path = path:gsub('${(.-)}', {
- meta = (ROOT / 'meta' / '3rd'):string(),
- })
+ path = m.getAbsolutePath(path)
log.info('Ignore by library:', path)
pattern[#pattern+1] = path
end
@@ -147,9 +145,7 @@ function m.getLibraryMatchers()
local librarys = {}
for path in pairs(config.get 'Lua.workspace.library') do
- path = path:gsub('${(.-)}', {
- meta = (ROOT / 'meta' / '3rd'):string(),
- })
+ path = m.getAbsolutePath(path)
librarys[m.normalize(path)] = true
end
if library.metaPath then