diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-23 15:16:36 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-23 15:16:36 +0800 |
commit | 67a10cf8b7eb64579d9c7ba4ab0c28a5389a72fd (patch) | |
tree | 20bcf9bc669048639be025b26401ccb250a86f6b | |
parent | 7b543e55d63de2ee64f96a86f087ff5b108332a6 (diff) | |
download | lua-language-server-67a10cf8b7eb64579d9c7ba4ab0c28a5389a72fd.zip |
修正全局值转到定义过慢的问题
-rw-r--r-- | server/main.lua | 2 | ||||
-rw-r--r-- | server/src/method/textDocument/definition.lua | 27 | ||||
-rw-r--r-- | server/src/method/textDocument/references.lua | 10 |
3 files changed, 19 insertions, 20 deletions
diff --git a/server/main.lua b/server/main.lua index 685fce01..ac7860c5 100644 --- a/server/main.lua +++ b/server/main.lua @@ -22,7 +22,7 @@ local function tryDebugger() log.info('Debugger startup, listen port: 11411') end -pcall(tryDebugger) +--pcall(tryDebugger) require 'utility' require 'global_protect' diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua index d37a3cb9..e5656a52 100644 --- a/server/src/method/textDocument/definition.lua +++ b/server/src/method/textDocument/definition.lua @@ -1,18 +1,7 @@ local core = require 'core' -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) - if not source then - return nil - end +local function findResult(lsp, uri, position) + local vm = lsp:getVM(uri) local positions, isGlobal = core.definition(vm, position, 'definition') if not positions then @@ -67,14 +56,24 @@ end local LastTask return function (lsp, params) + local uri = params.textDocument.uri + local vm, lines = lsp:loadVM(uri) + if not vm then + return nil + end + if LastTask then LastTask:remove() LastTask = nil end + + -- lua是从1开始的,因此都要+1 + local position = lines:positionAsChar(params.position.line + 1, params.position.character) + return function (response) local clock = os.clock() LastTask = ac.loop(0.1, function () - local result, isGlobal = findResult(lsp, params) + local result, isGlobal = findResult(lsp, uri, position) if isGlobal and lsp:isWaitingCompile() and os.clock() - clock < 1 then return end diff --git a/server/src/method/textDocument/references.lua b/server/src/method/textDocument/references.lua index 437aa21e..0a198323 100644 --- a/server/src/method/textDocument/references.lua +++ b/server/src/method/textDocument/references.lua @@ -1,12 +1,12 @@ local core = require 'core' local LastTask -local function findReferences(lsp, uri, position, declarat) +local function findReferences(lsp, uri, position) local vm = lsp:getVM(uri) local positions, isGlobal = core.definition(vm, position, 'reference') if not positions then - return nil + return nil, isGlobal end local locations = {} @@ -72,13 +72,13 @@ return function (lsp, params) return function (response) local clock = os.clock() - LastTask = ac.loop(0.1, function (t) - local positions, isGlobal = findReferences(lsp, uri, position, declarat) + LastTask = ac.loop(0.1, function () + local positions, isGlobal = findReferences(lsp, uri, position) if isGlobal and lsp:isWaitingCompile() and os.clock() - clock < 5 then return end response(positions) - t:remove() + LastTask:remove() LastTask = nil end) LastTask:onTimer() |