| 69 | } |
| 70 | |
| 71 | void CodeActionService::Spell(lsp::Diagnostic &diagnostic, std::shared_ptr<lsp::CodeActionParams> param, |
| 72 | std::shared_ptr<lsp::CodeActionResult> result) { |
| 73 | auto &originText = diagnostic.data; |
| 74 | if (originText.empty()) { |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | // add to custom dictionary |
| 79 | { |
| 80 | auto &action = result->actions.emplace_back(); |
| 81 | |
| 82 | action.title = util::format("Add '{}' to workspace dictionary", originText); |
| 83 | action.command.title = action.title; |
| 84 | action.command.command = _owner->GetService<CommandService>()->GetCommand( |
| 85 | CommandService::Command::SpellAddDict); |
| 86 | action.command.arguments.emplace_back(originText); |
| 87 | |
| 88 | action.kind = lsp::CodeActionKind::QuickFix; |
| 89 | } |
| 90 | |
| 91 | auto spellChecker = _owner->GetService<DiagnosticService>()->GetSpellChecker(); |
| 92 | auto suggests = spellChecker->GetSuggests(originText); |
| 93 | for (auto &suggest: suggests) { |
| 94 | if (!suggest.Term.empty()) { |
| 95 | if (result->actions.size() >= 15) { |
| 96 | break; |
| 97 | } |
| 98 | auto &action = result->actions.emplace_back(); |
| 99 | auto &term = suggest.Term; |
| 100 | |
| 101 | action.title = term; |
| 102 | action.command.title = term; |
| 103 | action.command.command = _owner->GetService<CommandService>()->GetCommand( |
| 104 | CommandService::Command::SpellCorrect); |
| 105 | action.command.arguments.emplace_back(param->textDocument.uri); |
| 106 | action.command.arguments.push_back(diagnostic.range.Serialize()); |
| 107 | action.command.arguments.emplace_back(term); |
| 108 | |
| 109 | action.kind = lsp::CodeActionKind::QuickFix; |
| 110 | } |
| 111 | } |
| 112 | } |
nothing calls this directly
no test coverage detected