summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-15 15:50:39 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-15 15:50:39 +0800
commit9aaf4607376e11a35fe04ef86baa3c18a9d90864 (patch)
treef0e9e025de033dc01e7f76b406d6ae0af7a9fbc7 /server
parentf65de4fabbe2b8b1a66a13661adc26f9b93f5d80 (diff)
downloadlua-language-server-9aaf4607376e11a35fe04ef86baa3c18a9d90864.zip
解除死掉的全局变量引用
Diffstat (limited to 'server')
-rw-r--r--server/src/vm/global.lua1
-rw-r--r--server/src/vm/value.lua23
-rw-r--r--server/test/crossfile/completion.lua35
3 files changed, 56 insertions, 3 deletions
diff --git a/server/src/vm/global.lua b/server/src/vm/global.lua
index dea30525..99f05e37 100644
--- a/server/src/vm/global.lua
+++ b/server/src/vm/global.lua
@@ -12,6 +12,7 @@ return function (lsp)
end
global = t._G
+ global:set('_G', true)
for k, v in pairs(t) do
global:setChild(k, v)
end
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index 60f0c663..67b4536c 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -38,6 +38,19 @@ local function create (tp, source, literal)
return self
end
+local function isDeadGlobalChild(value)
+ if value._lib then
+ return false
+ end
+ for srcId in pairs(value._info) do
+ local src = sourceMgr.list[srcId]
+ if src then
+ return false
+ end
+ end
+ return true
+end
+
function mt:setType(tp, rate)
if type(tp) == 'table' then
for _, ctp in ipairs(tp) do
@@ -92,6 +105,12 @@ function mt:rawGet(index)
if not child then
return nil
end
+ if self:get '_G' then
+ if isDeadGlobalChild(child) then
+ self._child[index] = nil
+ return nil
+ end
+ end
return child
end
@@ -182,6 +201,10 @@ function mt:rawEach(callback, foundIndex)
end
foundIndex[index] = true
end
+ if self:get '_G' and isDeadGlobalChild(value) then
+ self._child[index] = nil
+ goto CONTINUE
+ end
local res = callback(index, value)
if res ~= nil then
return res
diff --git a/server/test/crossfile/completion.lua b/server/test/crossfile/completion.lua
index 0ad6cd21..e63c8384 100644
--- a/server/test/crossfile/completion.lua
+++ b/server/test/crossfile/completion.lua
@@ -106,10 +106,10 @@ function TEST(data)
end
lsp:saveText(uri, 1, script)
ws:addFile(uri)
- end
- while lsp._needCompile[1] do
- lsp:compileVM(lsp._needCompile[1])
+ while lsp._needCompile[1] do
+ lsp:compileVM(lsp._needCompile[1])
+ end
end
local vm = lsp:loadVM(mainUri)
@@ -339,3 +339,32 @@ TEST {
},
}
}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ abc = 1
+ ]]
+ },
+ {
+ path = 'a.lua',
+ content = [[
+ abcdef = 1
+ ]]
+ },
+ {
+ path = 'b.lua',
+ content = [[
+ ab@
+ ]],
+ main = true,
+ },
+ completion = {
+ {
+ label = 'abcdef',
+ kind = CompletionItemKind.Enum,
+ detail = '= 1',
+ },
+ }
+}