diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/locale/en-US/script.lni | 4 | ||||
-rw-r--r-- | server/locale/zh-CN/script.lni | 2 | ||||
-rw-r--r-- | server/src/method/textDocument/codeAction.lua | 49 |
3 files changed, 46 insertions, 9 deletions
diff --git a/server/locale/en-US/script.lni b/server/locale/en-US/script.lni index d70492c8..1bec292e 100644 --- a/server/locale/en-US/script.lni +++ b/server/locale/en-US/script.lni @@ -41,7 +41,8 @@ PARSER_KEYWORD = '<keyword> cannot be used as name.' PARSER_EXP_IN_ACTION = 'Unexpected <exp> .' PARSER_BREAK_OUTSIDE = '<break> not inside a loop.' PARSER_MALFORMED_NUMBER = 'Malformed number.' -PARSER_ACTION_AFTER_RETURN = '<eof> expected.' +PARSER_ACTION_AFTER_RETURN = '<eof> expected after `return`.' +PARSER_ACTION_AFTER_BREAK = '<eof> expected after `break`.' PARSER_NO_VISIBLE_LABEL = 'No visible label `{label}` .' PARSER_REDEFINE_LABEL = 'Label `{label}` already defined.' PARSER_UNSUPPORT_SYMBOL = '{version} does not support this grammar.' @@ -55,6 +56,7 @@ ACTION_ADD_SEMICOLON = 'Add `;` .' ACTION_ADD_BRACKETS = 'Add brackets.' ACTION_RUNTIME_VERSION = 'Change runtime version to {} .' ACTION_OPEN_LIBRARY = 'Load globals from {} .' +ACTION_ADD_DO_END = 'Add `do ... end` .' COMMAND_DISABLE_DIAG = 'Disable diagnostics' COMMAND_MARK_GLOBAL = 'Mark defined global' diff --git a/server/locale/zh-CN/script.lni b/server/locale/zh-CN/script.lni index bac2a238..cca71763 100644 --- a/server/locale/zh-CN/script.lni +++ b/server/locale/zh-CN/script.lni @@ -42,6 +42,7 @@ PARSER_EXP_IN_ACTION = '表达式不能独立存在。' PARSER_BREAK_OUTSIDE = '`break`必须在循环内部。' PARSER_MALFORMED_NUMBER = '无法构成有效数字。' PARSER_ACTION_AFTER_RETURN = '`return`之后不能再执行代码。' +PARSER_ACTION_AFTER_BREAK = '`break`之后不能再执行代码。' PARSER_NO_VISIBLE_LABEL = '标签`{label}`不可见。' PARSER_REDEFINE_LABEL = '标签`{label}`重复定义。' PARSER_UNSUPPORT_SYMBOL = '{version} 不支持该符号。' @@ -55,6 +56,7 @@ ACTION_ADD_SEMICOLON = '添加 `;` 。' ACTION_ADD_BRACKETS = '添加括号。' ACTION_RUNTIME_VERSION = '修改运行版本为 {} 。' ACTION_OPEN_LIBRARY = '加载 {} 中的全局变量。' +ACTION_ADD_DO_END = '添加 `do ... end` 。' COMMAND_DISABLE_DIAG = '禁用诊断' COMMAND_MARK_GLOBAL = '标记全局变量' 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 |