diff options
Diffstat (limited to 'server/src/method/textDocument')
-rw-r--r-- | server/src/method/textDocument/definition.lua | 27 | ||||
-rw-r--r-- | server/src/method/textDocument/references.lua | 10 |
2 files changed, 18 insertions, 19 deletions
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() |