diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-07-22 11:33:54 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-07-22 11:33:54 +0800 |
commit | a98f8cf8381e5037c282fd3562a41ea6760167bf (patch) | |
tree | c46cb542816f2a853c0bf8b9b3c0bd63c330085e /server/src/core/code_action.lua | |
parent | bc51b878c4958e2977e21b835ec62bcfb4f2b604 (diff) | |
download | lua-language-server-a98f8cf8381e5037c282fd3562a41ea6760167bf.zip |
支持替换修复
Diffstat (limited to 'server/src/core/code_action.lua')
-rw-r--r-- | server/src/core/code_action.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/server/src/core/code_action.lua b/server/src/core/code_action.lua index 3c61ed56..b28bda34 100644 --- a/server/src/core/code_action.lua +++ b/server/src/core/code_action.lua @@ -216,6 +216,36 @@ local function solveSyntaxByAddDoEnd(uri, data, callback) } end +local function solveSyntaxByFix(uri, err, lines, callback) + local changes = {} + for _, e in ipairs(err.fix) do + local start_row, start_col = lines:rowcol(e.start) + local finish_row, finish_col = lines:rowcol(e.finish) + changes[#changes+1] = { + range = { + start = { + line = start_row - 1, + character = start_col - 1, + }, + ['end'] = { + line = finish_row - 1, + character = finish_col, + }, + }, + newText = e.text, + } + end + callback { + title = lang.script[err.fix.title], + kind = 'quickfix', + edit = { + changes = { + [uri] = changes, + } + } + } +end + ---@param lsp LSP ---@param uri uri ---@param data table @@ -239,6 +269,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.fix then + solveSyntaxByFix(uri, err, lines, callback) + end end local function solveDiagnostic(lsp, uri, data, callback) |