diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/method/textDocument/definition.lua | 33 | ||||
-rw-r--r-- | server/src/method/textDocument/implementation.lua | 32 | ||||
-rw-r--r-- | server/src/method/workspace/didChangeConfiguration.lua | 2 | ||||
-rw-r--r-- | server/src/service.lua | 2 |
4 files changed, 61 insertions, 8 deletions
diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua index e1c45317..d9c32b36 100644 --- a/server/src/method/textDocument/definition.lua +++ b/server/src/method/textDocument/definition.lua @@ -10,12 +10,13 @@ local function checkWorkSpaceComplete(lsp, source) lsp:checkWorkSpaceComplete() end -return function (lsp, params) +local function findResult(lsp, params) local uri = params.textDocument.uri local vm, lines = lsp:loadVM(uri) if not vm then return nil end + -- lua是从1开始的,因此都要+1 local position = lines:positionAsChar(params.position.line + 1, params.position.character) local source = core.findSource(vm, position) @@ -54,7 +55,33 @@ return function (lsp, params) end end - local response = locations + if #locations == 0 then + return nil + end + + return locations +end - return response +local LastTask + +return function (lsp, params) + if LastTask then + LastTask:remove() + LastTask = nil + end + local result = findResult(lsp, params) + if result then + return result + end + return function (response) + LastTask = ac.loop(0.1, function () + if lsp:isWaitingCompile() then + return + end + LastTask:remove() + LastTask = nil + local result = findResult(lsp, params) + response(result) + end) + end end diff --git a/server/src/method/textDocument/implementation.lua b/server/src/method/textDocument/implementation.lua index 8bd35a6c..a4d45169 100644 --- a/server/src/method/textDocument/implementation.lua +++ b/server/src/method/textDocument/implementation.lua @@ -10,7 +10,7 @@ local function checkWorkSpaceComplete(lsp, source) lsp:checkWorkSpaceComplete() end -return function (lsp, params) +local function findResult(lsp, params) local uri = params.textDocument.uri local vm, lines = lsp:loadVM(uri) if not vm then @@ -54,7 +54,33 @@ return function (lsp, params) end end - local response = locations + if #locations == 0 then + return nil + end + + return locations +end + +local LastTask - return response +return function (lsp, params) + if LastTask then + LastTask:remove() + LastTask = nil + end + local result = findResult(lsp, params) + if result then + return result + end + return function (response) + LastTask = ac.loop(0.1, function () + if lsp:isWaitingCompile() then + return + end + LastTask:remove() + LastTask = nil + local result = findResult(lsp, params) + response(result) + end) + end end diff --git a/server/src/method/workspace/didChangeConfiguration.lua b/server/src/method/workspace/didChangeConfiguration.lua index 7a00676d..dd1f84ff 100644 --- a/server/src/method/workspace/didChangeConfiguration.lua +++ b/server/src/method/workspace/didChangeConfiguration.lua @@ -58,7 +58,7 @@ return function (lsp) lsp:reDiagnostic() end if not eq(oldConfig.workspace, newConfig.workspace) then - lsp:ClearAllFiles() + lsp:clearAllFiles() lsp.workspace:scanFiles() end end) diff --git a/server/src/service.lua b/server/src/service.lua index d5a66a92..586aa937 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -249,7 +249,7 @@ function mt:reDiagnostic() end end -function mt:ClearAllFiles() +function mt:clearAllFiles() for uri in pairs(self._file) do self:removeText(uri) self:clearDiagnostics(uri) |