diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-26 13:22:35 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-26 13:22:35 +0800 |
commit | 1e914171e328c90237b98560cae49f6e386c01cf (patch) | |
tree | 515162ef88473805bd88e2ee018ea49798c331b4 /server | |
parent | 097e9c06c9a78d3ae845a7eec694a2dbe99161b0 (diff) | |
download | lua-language-server-1e914171e328c90237b98560cae49f6e386c01cf.zip |
整理代码
Diffstat (limited to 'server')
-rw-r--r-- | server/src/matcher/definition.lua | 6 | ||||
-rw-r--r-- | server/src/method/textDocument/definition.lua | 10 | ||||
-rw-r--r-- | server/test/crossfile/definition.lua | 3 | ||||
-rw-r--r-- | server/test/definition/init.lua | 7 |
4 files changed, 14 insertions, 12 deletions
diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua index b4a19b55..5b79aedd 100644 --- a/server/src/matcher/definition.lua +++ b/server/src/matcher/definition.lua @@ -1,5 +1,3 @@ -local findResult = require 'matcher.find_result' - local function parseResultAcrossUri(positions, vm, result) -- 跨越文件时,遍历的是值的绑定信息 for _, info in ipairs(result.value) do @@ -81,12 +79,10 @@ local function parseResult(vm, result) return positions end -return function (vm, pos) - local result = findResult(vm, pos) +return function (vm, result) if not result then return nil end - local positions = parseResult(vm, result) return positions end diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua index 9115638b..75df54da 100644 --- a/server/src/method/textDocument/definition.lua +++ b/server/src/method/textDocument/definition.lua @@ -4,13 +4,17 @@ return function (lsp, params) local uri = params.textDocument.uri local vm, lines = lsp:loadVM(uri) if not vm then - return {} + return nil end -- lua是从1开始的,因此都要+1 local position = lines:position(params.position.line + 1, params.position.character + 1) - local positions = matcher.definition(vm, position) + local result = matcher.findResult(vm, position) + if not result then + return nil + end + local positions = matcher.definition(vm, result) if not positions then - return {} + return nil end local locations = {} diff --git a/server/test/crossfile/definition.lua b/server/test/crossfile/definition.lua index 230b9ddf..dfc91c31 100644 --- a/server/test/crossfile/definition.lua +++ b/server/test/crossfile/definition.lua @@ -48,7 +48,8 @@ function TEST(data) local sourceVM = lsp:getVM(sourceUri) assert(sourceVM) local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2 - local positions = matcher.definition(sourceVM, sourcePos) + local result = matcher.findResult(sourceVM, sourcePos) + local positions = matcher.definition(sourceVM, result) assert(positions and positions[1]) local start, finish, valueUri = positions[1][1], positions[1][2], positions[1][3] assert(valueUri == targetUri) diff --git a/server/test/definition/init.lua b/server/test/definition/init.lua index 190b5736..38201435 100644 --- a/server/test/definition/init.lua +++ b/server/test/definition/init.lua @@ -44,9 +44,10 @@ function TEST(script) local vm = matcher.vm(ast) assert(vm) - local result = matcher.definition(vm, pos) - if result then - assert(founded(target, result)) + local result = matcher.findResult(vm, pos) + local positions = matcher.definition(vm, result) + if positions then + assert(founded(target, positions)) else assert(#target == 0) end |