summaryrefslogtreecommitdiff
path: root/server/src/method/textDocument
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-23 15:16:36 +0800
committersumneko <sumneko@hotmail.com>2019-04-23 15:16:36 +0800
commit67a10cf8b7eb64579d9c7ba4ab0c28a5389a72fd (patch)
tree20bcf9bc669048639be025b26401ccb250a86f6b /server/src/method/textDocument
parent7b543e55d63de2ee64f96a86f087ff5b108332a6 (diff)
downloadlua-language-server-67a10cf8b7eb64579d9c7ba4ab0c28a5389a72fd.zip
修正全局值转到定义过慢的问题
Diffstat (limited to 'server/src/method/textDocument')
-rw-r--r--server/src/method/textDocument/definition.lua27
-rw-r--r--server/src/method/textDocument/references.lua10
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()