summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/src/core/diagnostics/undefined-global.lua49
-rw-r--r--server-beta/src/files.lua4
-rw-r--r--server-beta/src/provider/init.lua2
-rw-r--r--server-beta/src/searcher/eachGlobal.lua38
-rw-r--r--server-beta/src/searcher/eachRef.lua13
5 files changed, 57 insertions, 49 deletions
diff --git a/server-beta/src/core/diagnostics/undefined-global.lua b/server-beta/src/core/diagnostics/undefined-global.lua
index b39803b8..b3ef3044 100644
--- a/server-beta/src/core/diagnostics/undefined-global.lua
+++ b/server-beta/src/core/diagnostics/undefined-global.lua
@@ -10,27 +10,12 @@ return function (uri, callback)
return
end
- -- 先遍历一次该文件中的全局变量
- -- 如果变量有 set 行为,则做标记
- -- 然后再遍历一次,对所有的行为打上相同标记
- local hasSet = {}
- searcher.eachGlobal(ast.ast, function (info)
- if hasSet[info.source] ~= nil then
+ -- 遍历全局变量,检查所有没有 mode['set'] 的全局变量
+ searcher.eachGlobal(ast.ast, function (infos)
+ if infos.mode['set'] == true then
return
end
- local mark = searcher.eachRef(info.source, function (info)
- if info.mode == 'set' then
- return true
- end
- end)
- searcher.eachRef(info.source, function (info)
- hasSet[info.source] = mark
- end)
- end)
- -- 然后再遍历一次,检查所有标记为假的全局变量
- searcher.eachGlobal(ast.ast, function (info)
- local source = info.source
- local key = info.key
+ local key = infos.key
local skey = key and key:match '^s|(.+)$'
if not skey then
return
@@ -41,20 +26,20 @@ return function (uri, callback)
if config.config.diagnostics.globals[skey] then
return
end
- if info.mode == 'get' and not hasSet[source] then
- local message
- local otherVersion = library.other[skey]
- local customVersion = library.custom[skey]
- if otherVersion then
- message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(otherVersion, '/'), config.config.runtime.version))
- elseif customVersion then
- message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_CUSTOM', table.concat(customVersion, '/')))
- else
- message = lang.script('DIAG_UNDEF_GLOBAL', skey)
- end
+ local message
+ local otherVersion = library.other[skey]
+ local customVersion = library.custom[skey]
+ if otherVersion then
+ message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(otherVersion, '/'), config.config.runtime.version))
+ elseif customVersion then
+ message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_CUSTOM', table.concat(customVersion, '/')))
+ else
+ message = lang.script('DIAG_UNDEF_GLOBAL', skey)
+ end
+ for _, info in ipairs(infos) do
callback {
- start = source.start,
- finish = source.finish,
+ start = info.source.start,
+ finish = info.source.finish,
message = message,
}
end
diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua
index 03a1589e..3c0862c2 100644
--- a/server-beta/src/files.lua
+++ b/server-beta/src/files.lua
@@ -208,9 +208,7 @@ function m.getGlobals(uri)
file.globals = {}
searcher.eachGlobal(ast.ast, function (info)
local name = info.key
- if name then
- file.globals[name] = true
- end
+ file.globals[name] = true
end)
return file.globals
end
diff --git a/server-beta/src/provider/init.lua b/server-beta/src/provider/init.lua
index b510c580..c4835dce 100644
--- a/server-beta/src/provider/init.lua
+++ b/server-beta/src/provider/init.lua
@@ -181,6 +181,6 @@ proto.on('textDocument/definition', function (params)
end)
proto.on('textDocument/completion', function (params)
- log.info(util.dump(params))
+ --log.info(util.dump(params))
return nil
end)
diff --git a/server-beta/src/searcher/eachGlobal.lua b/server-beta/src/searcher/eachGlobal.lua
index 49396b00..8f556976 100644
--- a/server-beta/src/searcher/eachGlobal.lua
+++ b/server-beta/src/searcher/eachGlobal.lua
@@ -4,14 +4,38 @@ local searcher = require 'searcher.searcher'
local function eachGlobal(source, callback)
local root = guide.getRoot(source)
local env = root.locals[1]
- searcher.eachField(env, callback)
+ local result = {}
+ local mark = {}
+ searcher.eachField(env, function (info)
+ local src = info.source
+ if mark[src] then
+ return
+ end
+ mark[src] = true
+ local name = info.key
+ if not result[name] then
+ result[name] = {
+ key = name,
+ mode = {},
+ }
+ end
+ result[name][#result[name]+1] = info
+ result[name].mode[info.mode] = true
+ end)
+ for _, info in pairs(result) do
+ callback(info)
+ end
end
function searcher.eachGlobal(source, callback)
+ source = guide.getRoot(source)
local cache = searcher.cache.eachGlobal[source]
if cache then
for i = 1, #cache do
- callback(cache[i])
+ local res = callback(cache[i])
+ if res ~= nil then
+ return res
+ end
end
return
end
@@ -23,15 +47,13 @@ function searcher.eachGlobal(source, callback)
searcher.cache.eachGlobal[source] = cache
local mark = {}
eachGlobal(source, function (info)
- local src = info.source
- if mark[src] then
- return
- end
- mark[src] = true
cache[#cache+1] = info
end)
unlock()
for i = 1, #cache do
- callback(cache[i])
+ local res = callback(cache[i])
+ if res ~= nil then
+ return res
+ end
end
end
diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua
index e6540b7a..0cfed014 100644
--- a/server-beta/src/searcher/eachRef.lua
+++ b/server-beta/src/searcher/eachRef.lua
@@ -238,12 +238,15 @@ local function ofGlobal(source, callback)
local globals = files.getGlobals(uri)
local ast = files.getAst(uri)
if ast and globals and globals[key] then
- searcher.eachGlobal(ast.ast, function (info)
- if key == info.key then
- callback(info)
- if info.value then
- ofValue(info.value, callback)
+ searcher.eachGlobal(ast.ast, function (infos)
+ if key == infos.key then
+ for _, info in ipairs(infos) do
+ callback(info)
+ if info.value then
+ ofValue(info.value, callback)
+ end
end
+ return true
end
end)
end