summaryrefslogtreecommitdiff
path: root/script/method/workspace/didChangeWatchedFiles.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-23 00:05:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-23 00:05:30 +0800
commit6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444 (patch)
treefdc22d78150fd1c5edc46732c8b151ccfefb519f /script/method/workspace/didChangeWatchedFiles.lua
parentd0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (diff)
downloadlua-language-server-6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444.zip
正路目录
Diffstat (limited to 'script/method/workspace/didChangeWatchedFiles.lua')
-rw-r--r--script/method/workspace/didChangeWatchedFiles.lua44
1 files changed, 44 insertions, 0 deletions
diff --git a/script/method/workspace/didChangeWatchedFiles.lua b/script/method/workspace/didChangeWatchedFiles.lua
new file mode 100644
index 00000000..3ce68924
--- /dev/null
+++ b/script/method/workspace/didChangeWatchedFiles.lua
@@ -0,0 +1,44 @@
+local fs = require 'bee.filesystem'
+local uric = require 'uri'
+
+local FileChangeType = {
+ Created = 1,
+ Changed = 2,
+ Deleted = 3,
+}
+
+return function (lsp, params)
+ if not lsp.workspace then
+ return
+ end
+ local needReset
+ for _, change in ipairs(params.changes) do
+ local path = uric.decode(change.uri)
+ if not path then
+ goto CONTINUE
+ end
+ if change.type == FileChangeType.Created then
+ lsp.workspace:addFile(path)
+ if lsp:getVM(change.uri) then
+ needReset = true
+ end
+ elseif change.type == FileChangeType.Deleted then
+ lsp.workspace:removeFile(path)
+ if lsp:getVM(change.uri) then
+ needReset = true
+ end
+ end
+ -- 排除类文件发生更改需要重新扫描
+ local filename = path:filename():string()
+ if lsp.workspace:fileNameEq(filename, '.gitignore')
+ or lsp.workspace:fileNameEq(filename, '.gitmodules')
+ then
+ lsp:reScanFiles()
+ end
+ ::CONTINUE::
+ end
+ -- 缓存过的文件发生变化后,重新计算
+ if needReset then
+ lsp.workspace:reset()
+ end
+end