From b51c930f3cca060b10ab724666c9f5265cefd517 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Tue, 24 May 2022 11:57:39 +0800 Subject: =?UTF-8?q?=E9=87=8D=E7=BD=AE=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E5=A4=9A=E4=BD=99=E7=9A=84=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/core/code-action.lua | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'script/core/code-action.lua') diff --git a/script/core/code-action.lua b/script/core/code-action.lua index 6bba0a82..09b271c6 100644 --- a/script/core/code-action.lua +++ b/script/core/code-action.lua @@ -350,6 +350,51 @@ local function solveAwaitInSync(uri, diag, results) } end +local function solveSpell(uri, diag, results) + local spell = require 'provider.spell' + local word = diag.data + if word == nil then + return + end + + results[#results+1] = { + title = lang.script('ACTION_ADD_DICT', word), + kind = 'quickfix', + command = { + title = lang.script.COMMAND_ADD_DICT, + command = 'lua.setConfig', + arguments = { + { + key = 'Lua.spell.dict', + action = 'add', + value = word, + uri = uri, + } + } + } + } + + local suggests = spell.getSpellSuggest(word) + for _, suggest in ipairs(suggests) do + results[#results+1] = { + title = suggest, + kind = 'quickfix', + edit = { + changes = { + [uri] = { + { + start = converter.unpackPosition(uri, diag.range.start), + finish = converter.unpackPosition(uri, diag.range["end"]), + newText = suggest + } + } + } + } + } + end + +end + local function solveDiagnostic(uri, diag, start, results) if diag.source == lang.script.DIAG_SYNTAX_CHECK then solveSyntax(uri, diag, results) @@ -370,6 +415,8 @@ local function solveDiagnostic(uri, diag, start, results) solveTrailingSpace(uri, diag, results) elseif diag.code == 'await-in-sync' then solveAwaitInSync(uri, diag, results) + elseif diag.code == 'spell-check' then + solveSpell(uri, diag, results) end disableDiagnostic(uri, diag.code, start, results) end -- cgit v1.2.3