summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-12-01 20:04:35 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-12-01 20:04:35 +0800
commit671f1f4562ff284530c4be5a4296bf8ddb42b90a (patch)
tree0e2ff141fa9e8f6ef530a4403c97b2e5572a1d15 /script
parent3fba691469ae30b06575174bbd151cc460b7b132 (diff)
downloadlua-language-server-671f1f4562ff284530c4be5a4296bf8ddb42b90a.zip
#831
add tests
Diffstat (limited to 'script')
-rw-r--r--script/client.lua10
-rw-r--r--script/json-edit.lua2
-rw-r--r--script/provider/provider.lua26
3 files changed, 24 insertions, 14 deletions
diff --git a/script/client.lua b/script/client.lua
index c9169d3c..6618752c 100644
--- a/script/client.lua
+++ b/script/client.lua
@@ -204,12 +204,15 @@ end
---@field global? boolean
---@field uri? uri
----@param uri uri
+---@param uri uri?
---@param changes config.change[]
---@return config.change[]
local function getValidChanges(uri, changes)
- local scp = scope.getScope(uri)
local newChanges = {}
+ if not uri then
+ return changes
+ end
+ local scp = scope.getScope(uri)
for _, change in ipairs(changes) do
if scp:isChildUri(change.uri)
or scp:isLinkedUri(change.uri) then
@@ -429,6 +432,9 @@ function m.setConfig(changes, onlyMemory)
xpcall(function ()
local ws = require 'workspace'
if #ws.folders == 0 then
+ if tryModifySpecifiedConfig(nil, finalChanges) then
+ return
+ end
tryModifyClient(nil, finalChanges)
return
end
diff --git a/script/json-edit.lua b/script/json-edit.lua
index 7a62ce98..05fb6499 100644
--- a/script/json-edit.lua
+++ b/script/json-edit.lua
@@ -1,3 +1,5 @@
+---@diagnostic disable: param-type-mismatch
+
local type = type
local next = next
local error = error
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index f1ef08e9..ede4039e 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -23,8 +23,13 @@ local fs = require 'bee.filesystem'
require 'library'
+---@class provider
+local m = {}
+
+m.attributes = {}
+
---@async
-local function updateConfig(uri)
+function m.updateConfig(uri)
config.addNullSymbol(json.null)
local specified = cfgLoader.loadLocalConfig(uri, CONFIGPATH)
if specified then
@@ -58,11 +63,6 @@ local function updateConfig(uri)
config.update(scope.fallback, global)
end
----@class provider
-local m = {}
-
-m.attributes = {}
-
function m.register(method)
return function (attrs)
m.attributes[method] = attrs
@@ -81,7 +81,7 @@ filewatch.event(function (ev, path) ---@async
for _, scp in ipairs(workspace.folders) do
local configPath = workspace.getAbsolutePath(scp.uri, CONFIGPATH)
if path == configPath then
- updateConfig(scp.uri)
+ m.updateConfig(scp.uri)
end
end
end
@@ -89,7 +89,7 @@ filewatch.event(function (ev, path) ---@async
for _, scp in ipairs(workspace.folders) do
local rcPath = workspace.getAbsolutePath(scp.uri, '.luarc.json')
if path == rcPath then
- updateConfig(scp.uri)
+ m.updateConfig(scp.uri)
end
end
end
@@ -97,7 +97,7 @@ filewatch.event(function (ev, path) ---@async
for _, scp in ipairs(workspace.folders) do
local rcPath = workspace.getAbsolutePath(scp.uri, '.luarc.jsonc')
if path == rcPath then
- updateConfig(scp.uri)
+ m.updateConfig(scp.uri)
end
end
end
@@ -136,7 +136,7 @@ m.register 'initialized'{
function (params)
files.init()
local _ <close> = progress.create(workspace.getFirstScope().uri, lang.script.WINDOW_INITIALIZING, 0.5)
- updateConfig()
+ m.updateConfig()
local registrations = {}
if client.getAbility 'workspace.didChangeConfiguration.dynamicRegistration' then
@@ -177,7 +177,7 @@ m.register 'workspace/didChangeConfiguration' {
if CONFIGPATH then
return
end
- updateConfig()
+ m.updateConfig()
end
}
@@ -251,7 +251,7 @@ m.register 'workspace/didChangeWorkspaceFolders' {
log.debug('workspace/didChangeWorkspaceFolders', inspect(params))
for _, folder in ipairs(params.event.added) do
workspace.create(folder.uri)
- updateConfig()
+ m.updateConfig()
workspace.reload(scope.getScope(folder.uri))
end
for _, folder in ipairs(params.event.removed) do
@@ -1576,3 +1576,5 @@ files.watch(function (ev, uri)
end
end
end)
+
+return m