summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-26 14:09:54 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-26 14:09:54 +0800
commit72382639d52d66de5807157fea232646d27f9554 (patch)
treeb586516742f972a6eaa31e7f431448bd0486f872
parentca498542d4424322e2172425ab02a8986deb477b (diff)
downloadlua-language-server-72382639d52d66de5807157fea232646d27f9554.zip
修正无法跨文件看到对方表里数据的问题
-rw-r--r--server/src/matcher/vm.lua22
-rw-r--r--server/test/crossfile/completion.lua38
2 files changed, 57 insertions, 3 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 1b098785..e2ea5a15 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -36,8 +36,12 @@ local function orderTable()
end
local function readOnly(t)
+ local keys
return setmetatable({}, {
__index = function (self, k)
+ if k == nil then
+ return nil
+ end
local v = t[k]
if type(v) == 'table' then
v = readOnly(v)
@@ -48,6 +52,20 @@ local function readOnly(t)
__len = function (self)
return #t
end,
+ __pairs = function (self)
+ if not keys then
+ keys = {}
+ for k in pairs(t) do
+ keys[#keys+1] = k
+ end
+ end
+ local i = 0
+ return function ()
+ i = i + 1
+ local k = keys[i]
+ return k, self[k]
+ end
+ end,
__source = t,
})
end
@@ -218,9 +236,7 @@ function mt:mergeValue(a, b, mark)
end
mark[a] = true
mark[b] = true
- if b.uri == self.uri then
- self:mergeChild(a, b, mark)
- end
+ self:mergeChild(a, b, mark)
for k in pairs(a) do
a[k] = nil
end
diff --git a/server/test/crossfile/completion.lua b/server/test/crossfile/completion.lua
index 15b19176..7d4513ba 100644
--- a/server/test/crossfile/completion.lua
+++ b/server/test/crossfile/completion.lua
@@ -217,3 +217,41 @@ TEST {
},
}
}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ return {
+ a = 1,
+ b = 2,
+ c = 3,
+ }
+ ]]
+ },
+ {
+ path = 'b.lua',
+ content = [[
+ local t = require 'a'
+ t.@
+ ]],
+ main = true,
+ },
+ completion = {
+ {
+ label = 'a',
+ kind = CompletionItemKind.Enum,
+ detail = '= 1',
+ },
+ {
+ label = 'b',
+ kind = CompletionItemKind.Enum,
+ detail = '= 2',
+ },
+ {
+ label = 'c',
+ kind = CompletionItemKind.Enum,
+ detail = '= 3',
+ },
+ }
+}