summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-09 16:59:14 +0800
committersumneko <sumneko@hotmail.com>2019-04-09 16:59:14 +0800
commit55b572b1b6d7c44f23c656eecfa8498b4c1e55b9 (patch)
treefe69ff5ebf987847ac7a6a79862558b668da4d0f /server/src
parente91edca105721ce5280f746f23eb438b27eb5d55 (diff)
downloadlua-language-server-55b572b1b6d7c44f23c656eecfa8498b4c1e55b9.zip
加个 do end 的快速修复
Diffstat (limited to 'server/src')
-rw-r--r--server/src/method/textDocument/codeAction.lua49
1 files changed, 41 insertions, 8 deletions
diff --git a/server/src/method/textDocument/codeAction.lua b/server/src/method/textDocument/codeAction.lua
index 1d85235a..d924ce11 100644
--- a/server/src/method/textDocument/codeAction.lua
+++ b/server/src/method/textDocument/codeAction.lua
@@ -179,6 +179,43 @@ local function findSyntax(astErr, lines, data)
return nil
end
+local function solveSyntaxByChangeVersion(err, callback)
+ if type(err.version) == 'table' then
+ for _, version in ipairs(err.version) do
+ changeVersion(version, callback)
+ end
+ else
+ changeVersion(err.version, callback)
+ end
+end
+
+local function solveSyntaxByAddDoEnd(uri, data, callback)
+ callback {
+ title = lang.script.ACTION_ADD_DO_END,
+ kind = 'quickfix',
+ edit = {
+ changes = {
+ [uri] = {
+ {
+ range = {
+ start = data.range.start,
+ ['end'] = data.range.start,
+ },
+ newText = 'do ',
+ },
+ {
+ range = {
+ start = data.range['end'],
+ ['end'] = data.range['end'],
+ },
+ newText = ' end',
+ }
+ }
+ }
+ }
+ }
+end
+
local function solveSyntax(lsp, uri, data, callback)
local obj = lsp:getFile(uri)
if not obj then
@@ -192,15 +229,11 @@ local function solveSyntax(lsp, uri, data, callback)
if not err then
return nil
end
- if not err.version then
- return
+ if err.version then
+ solveSyntaxByChangeVersion(err, callback)
end
- if type(err.version) == 'table' then
- for _, version in ipairs(err.version) do
- changeVersion(version, callback)
- end
- else
- changeVersion(err.version, callback)
+ if err.type == 'ACTION_AFTER_BREAK' or err.type == 'ACTION_AFTER_RETURN' then
+ solveSyntaxByAddDoEnd(uri, data, callback)
end
end