summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/locale/en-US/script.lni1
-rw-r--r--server/locale/zh-CN/script.lni1
-rw-r--r--server/src/core/diagnostics.lua7
-rw-r--r--server/src/core/library.lua35
-rw-r--r--server/src/method/textDocument/codeAction.lua75
-rw-r--r--server/src/method/textDocument/publishDiagnostics.lua6
-rw-r--r--server/test/completion/init.lua2
-rw-r--r--server/test/definition/init.lua2
-rw-r--r--server/test/diagnostics/init.lua6
-rw-r--r--server/test/document_symbol/init.lua2
-rw-r--r--server/test/find_lib/init.lua2
-rw-r--r--server/test/full/init.lua2
-rw-r--r--server/test/highlight/init.lua2
-rw-r--r--server/test/hover/init.lua2
-rw-r--r--server/test/references/init.lua2
-rw-r--r--server/test/rename/init.lua2
-rw-r--r--server/test/signature/init.lua2
-rw-r--r--server/test/type_inference/init.lua2
18 files changed, 110 insertions, 43 deletions
diff --git a/server/locale/en-US/script.lni b/server/locale/en-US/script.lni
index d994a404..0f36bd9f 100644
--- a/server/locale/en-US/script.lni
+++ b/server/locale/en-US/script.lni
@@ -12,6 +12,7 @@ DIAG_LOWERCASE_GLOBAL = 'Global variable in lowercase initial'
DIAG_DIAGNOSTICS = 'Diagnostics'
DIAG_SYNTAX_CHECK = 'Syntax Check'
DIAG_NEED_VERSION = 'Supported in {}'
+DIAG_DEFINED_VERSION = 'Defined in {}'
MWS_NOT_SUPPORT = '{} dose not support multi workspace for now, I may need to restart to support the new workspace ...'
MWS_RESTART = 'Restart'
diff --git a/server/locale/zh-CN/script.lni b/server/locale/zh-CN/script.lni
index 343d903c..7c541e98 100644
--- a/server/locale/zh-CN/script.lni
+++ b/server/locale/zh-CN/script.lni
@@ -12,6 +12,7 @@ DIAG_LOWERCASE_GLOBAL = '首字母小写的全局变量'
DIAG_DIAGNOSTICS = '诊断'
DIAG_SYNTAX_CHECK = '语法检查'
DIAG_NEED_VERSION = '在 {} 中是合法的'
+DIAG_DEFINED_VERSION = '在 {} 中有定义'
MWS_NOT_SUPPORT = '{} 目前还不支持多工作目录,我可能需要重启才能支持新的工作目录...'
MWS_RESTART = '重启'
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index 7337dd7b..c38d563b 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -335,9 +335,14 @@ return function (vm, lines, uri)
end)
-- 读取未定义全局变量
session:doDiagnostics(session.searchUndefinedGlobal, 'undefined-global', function (key)
+ local message = lang.script('DIAG_UNDEF_GLOBAL', key)
+ local otherVersion = library.other[key]
+ if otherVersion then
+ message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(otherVersion, '/')))
+ end
return {
level = DiagnosticSeverity.Warning,
- message = lang.script('DIAG_UNDEF_GLOBAL', key),
+ message = message,
}
end)
-- 未使用的Label
diff --git a/server/src/core/library.lua b/server/src/core/library.lua
index 75382912..f943bf8a 100644
--- a/server/src/core/library.lua
+++ b/server/src/core/library.lua
@@ -77,26 +77,52 @@ local function insertGlobal(tbl, key, value)
end
end
if not ok then
- return
+ return false
end
else
if value.version ~= runtimeVersion then
- return
+ return false
end
end
end
tbl[key] = value
+ return true
+end
+
+local function insertOther(tbl, key, value)
+ if not value.version then
+ return
+ end
+ if not tbl[key] then
+ tbl[key] = {}
+ end
+ if type(value.version) == 'string' then
+ tbl[key][#tbl[key]+1] = value.version
+ elseif type(value.version) == 'table' then
+ for _, version in ipairs(value.version) do
+ if type(version) == 'string' then
+ tbl[key][#tbl[key]+1] = version
+ end
+ end
+ end
+ table.sort(tbl[key])
end
local function mergeSource(alllibs, name, lib)
if not lib.source then
- insertGlobal(alllibs.global, name, lib)
+ local suc = insertGlobal(alllibs.global, name, lib)
+ if not suc then
+ insertOther(alllibs.other, name, lib)
+ end
return
end
for _, source in ipairs(lib.source) do
local sourceName = source.name or name
if source.type == 'global' then
- insertGlobal(alllibs.global, sourceName, lib)
+ local suc = insertGlobal(alllibs.global, sourceName, lib)
+ if not suc then
+ insertOther(alllibs.other, sourceName, lib)
+ end
elseif source.type == 'library' then
insertGlobal(alllibs.library, sourceName, lib)
elseif source.type == 'object' then
@@ -213,6 +239,7 @@ local function init()
Library.global = table.container()
Library.library = table.container()
Library.object = table.container()
+ Library.other = table.container()
for path in scan(ROOT / 'libs') do
local libs
diff --git a/server/src/method/textDocument/codeAction.lua b/server/src/method/textDocument/codeAction.lua
index 70e875a6..36b8d90f 100644
--- a/server/src/method/textDocument/codeAction.lua
+++ b/server/src/method/textDocument/codeAction.lua
@@ -1,4 +1,5 @@
local lang = require 'language'
+local library = require 'core.library'
local function disableDiagnostic(lsp, uri, data, callback)
callback {
@@ -18,13 +19,7 @@ local function disableDiagnostic(lsp, uri, data, callback)
}
end
-local function addGlobal(lines, text, data, callback)
- local start = lines:position(data.range.start.line + 1, data.range.start.character + 1)
- local finish = lines:position(data.range['end'].line + 1, data.range['end'].character)
- local name = text:sub(start, finish)
- if #name < 0 or name:find('[^%w_]') then
- return
- end
+local function addGlobal(name, callback)
callback {
title = lang.script('ACTION_MARK_GLOBAL', name),
kind = 'quickfix',
@@ -42,12 +37,43 @@ local function addGlobal(lines, text, data, callback)
}
end
+
+local function changeVersion(version, callback)
+ callback {
+ title = lang.script('ACTION_RUNTIME_VERSION', version),
+ kind = 'quickfix',
+ command = {
+ title = lang.script.COMMAND_RUNTIME_VERSION,
+ command = 'config',
+ arguments = {
+ {
+ key = {'runtime', 'version'},
+ action = 'set',
+ value = version,
+ }
+ }
+ },
+ }
+end
+
local function solveUndefinedGlobal(lsp, uri, data, callback)
local vm, lines, text = lsp:getVM(uri)
if not vm then
return
end
- addGlobal(lines, text, data, callback)
+ local start = lines:position(data.range.start.line + 1, data.range.start.character + 1)
+ local finish = lines:position(data.range['end'].line + 1, data.range['end'].character)
+ local name = text:sub(start, finish)
+ if #name < 0 or name:find('[^%w_]') then
+ return
+ end
+ addGlobal(name, callback)
+ local otherVersion = library.other[name]
+ if otherVersion then
+ for _, version in ipairs(otherVersion) do
+ changeVersion(version, callback)
+ end
+ end
end
local function solveLowercaseGlobal(lsp, uri, data, callback)
@@ -55,7 +81,13 @@ local function solveLowercaseGlobal(lsp, uri, data, callback)
if not vm then
return
end
- addGlobal(lines, text, data, callback)
+ local start = lines:position(data.range.start.line + 1, data.range.start.character + 1)
+ local finish = lines:position(data.range['end'].line + 1, data.range['end'].character)
+ local name = text:sub(start, finish)
+ if #name < 0 or name:find('[^%w_]') then
+ return
+ end
+ addGlobal(name, callback)
end
local function solveTrailingSpace(lsp, uri, data, callback)
@@ -136,22 +168,15 @@ local function solveSyntax(lsp, uri, data, callback)
if not err then
return nil
end
- if err.version then
- callback {
- title = lang.script('ACTION_RUNTIME_VERSION', err.version),
- kind = 'quickfix',
- command = {
- title = lang.script.COMMAND_RUNTIME_VERSION,
- command = 'config',
- arguments = {
- {
- key = {'runtime', 'version'},
- action = 'set',
- value = err.version,
- }
- }
- },
- }
+ if not err.version then
+ return
+ end
+ if type(err.version) == 'table' then
+ for _, version in ipairs(err.version) do
+ changeVersion(version, callback)
+ end
+ else
+ changeVersion(err.version, callback)
end
end
diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua
index ed5ea99d..fbe65bb3 100644
--- a/server/src/method/textDocument/publishDiagnostics.lua
+++ b/server/src/method/textDocument/publishDiagnostics.lua
@@ -83,7 +83,11 @@ local function buildError(err, lines, uri)
message = lang.script('PARSER_'..err.type, err.info)
}
if err.version then
- diagnostic.message = ('%s(%s)'):format(diagnostic.message, lang.script('DIAG_NEED_VERSION', err.version))
+ if type(err.version) == 'table' then
+ diagnostic.message = ('%s(%s)'):format(diagnostic.message, lang.script('DIAG_NEED_VERSION', table.concat(err.version, '/')))
+ else
+ diagnostic.message = ('%s(%s)'):format(diagnostic.message, lang.script('DIAG_NEED_VERSION', err.version))
+ end
end
if err.level == 'error' then
diagnostic.severity = DiagnosticSeverity.Error
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index a36d0cd5..d17b4a83 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -103,7 +103,7 @@ function TEST(script)
return function (expect)
local pos = script:find('@', 1, true) - 1
local new_script = script:gsub('@', ' ')
- local ast = parser:ast(new_script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(new_script, 'lua', 'Lua 5.3')
local vm = buildVM(ast)
assert(vm)
local word = findWord(pos, new_script)
diff --git a/server/test/definition/init.lua b/server/test/definition/init.lua
index 59cf6d3d..e095e474 100644
--- a/server/test/definition/init.lua
+++ b/server/test/definition/init.lua
@@ -40,7 +40,7 @@ function TEST(script)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
- local ast = parser:ast(new_script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(new_script, 'lua', 'Lua 5.3')
assert(ast)
local vm = buildVM(ast)
assert(vm)
diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua
index e0893286..4aac9719 100644
--- a/server/test/diagnostics/init.lua
+++ b/server/test/diagnostics/init.lua
@@ -41,7 +41,7 @@ end
function TEST(script)
local new_script, target = catch_target(script)
local lsp = service()
- local ast = parser:ast(new_script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(new_script, 'lua', 'Lua 5.3')
assert(ast)
local lines = parser:lines(new_script)
local vm = buildVM(ast, lsp)
@@ -246,3 +246,7 @@ TEST [[
local f = load('')
f(1, 2, 3)
]]
+
+TEST [[
+<!warn!>(1)
+]]
diff --git a/server/test/document_symbol/init.lua b/server/test/document_symbol/init.lua
index f14c5951..09e533ac 100644
--- a/server/test/document_symbol/init.lua
+++ b/server/test/document_symbol/init.lua
@@ -76,7 +76,7 @@ end
function TEST(script)
return function (expect)
- local ast = parser:ast(script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(script, 'lua', 'Lua 5.3')
local vm = buildVM(ast)
assert(vm)
local result = core.documentSymbol(vm)
diff --git a/server/test/find_lib/init.lua b/server/test/find_lib/init.lua
index 5f7c5dce..accf1b35 100644
--- a/server/test/find_lib/init.lua
+++ b/server/test/find_lib/init.lua
@@ -10,7 +10,7 @@ function TEST(fullkey)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
- local ast = parser:ast(new_script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(new_script, 'lua', 'Lua 5.3')
assert(ast)
local vm = buildVM(ast)
assert(vm)
diff --git a/server/test/full/init.lua b/server/test/full/init.lua
index 2c92e90b..342ac331 100644
--- a/server/test/full/init.lua
+++ b/server/test/full/init.lua
@@ -4,7 +4,7 @@ local parser = require 'parser'
rawset(_G, 'TEST', true)
function TEST(script)
- local ast = parser:ast(script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(script, 'lua', 'Lua 5.3')
assert(ast)
local vm, err = buildVM(ast)
assert(vm, err)
diff --git a/server/test/highlight/init.lua b/server/test/highlight/init.lua
index e26b0ab3..aa7ab69f 100644
--- a/server/test/highlight/init.lua
+++ b/server/test/highlight/init.lua
@@ -39,7 +39,7 @@ function TEST(newName)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
- local ast = parser:ast(new_script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(new_script, 'lua', 'Lua 5.3')
assert(ast)
local vm = buildVM(ast)
assert(vm)
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index 95be529f..09c14bee 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -10,7 +10,7 @@ function TEST(script)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
- local ast = parser:ast(new_script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(new_script, 'lua', 'Lua 5.3')
local vm = buildVM(ast)
assert(vm)
local source = core.findSource(vm, pos)
diff --git a/server/test/references/init.lua b/server/test/references/init.lua
index 6b53decb..e5d0b1cc 100644
--- a/server/test/references/init.lua
+++ b/server/test/references/init.lua
@@ -38,7 +38,7 @@ function TEST(script)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
- local ast = parser:ast(new_script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(new_script, 'lua', 'Lua 5.3')
assert(ast)
local vm = buildVM(ast)
assert(vm)
diff --git a/server/test/rename/init.lua b/server/test/rename/init.lua
index 1ad8994a..ad7fe650 100644
--- a/server/test/rename/init.lua
+++ b/server/test/rename/init.lua
@@ -39,7 +39,7 @@ function TEST(newName)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
- local ast = parser:ast(new_script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(new_script, 'lua', 'Lua 5.3')
assert(ast)
local vm = buildVM(ast)
assert(vm)
diff --git a/server/test/signature/init.lua b/server/test/signature/init.lua
index 0910ab83..91ef75c8 100644
--- a/server/test/signature/init.lua
+++ b/server/test/signature/init.lua
@@ -8,7 +8,7 @@ function TEST(script)
return function (expect)
local pos = script:find('@', 1, true)
local new_script = script:gsub('@', '')
- local ast = parser:ast(new_script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(new_script, 'lua', 'Lua 5.3')
local vm = buildVM(ast)
assert(vm)
local hovers = core.signature(vm, pos)
diff --git a/server/test/type_inference/init.lua b/server/test/type_inference/init.lua
index c966eb18..a4f95caa 100644
--- a/server/test/type_inference/init.lua
+++ b/server/test/type_inference/init.lua
@@ -10,7 +10,7 @@ function TEST(res)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
- local ast = parser:ast(new_script, 'lua', 'Lua 5.4')
+ local ast = parser:ast(new_script, 'lua', 'Lua 5.3')
local vm = buildVM(ast)
assert(vm)
local result = core.findSource(vm, pos)