summaryrefslogtreecommitdiff
path: root/server/src/matcher
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-21 10:07:38 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-21 10:07:38 +0800
commit8254afb1d359e8db10883f56f1474c7a7a7e3779 (patch)
tree8327090b78be1ee0a899c52baa4d78c6661d4b04 /server/src/matcher
parentf8c11fb3a7cd46905f45754c47b363d822738380 (diff)
downloadlua-language-server-8254afb1d359e8db10883f56f1474c7a7a7e3779.zip
转到实现支持跨文件
Diffstat (limited to 'server/src/matcher')
-rw-r--r--server/src/matcher/definition.lua2
-rw-r--r--server/src/matcher/implementation.lua70
2 files changed, 59 insertions, 13 deletions
diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua
index fd3cc412..18804516 100644
--- a/server/src/matcher/definition.lua
+++ b/server/src/matcher/definition.lua
@@ -1,6 +1,4 @@
local findResult = require 'matcher.find_result'
-local rpc = require 'rpc'
-
local function parseResultAcrossUri(positions, vm, result)
-- 跨越文件时,遍历的是值的绑定信息
diff --git a/server/src/matcher/implementation.lua b/server/src/matcher/implementation.lua
index 72d2411f..03b163e3 100644
--- a/server/src/matcher/implementation.lua
+++ b/server/src/matcher/implementation.lua
@@ -1,28 +1,76 @@
local findResult = require 'matcher.find_result'
-local function parseResult(result)
+local function parseResultAcrossUri(positions, vm, result)
+ -- 跨越文件时,遍历的是值的绑定信息
+ for _, info in ipairs(result.value) do
+ if info.type == 'set' and info.source.uri == result.value.uri then
+ positions[#positions+1] = {
+ info.source.start,
+ info.source.finish,
+ info.source.uri,
+ }
+ end
+ end
+ if #positions == 0 then
+ for _, info in ipairs(result.value) do
+ if info.type == 'return' and info.source.uri == result.value.uri then
+ positions[#positions+1] = {
+ info.source.start,
+ info.source.finish,
+ info.source.uri,
+ }
+ end
+ end
+ end
+end
+
+local function parseResult(vm, result)
local positions = {}
local tp = result.type
if tp == 'local' then
- for _, info in ipairs(result) do
- if info.type == 'set' then
- positions[#positions+1] = {info.source.start, info.source.finish}
+ if result.value.uri ~= vm.uri then
+ parseResultAcrossUri(positions, vm, result)
+ else
+ for _, info in ipairs(result) do
+ if info.type == 'set' then
+ positions[#positions+1] = {
+ info.source.start,
+ info.source.finish,
+ info.source.uri,
+ }
+ end
end
end
elseif tp == 'field' then
- for _, info in ipairs(result) do
- if info.type == 'set' then
- positions[#positions+1] = {info.source.start, info.source.finish}
+ if result.value.uri ~= vm.uri then
+ parseResultAcrossUri(positions, vm, result)
+ else
+ for _, info in ipairs(result) do
+ if info.type == 'set' then
+ positions[#positions+1] = {
+ info.source.start,
+ info.source.finish,
+ info.source.uri,
+ }
+ end
end
end
elseif tp == 'label' then
for _, info in ipairs(result) do
if info.type == 'set' then
- positions[#positions+1] = {info.source.start, info.source.finish}
+ positions[#positions+1] = {
+ info.source.start,
+ info.source.finish,
+ }
end
end
- else
- error('Unknow result type:' .. result.type)
+ elseif tp == 'string' then
+ -- require 'XXX' 专用
+ positions[#positions+1] = {
+ 0,
+ 0,
+ result.uri,
+ }
end
return positions
end
@@ -32,6 +80,6 @@ return function (vm, pos)
if not result then
return nil
end
- local positions = parseResult(result)
+ local positions = parseResult(vm, result)
return positions
end