diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-27 09:56:16 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-27 09:56:16 +0800 |
commit | b99a2b5fc819d2a519f6bae52b8fbd8babf834d4 (patch) | |
tree | 0bfb93f9ffee15d05eb4a5880d16a83836ecb820 /server | |
parent | bd4447c9128af36c14d786af2626c370f543c1d0 (diff) | |
download | lua-language-server-b99a2b5fc819d2a519f6bae52b8fbd8babf834d4.zip |
寻找定义等待编译
Diffstat (limited to 'server')
-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) |