summaryrefslogtreecommitdiff
path: root/server/src/method/textDocument/codeAction.lua
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-03 20:42:40 +0800
committersumneko <sumneko@hotmail.com>2019-04-03 20:42:40 +0800
commit8989f2503db172023f14ab1715709267fe87e371 (patch)
treeb48127faf70d8c1f2d12c68351446208f30334d1 /server/src/method/textDocument/codeAction.lua
parent46e2b37d95bd14394b0a10f7c198e559d209aaa3 (diff)
downloadlua-language-server-8989f2503db172023f14ab1715709267fe87e371.zip
检测未定义变量
Diffstat (limited to 'server/src/method/textDocument/codeAction.lua')
-rw-r--r--server/src/method/textDocument/codeAction.lua75
1 files changed, 50 insertions, 25 deletions
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