summaryrefslogtreecommitdiff
path: root/script/method
diff options
context:
space:
mode:
authorRuin0x11 <ipickering2@gmail.com>2020-05-25 19:16:45 -0700
committerRuin0x11 <ipickering2@gmail.com>2020-05-25 19:25:36 -0700
commit9dc816f99f4a4329a3daff55a7199a8265a00c2c (patch)
treed400a9cb6f1a897913ff9fe56d7d0e83c45c078b /script/method
parent0583236680b16588c52c7c98ac5a3f8a7071b868 (diff)
downloadlua-language-server-9dc816f99f4a4329a3daff55a7199a8265a00c2c.zip
Support multiple workspace folders
Diffstat (limited to 'script/method')
-rw-r--r--script/method/init.lua1
-rw-r--r--script/method/initialize.lua13
-rw-r--r--script/method/initialized.lua63
-rw-r--r--script/method/textDocument/codeAction.lua3
-rw-r--r--script/method/textDocument/completion.lua3
-rw-r--r--script/method/textDocument/didChange.lua12
-rw-r--r--script/method/textDocument/didClose.lua3
-rw-r--r--script/method/textDocument/didOpen.lua3
-rw-r--r--script/method/textDocument/documentHighlight.lua3
-rw-r--r--script/method/textDocument/documentSymbol.lua3
-rw-r--r--script/method/textDocument/foldingRange.lua3
-rw-r--r--script/method/textDocument/hover.lua3
-rw-r--r--script/method/textDocument/implementation.lua3
-rw-r--r--script/method/textDocument/onTypeFormatting.lua3
-rw-r--r--script/method/textDocument/publishDiagnostics.lua3
-rw-r--r--script/method/textDocument/references.lua3
-rw-r--r--script/method/textDocument/rename.lua3
-rw-r--r--script/method/textDocument/semanticTokens.lua3
-rw-r--r--script/method/textDocument/signatureHelp.lua3
-rw-r--r--script/method/workspace/didChangeConfiguration.lua47
-rw-r--r--script/method/workspace/didChangeWatchedFiles.lua33
-rw-r--r--script/method/workspace/didChangeWorkspaceFolders.lua43
-rw-r--r--script/method/workspace/executeCommand.lua16
23 files changed, 199 insertions, 74 deletions
diff --git a/script/method/init.lua b/script/method/init.lua
index 41ff3ec3..dd662a2d 100644
--- a/script/method/init.lua
+++ b/script/method/init.lua
@@ -27,6 +27,7 @@ init 'textDocument/semanticTokens'
init 'textDocument/signatureHelp'
init 'workspace/didChangeConfiguration'
init 'workspace/didChangeWatchedFiles'
+init 'workspace/didChangeWorkspaceFolders'
init 'workspace/executeCommand'
return method
diff --git a/script/method/initialize.lua b/script/method/initialize.lua
index be553325..0f986dc1 100644
--- a/script/method/initialize.lua
+++ b/script/method/initialize.lua
@@ -11,15 +11,21 @@ local function allWords()
return list
end
+--- @param lsp LSP
+--- @param params table
+--- @return table
return function (lsp, params)
lsp._inited = true
lsp.client = params
client.init(params)
log.info(table.dump(params))
- if params.rootUri then
- lsp.workspace = workspace(lsp, 'root')
- lsp.workspace:init(params.rootUri)
+ if params.workspaceFolders then
+ for _, folder in ipairs(params.workspaceFolders) do
+ lsp:addWorkspace(folder.name, folder.uri)
+ end
+ elseif params.rootUri then
+ lsp:addWorkspace('root', params.rootUri)
end
local server = {
@@ -45,6 +51,7 @@ return function (lsp, params)
workspace = {
workspaceFolders = {
supported = true,
+ changeNotifications = true,
}
},
documentOnTypeFormattingProvider = {
diff --git a/script/method/initialized.lua b/script/method/initialized.lua
index e4ab585b..9e37fb37 100644
--- a/script/method/initialized.lua
+++ b/script/method/initialized.lua
@@ -1,8 +1,37 @@
-local rpc = require 'rpc'
-local workspace = require 'workspace'
+local rpc = require 'rpc'
+
+--- @param lsp LSP
+--- @return boolean
+return function (lsp)
+ local ws = lsp.workspaces[1]
+
+ if ws then
+ -- 请求工作目录
+ local uri = ws.uri
+ -- 请求配置
+ rpc:request('workspace/configuration', {
+ items = {
+ {
+ scopeUri = uri,
+ section = 'Lua',
+ },
+ {
+ scopeUri = uri,
+ section = 'files.associations',
+ },
+ {
+ scopeUri = uri,
+ section = 'files.exclude',
+ }
+ },
+ }, function (configs)
+ lsp:onUpdateConfig(configs[1], {
+ associations = configs[2],
+ exclude = configs[3],
+ })
+ end)
+ end
-local function initAfterConfig(lsp)
- -- 必须动态注册的事件:
rpc:request('client/registerCapability', {
registrations = {
-- 监视文件变化
@@ -27,32 +56,6 @@ local function initAfterConfig(lsp)
}, function ()
log.debug('client/registerCapability Success!')
end)
-end
-return function (lsp)
- local uri = lsp.workspace and lsp.workspace.uri
- -- 请求配置
- rpc:request('workspace/configuration', {
- items = {
- {
- scopeUri = uri,
- section = 'Lua',
- },
- {
- scopeUri = uri,
- section = 'files.associations',
- },
- {
- scopeUri = uri,
- section = 'files.exclude',
- }
- },
- }, function (configs)
- lsp:onUpdateConfig(configs[1], {
- associations = configs[2],
- exclude = configs[3],
- })
- initAfterConfig(lsp)
- end)
return true
end
diff --git a/script/method/textDocument/codeAction.lua b/script/method/textDocument/codeAction.lua
index 3c6e8d49..80a40a0c 100644
--- a/script/method/textDocument/codeAction.lua
+++ b/script/method/textDocument/codeAction.lua
@@ -1,5 +1,8 @@
local core = require 'core'
+--- @param lsp LSP
+--- @param params table
+--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local vm, lines = lsp:getVM(uri)
diff --git a/script/method/textDocument/completion.lua b/script/method/textDocument/completion.lua
index d622fe73..0ede5903 100644
--- a/script/method/textDocument/completion.lua
+++ b/script/method/textDocument/completion.lua
@@ -82,6 +82,9 @@ local function cuterFactory(lines, text, position)
end
end
+--- @param lsp LSP
+--- @param params table
+--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local text, oldText = lsp:getText(uri)
diff --git a/script/method/textDocument/didChange.lua b/script/method/textDocument/didChange.lua
index 82e6c096..83701662 100644
--- a/script/method/textDocument/didChange.lua
+++ b/script/method/textDocument/didChange.lua
@@ -1,12 +1,16 @@
+--- @param lsp LSP
+--- @param params table
+--- @return boolean
return function (lsp, params)
local doc = params.textDocument
local change = params.contentChanges
- if lsp.workspace then
- local path = lsp.workspace:relativePathByUri(doc.uri)
- if not path or not lsp.workspace:isLuaFile(path) then
+ local ws = lsp:findWorkspaceFor(doc.uri)
+ if ws then
+ local path = ws:relativePathByUri(doc.uri)
+ if not path or not ws:isLuaFile(path) then
return
end
- if not lsp:isOpen(doc.uri) and lsp.workspace.gitignore(path:string()) then
+ if not lsp:isOpen(doc.uri) and ws.gitignore(path:string()) then
return
end
end
diff --git a/script/method/textDocument/didClose.lua b/script/method/textDocument/didClose.lua
index 589b212f..3cfd98e8 100644
--- a/script/method/textDocument/didClose.lua
+++ b/script/method/textDocument/didClose.lua
@@ -1,3 +1,6 @@
+--- @param lsp LSP
+--- @param params table
+--- @return boolean
return function (lsp, params)
local doc = params.textDocument
lsp:close(doc.uri)
diff --git a/script/method/textDocument/didOpen.lua b/script/method/textDocument/didOpen.lua
index e2a67fd2..d9b0de53 100644
--- a/script/method/textDocument/didOpen.lua
+++ b/script/method/textDocument/didOpen.lua
@@ -1,3 +1,6 @@
+--- @param lsp LSP
+--- @param params table
+--- @return boolean
return function (lsp, params)
local doc = params.textDocument
lsp:open(doc.uri, doc.version, doc.text)
diff --git a/script/method/textDocument/documentHighlight.lua b/script/method/textDocument/documentHighlight.lua
index 377ffcdf..2a6768f2 100644
--- a/script/method/textDocument/documentHighlight.lua
+++ b/script/method/textDocument/documentHighlight.lua
@@ -1,5 +1,8 @@
local core = require 'core'
+--- @param lsp LSP
+--- @param params table
+--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local vm, lines = lsp:loadVM(uri)
diff --git a/script/method/textDocument/documentSymbol.lua b/script/method/textDocument/documentSymbol.lua
index a4b0c3b7..a84afb7a 100644
--- a/script/method/textDocument/documentSymbol.lua
+++ b/script/method/textDocument/documentSymbol.lua
@@ -32,6 +32,9 @@ local function convertRange(lines, symbol)
end
end
+--- @param lsp LSP
+--- @param params table
+--- @return function
return function (lsp, params)
local uri = params.textDocument.uri
diff --git a/script/method/textDocument/foldingRange.lua b/script/method/textDocument/foldingRange.lua
index 0320b422..6395c908 100644
--- a/script/method/textDocument/foldingRange.lua
+++ b/script/method/textDocument/foldingRange.lua
@@ -16,6 +16,9 @@ local function convertRange(lines, range)
return result
end
+--- @param lsp LSP
+--- @param params table
+--- @return function
return function (lsp, params)
local uri = params.textDocument.uri
if timerCache[uri] then
diff --git a/script/method/textDocument/hover.lua b/script/method/textDocument/hover.lua
index f8dba27c..2e909dc1 100644
--- a/script/method/textDocument/hover.lua
+++ b/script/method/textDocument/hover.lua
@@ -1,5 +1,8 @@
local core = require 'core'
+--- @param lsp LSP
+--- @param params table
+--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local vm, lines = lsp:loadVM(uri)
diff --git a/script/method/textDocument/implementation.lua b/script/method/textDocument/implementation.lua
index 14e2f24c..94991fd4 100644
--- a/script/method/textDocument/implementation.lua
+++ b/script/method/textDocument/implementation.lua
@@ -77,6 +77,9 @@ end
local LastTask
+--- @param lsp LSP
+--- @param params table
+--- @return function
return function (lsp, params)
if LastTask then
LastTask:remove()
diff --git a/script/method/textDocument/onTypeFormatting.lua b/script/method/textDocument/onTypeFormatting.lua
index fc9cbdc9..8485ab49 100644
--- a/script/method/textDocument/onTypeFormatting.lua
+++ b/script/method/textDocument/onTypeFormatting.lua
@@ -1,3 +1,6 @@
+--- @param lsp LSP
+--- @param params table
+--- @return any
return function (lsp, params)
local uri = params.textDocument.uri
local vm, lines = lsp:loadVM(uri)
diff --git a/script/method/textDocument/publishDiagnostics.lua b/script/method/textDocument/publishDiagnostics.lua
index c767e934..0a2900fa 100644
--- a/script/method/textDocument/publishDiagnostics.lua
+++ b/script/method/textDocument/publishDiagnostics.lua
@@ -140,6 +140,9 @@ local function buildError(err, lines, uri)
return diagnostic
end
+--- @param lsp LSP
+--- @param params table
+--- @return table
return function (lsp, params)
local vm = params.vm
local lines = params.lines
diff --git a/script/method/textDocument/references.lua b/script/method/textDocument/references.lua
index 0a198323..6421145e 100644
--- a/script/method/textDocument/references.lua
+++ b/script/method/textDocument/references.lua
@@ -54,6 +54,9 @@ local function findReferences(lsp, uri, position)
return locations, isGlobal
end
+--- @param lsp LSP
+--- @param params table
+--- @return function
return function (lsp, params)
local uri = params.textDocument.uri
local declarat = params.context.includeDeclaration
diff --git a/script/method/textDocument/rename.lua b/script/method/textDocument/rename.lua
index 6da9c721..b637141d 100644
--- a/script/method/textDocument/rename.lua
+++ b/script/method/textDocument/rename.lua
@@ -1,5 +1,8 @@
local core = require 'core'
+--- @param lsp LSP
+--- @param params table
+--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local newName = params.newName
diff --git a/script/method/textDocument/semanticTokens.lua b/script/method/textDocument/semanticTokens.lua
index 03f0163a..bc6d2bcb 100644
--- a/script/method/textDocument/semanticTokens.lua
+++ b/script/method/textDocument/semanticTokens.lua
@@ -169,6 +169,9 @@ local function testTokens(vm, lines)
return tokens
end
+--- @param lsp LSP
+--- @param params table
+--- @return function
return function (lsp, params)
local uri = params.textDocument.uri
diff --git a/script/method/textDocument/signatureHelp.lua b/script/method/textDocument/signatureHelp.lua
index 01d6289d..e7e695ca 100644
--- a/script/method/textDocument/signatureHelp.lua
+++ b/script/method/textDocument/signatureHelp.lua
@@ -1,5 +1,8 @@
local core = require 'core'
+--- @param lsp LSP
+--- @param params table
+--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local vm, lines = lsp:loadVM(uri)
diff --git a/script/method/workspace/didChangeConfiguration.lua b/script/method/workspace/didChangeConfiguration.lua
index ecaa9182..eca61ebc 100644
--- a/script/method/workspace/didChangeConfiguration.lua
+++ b/script/method/workspace/didChangeConfiguration.lua
@@ -1,27 +1,30 @@
local rpc = require 'rpc'
+--- @param lsp LSP
return function (lsp)
- local uri = lsp.workspace and lsp.workspace.uri
- -- 请求配置
- rpc:request('workspace/configuration', {
- items = {
- {
- scopeUri = uri,
- section = 'Lua',
+ for _, ws in ipairs(lsp.workspaces) do
+ local uri = ws.uri
+ -- 请求配置
+ rpc:request('workspace/configuration', {
+ items = {
+ {
+ scopeUri = uri,
+ section = 'Lua',
+ },
+ {
+ scopeUri = uri,
+ section = 'files.associations',
+ },
+ {
+ scopeUri = uri,
+ section = 'files.exclude',
+ }
},
- {
- scopeUri = uri,
- section = 'files.associations',
- },
- {
- scopeUri = uri,
- section = 'files.exclude',
- }
- },
- }, function (configs)
- lsp:onUpdateConfig(configs[1], {
- associations = configs[2],
- exclude = configs[3],
- })
- end)
+ }, function (configs)
+ lsp:onUpdateConfig(configs[1], {
+ associations = configs[2],
+ exclude = configs[3],
+ })
+ end)
+ end
end
diff --git a/script/method/workspace/didChangeWatchedFiles.lua b/script/method/workspace/didChangeWatchedFiles.lua
index 3ce68924..3d8fc599 100644
--- a/script/method/workspace/didChangeWatchedFiles.lua
+++ b/script/method/workspace/didChangeWatchedFiles.lua
@@ -7,38 +7,45 @@ local FileChangeType = {
Deleted = 3,
}
+--- @param lsp LSP
+--- @param params table
return function (lsp, params)
- if not lsp.workspace then
- return
- end
- local needReset
+ local needReset = {}
+ local needRescan
for _, change in ipairs(params.changes) do
+ local ws = lsp:findWorkspaceFor(change.uri)
+ if not ws then
+ goto CONTINUE
+ end
local path = uric.decode(change.uri)
if not path then
goto CONTINUE
end
if change.type == FileChangeType.Created then
- lsp.workspace:addFile(path)
+ ws:addFile(path)
if lsp:getVM(change.uri) then
- needReset = true
+ needReset[ws] = true
end
elseif change.type == FileChangeType.Deleted then
- lsp.workspace:removeFile(path)
+ ws:removeFile(path)
if lsp:getVM(change.uri) then
- needReset = true
+ needReset[ws] = true
end
end
-- 排除类文件发生更改需要重新扫描
local filename = path:filename():string()
- if lsp.workspace:fileNameEq(filename, '.gitignore')
- or lsp.workspace:fileNameEq(filename, '.gitmodules')
+ if ws:fileNameEq(filename, '.gitignore')
+ or ws:fileNameEq(filename, '.gitmodules')
then
- lsp:reScanFiles()
+ needRescan = true
end
::CONTINUE::
end
+ if needRescan then
+ lsp:reScanFiles()
+ end
-- 缓存过的文件发生变化后,重新计算
- if needReset then
- lsp.workspace:reset()
+ for ws, _ in pairs(needReset) do
+ ws:reset()
end
end
diff --git a/script/method/workspace/didChangeWorkspaceFolders.lua b/script/method/workspace/didChangeWorkspaceFolders.lua
new file mode 100644
index 00000000..25c06f4b
--- /dev/null
+++ b/script/method/workspace/didChangeWorkspaceFolders.lua
@@ -0,0 +1,43 @@
+local rpc = require 'rpc'
+
+--- @param lsp LSP
+--- @param params table
+return function (lsp, params)
+ local event = params.event
+
+ for _, removed in ipairs(event.removed) do
+ lsp:removeWorkspace(removed.name, removed.uri)
+ end
+
+ for _, added in ipairs(event.added) do
+ lsp:addWorkspace(added.name, added.uri)
+ end
+
+ local ws = lsp.workspaces[1]
+ if ws then
+ -- 请求工作目录
+ local uri = ws.uri
+ -- 请求配置
+ rpc:request('workspace/configuration', {
+ items = {
+ {
+ scopeUri = uri,
+ section = 'Lua',
+ },
+ {
+ scopeUri = uri,
+ section = 'files.associations',
+ },
+ {
+ scopeUri = uri,
+ section = 'files.exclude',
+ }
+ },
+ }, function (configs)
+ lsp:onUpdateConfig(configs[1], {
+ associations = configs[2],
+ exclude = configs[3],
+ })
+ end)
+ end
+end
diff --git a/script/method/workspace/executeCommand.lua b/script/method/workspace/executeCommand.lua
index cfa4023e..d5abb453 100644
--- a/script/method/workspace/executeCommand.lua
+++ b/script/method/workspace/executeCommand.lua
@@ -37,6 +37,8 @@ local function posToRange(lines, start, finish)
}
end
+--- @param lsp LSP
+--- @param data table
function command.config(lsp, data)
local def = config.config
for _, k in ipairs(data.key) do
@@ -53,8 +55,12 @@ function command.config(lsp, data)
local vscodePath
local mode
- if lsp.workspace then
- vscodePath = lsp.workspace.root / '.vscode'
+ local ws
+ if data.uri then
+ ws = lsp:findWorkspaceFor(data.uri)
+ end
+ if ws then
+ vscodePath = ws.root / '.vscode'
mode = 'workspace'
else
if platform.OS == 'Windows' then
@@ -115,6 +121,8 @@ function command.config(lsp, data)
end
end
+--- @param lsp LSP
+--- @param data table
function command.removeSpace(lsp, data)
local uri = data.uri
local vm, lines = lsp:getVM(uri)
@@ -178,6 +186,8 @@ local literalMap = {
['table'] = true,
}
+--- @param lsp LSP
+--- @param data table
function command.solve(lsp, data)
local uri = data.uri
local vm, lines = lsp:getVM(uri)
@@ -248,6 +258,8 @@ function command.solve(lsp, data)
})
end
+--- @param lsp LSP
+--- @param params table
return function (lsp, params)
local name = params.command
if not command[name] then