diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/method/initialized.lua | 2 | ||||
-rw-r--r-- | server/src/method/workspace/didChangeWatchedFiles.lua | 14 | ||||
-rw-r--r-- | server/src/service.lua | 12 | ||||
-rw-r--r-- | server/src/workspace.lua | 22 |
4 files changed, 32 insertions, 18 deletions
diff --git a/server/src/method/initialized.lua b/server/src/method/initialized.lua index 47b924d0..1348e03b 100644 --- a/server/src/method/initialized.lua +++ b/server/src/method/initialized.lua @@ -17,7 +17,7 @@ local function initAfterConfig(lsp, firstScope) watchers = { { globPattern = '**/', - kind = 1 | 4, + kind = 1 | 2 | 4, } }, }, diff --git a/server/src/method/workspace/didChangeWatchedFiles.lua b/server/src/method/workspace/didChangeWatchedFiles.lua index 7e1afb92..06d840e1 100644 --- a/server/src/method/workspace/didChangeWatchedFiles.lua +++ b/server/src/method/workspace/didChangeWatchedFiles.lua @@ -15,11 +15,21 @@ return function (lsp, params) local path = lsp.workspace:uriDecode(change.uri) 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 - if lsp:getVM(change.uri) then - needReset = true + -- 排除类文件发生更改需要重新扫描 + local filename = path:filename():string() + if lsp.workspace:fileNameEq(filename, '.gitignore') + or lsp.workspace:fileNameEq(filename, '.gitmodules') + then + lsp:reScanFiles() end end -- 缓存过的文件发生变化后,重新计算 diff --git a/server/src/service.lua b/server/src/service.lua index 1e97cb5c..fafa5901 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -708,6 +708,13 @@ function mt:restartDueToMemoryLeak() end) end +function mt:reScanFiles() + self:clearAllFiles() + if self.workspace then + self.workspace:scanFiles() + end +end + function mt:onUpdateConfig(updated, other) local oldConfig = table.deepCopy(config.config) local oldOther = table.deepCopy(config.other) @@ -727,10 +734,7 @@ function mt:onUpdateConfig(updated, other) or not table.equal(oldOther.associations, newOther.associations) or not table.equal(oldOther.exclude, newOther.exclude) then - self:clearAllFiles() - if self.workspace then - self.workspace:scanFiles() - end + self:reScanFiles() end end diff --git a/server/src/workspace.lua b/server/src/workspace.lua index 605c216c..ee467a4b 100644 --- a/server/src/workspace.lua +++ b/server/src/workspace.lua @@ -22,14 +22,6 @@ local function getTrueName(name) return TrueName[name] or name end -local function fileNameEq(a, b) - if platform.OS == 'Windows' then - return a:lower() == b:lower() - else - return a == b - end -end - local function split(str, sep) local t = {} for s in str:gmatch('[^' .. sep .. ']+') do @@ -52,6 +44,14 @@ end local mt = {} mt.__index = mt +function mt:fileNameEq(a, b) + if platform.OS == 'Windows' then + return a:lower() == b:lower() + else + return a == b + end +end + function mt:uriDecode(uri) -- Unix-like系统根是/ if uri:sub(1, 9) == 'file:////' then @@ -212,7 +212,7 @@ end function mt:isLuaFile(path) local ext = path:extension():string() for k, v in pairs(config.other.associations) do - if fileNameEq(ext, k:match('[^%*]+$')) then + if self:fileNameEq(ext, k:match('[^%*]+$')) then if v == 'lua' then return true else @@ -220,7 +220,7 @@ function mt:isLuaFile(path) end end end - if fileNameEq(ext, '.lua') then + if self:fileNameEq(ext, '.lua') then return true end return false @@ -397,7 +397,7 @@ function mt:matchPath(baseUri, input) local list = self:convertPathAsRequire(trueFilename, start + 1) if list then for _, str in ipairs(list) do - if #str >= #input and fileNameEq(str:sub(1, #input), input) then + if #str >= #input and self:fileNameEq(str:sub(1, #input), input) then if not map[str] then map[str] = trueFilename else |