diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-02-02 16:59:55 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-02-02 16:59:55 +0800 |
commit | f5ae885f62c8bf5a3b6086177b5a703406459916 (patch) | |
tree | e36ff1eba467da2fee9c462fba97c2737c74741f | |
parent | cd5b93f0308ca9e3f494344a626730efdc10f219 (diff) | |
download | lua-language-server-f5ae885f62c8bf5a3b6086177b5a703406459916.zip |
stash
-rw-r--r-- | script/provider/provider.lua | 16 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 19 |
2 files changed, 30 insertions, 5 deletions
diff --git a/script/provider/provider.lua b/script/provider/provider.lua index a7a15b84..a7927715 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -157,11 +157,17 @@ end) proto.on('workspace/didChangeWatchedFiles', function (params) for _, change in ipairs(params.changes) do local uri = change.uri - -- TODO 创建文件与删除文件直接重新扫描(文件改名、文件夹删除等情况太复杂了) - if change.type == define.FileChangeType.Created - or change.type == define.FileChangeType.Deleted then - workspace.reload() - break + if change.type == define.FileChangeType.Created then + log.debug('FileChangeType.Created', uri) + workspace.awaitLoadFile(uri) + elseif change.type == define.FileChangeType.Deleted then + log.debug('FileChangeType.Deleted', uri) + files.remove(uri) + local childs = files.getChildFiles(uri) + for _, curi in ipairs(childs) do + log.debug('FileChangeType.Deleted.Child', curi) + files.remove(curi) + end elseif change.type == define.FileChangeType.Changed then -- 如果文件处于关闭状态,则立即更新;否则等待didChange协议来更新 if files.isLua(uri) and not files.isOpen(uri) then diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index edde3ab9..2e47bb7e 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -246,6 +246,25 @@ local function loadFileFactory(root, progressData, isLibrary) end end +function m.awaitLoadFile(uri) + local progressBar <close> = progress.create(lang.script.WORKSPACE_LOADING) + local progressData = { + max = 0, + read = 0, + preload = 0, + update = function (self) + progressBar:setMessage(('%d/%d'):format(self.read, self.max)) + progressBar:setPercentage(self.read / self.max * 100) + end + } + local nativeLoader = loadFileFactory(m.path, progressData) + local native = m.getNativeMatcher() + if native then + log.info('Scan files at:', m.path) + native:scan(uri, nativeLoader) + end +end + --- 预读工作区内所有文件 function m.awaitPreload() local diagnostic = require 'provider.diagnostic' |