diff options
author | sumneko <sumneko@hotmail.com> | 2019-05-13 15:07:36 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-05-13 15:07:36 +0800 |
commit | db93eef2333a437e5bcdde1ac164677e78a74356 (patch) | |
tree | f1ba742e473cdaf525c6e110ffc4f9237772641d /server/src | |
parent | aff1423844b2e9bfa5361335295a3c24fd0fd5bd (diff) | |
download | lua-language-server-db93eef2333a437e5bcdde1ac164677e78a74356.zip |
监视 .gitignore 与 .gitmodules 更改,重新扫描文件
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 |