summaryrefslogtreecommitdiff
path: root/script/method/workspace/didChangeWatchedFiles.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-05-26 13:51:26 +0800
committerGitHub <noreply@github.com>2020-05-26 13:51:26 +0800
commitd7b7bd258df58c8b9fea5d5ac110975e7387cd9c (patch)
treed400a9cb6f1a897913ff9fe56d7d0e83c45c078b /script/method/workspace/didChangeWatchedFiles.lua
parent0583236680b16588c52c7c98ac5a3f8a7071b868 (diff)
parent9dc816f99f4a4329a3daff55a7199a8265a00c2c (diff)
downloadlua-language-server-d7b7bd258df58c8b9fea5d5ac110975e7387cd9c.zip
Merge pull request #167 from Ruin0x11/multi-workspace
Support multiple workspace folders
Diffstat (limited to 'script/method/workspace/didChangeWatchedFiles.lua')
-rw-r--r--script/method/workspace/didChangeWatchedFiles.lua33
1 files changed, 20 insertions, 13 deletions
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