diff options
-rw-r--r-- | server/src/core/code_action.lua | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/server/src/core/code_action.lua b/server/src/core/code_action.lua index 9f3e0338..7291e3a7 100644 --- a/server/src/core/code_action.lua +++ b/server/src/core/code_action.lua @@ -246,6 +246,67 @@ local function solveSyntaxByFix(uri, err, lines, callback) } end +local function findEndPosition(err, lines, row, endrow) + if endrow == row then + return { + newText = ' end', + range = { + start = { + line = row - 1, + character = 999999, + }, + ['end'] = { + line = row - 1, + character = 999999, + } + } + } + else + local l = lines[row] + return { + newText = ('\t'):rep(l.tab) .. (' '):rep(l.sp) .. 'end\n', + range = { + start = { + line = endrow, + character = 0, + }, + ['end'] = { + line = endrow, + character = 0, + } + } + } + end +end + +local function solveSyntaxByAddEnd(uri, err, lines, callback) + local row = lines:rowcol(err.start) + local line = lines[row] + if not line then + return nil + end + local sp = line.sp + line.tab * 4 + for i = row + 1, #lines do + local nl = lines[i] + local lsp = nl.sp + nl.tab * 4 + if lsp <= sp then + callback { + title = lang.script['ACTION_ADD_END'], + kind = 'quickfix', + edit = { + changes = { + [uri] = { + findEndPosition(err, lines, row, i - 1) + } + } + } + } + return + end + end + return nil +end + ---@param lsp LSP ---@param uri uri ---@param data table @@ -269,6 +330,9 @@ local function solveSyntax(lsp, uri, data, callback) if err.type == 'ACTION_AFTER_BREAK' or err.type == 'ACTION_AFTER_RETURN' then solveSyntaxByAddDoEnd(uri, data, callback) end + if err.type == 'MISS_END' then + solveSyntaxByAddEnd(uri, err, lines, callback) + end if err.fix then solveSyntaxByFix(uri, err, lines, callback) end @@ -326,5 +390,7 @@ return function (lsp, uri, diagnostics, range) end end + log.debug(table.dump(results)) + return results end |