From 72382639d52d66de5807157fea232646d27f9554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 26 Dec 2018 14:09:54 +0800 Subject: =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=97=A0=E6=B3=95=E8=B7=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9C=8B=E5=88=B0=E5=AF=B9=E6=96=B9=E8=A1=A8=E9=87=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/matcher/vm.lua | 22 ++++++++++++++++++--- server/test/crossfile/completion.lua | 38 ++++++++++++++++++++++++++++++++++++ 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', + }, + } +} -- cgit v1.2.3