summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-19 15:15:18 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-19 15:15:18 +0800
commit4087a9774bbfbad2652725684b812ed1eca43bde (patch)
tree8c40c3787ffa721c50c27f2dc788f62b9de64549 /server/src
parent8662a6394eaaa1f0514578299627f7c4ec9808bf (diff)
downloadlua-language-server-4087a9774bbfbad2652725684b812ed1eca43bde.zip
区分重载_ENV的特殊情况
Diffstat (limited to 'server/src')
-rw-r--r--server/src/core/diagnostics.lua23
-rw-r--r--server/src/vm/global.lua1
-rw-r--r--server/src/vm/value.lua36
3 files changed, 44 insertions, 16 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index def54a35..7ebe297a 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -40,15 +40,14 @@ end
function mt:searchUndefinedGlobal(callback)
local definedGlobal = {}
- local definedValue = {}
for name in pairs(config.config.diagnostics.globals) do
definedGlobal[name] = true
end
local envValue = self.vm.env:getValue()
envValue:eachInfo(function (info)
if info.type == 'set child' then
- local value = info[2]
- definedValue[value] = true
+ local name = info[1]
+ definedGlobal[name] = true
end
end)
self.vm:eachSource(function (source)
@@ -59,14 +58,24 @@ function mt:searchUndefinedGlobal(callback)
if name == '' then
return
end
- if definedGlobal[name] then
- return
- end
local value = source:bindValue()
if not value then
return
end
- if definedValue[value] then
+ if not value:isGlobal() then
+ -- 上文重载了 _ENV 的情况
+ local ok = value:eachInfo(function (info)
+ if info.type == 'set' then
+ return true
+ end
+ end)
+ if ok then
+ return
+ end
+ callback(source.start, source.finish, name)
+ return
+ end
+ if definedGlobal[name] then
return
end
if type(name) ~= 'string' then
diff --git a/server/src/vm/global.lua b/server/src/vm/global.lua
index a775acd8..806c8931 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:markGlobal()
for k, v in pairs(t) do
global:setChild(k, v, sourceMgr.dummy())
end
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index 838bca15..7ac70181 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -10,6 +10,7 @@ mt.type = 'value'
mt.uri = ''
mt._infoCount = 0
mt._infoLimit = 10
+mt._global = false
local function create (tp, source, literal)
if tp == '...' then
@@ -97,6 +98,9 @@ function mt:rawSet(index, value, source)
self._child[index] = value
end
self:addInfo('set child', source, index, value)
+ if self._global then
+ value:markGlobal()
+ end
end
function mt:rawGet(index)
@@ -248,15 +252,15 @@ function mt:mergeValue(value)
end
end
value._type = self._type
- if value._child then
- if not self._child then
- self._child = {}
- end
- for k, v in pairs(value._child) do
- self._child[k] = v
- end
- end
- value._child = self._child
+ --if value._child then
+ -- if not self._child then
+ -- self._child = {}
+ -- end
+ -- for k, v in pairs(value._child) do
+ -- self._child[k] = v
+ -- end
+ --end
+ --value._child = self._child
for srcId, info in pairs(value._info) do
local src = sourceMgr.list[srcId]
@@ -383,4 +387,18 @@ function mt:getSource()
return sourceMgr.list[self.source]
end
+function mt:markGlobal()
+ if self._global then
+ return
+ end
+ self._global = true
+ self:rawEach(function (index, value)
+ value:markGlobal()
+ end)
+end
+
+function mt:isGlobal()
+ return self._global
+end
+
return create