From 48e344a2a813b875ca813be726387692b7ba0762 Mon Sep 17 00:00:00 2001 From: Grzegorz Baranski Date: Sat, 24 Jul 2021 03:26:43 +0200 Subject: feat: code actions - document edits (#478) * wip: Code actions * fix(term): use current macro instead Context::context * feat(lsp): set code_action capabilities * feat(term): set SPC-a to code_action * feat(term): wip on applying code actions * deps: `cargo update` * feat(term): applying code actions edits * fix(term): cleanup of apply_edit * fix(term): applying edits as a whole thing instead one by one * refactor(term): move apply_edits below * fix(term): improve unimplemented messages for further investigation * fix(term): change code action command comment Co-authored-by: Ivan Tham * fix(term): add matching `}` * fix(term): cleanup, todo!() on workspace edit * fix(term): remove unrelated workspace_symbol_picker * fix(term): apply cargo-clippy suggestions * fix(term): replace todo!'s with editor.set_error Co-authored-by: Blaž Hrastnik Co-authored-by: Ivan Tham --- helix-lsp/src/client.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'helix-lsp/src') diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 1c2a49b5..fd34f45d 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -247,6 +247,26 @@ impl Client { content_format: Some(vec![lsp::MarkupKind::Markdown]), ..Default::default() }), + code_action: Some(lsp::CodeActionClientCapabilities { + code_action_literal_support: Some(lsp::CodeActionLiteralSupport { + code_action_kind: lsp::CodeActionKindLiteralSupport { + value_set: [ + lsp::CodeActionKind::EMPTY, + lsp::CodeActionKind::QUICKFIX, + lsp::CodeActionKind::REFACTOR, + lsp::CodeActionKind::REFACTOR_EXTRACT, + lsp::CodeActionKind::REFACTOR_INLINE, + lsp::CodeActionKind::REFACTOR_REWRITE, + lsp::CodeActionKind::SOURCE, + lsp::CodeActionKind::SOURCE_ORGANIZE_IMPORTS, + ] + .iter() + .map(|kind| kind.as_str().to_string()) + .collect(), + }, + }), + ..Default::default() + }), ..Default::default() }), window: Some(lsp::WindowClientCapabilities { @@ -713,4 +733,31 @@ impl Client { self.call::(params) } + + // empty string to get all symbols + pub fn workspace_symbols(&self, query: String) -> impl Future> { + let params = lsp::WorkspaceSymbolParams { + query, + work_done_progress_params: lsp::WorkDoneProgressParams::default(), + partial_result_params: lsp::PartialResultParams::default(), + }; + + self.call::(params) + } + + pub fn code_actions( + &self, + text_document: lsp::TextDocumentIdentifier, + range: lsp::Range, + ) -> impl Future> { + let params = lsp::CodeActionParams { + text_document, + range, + context: lsp::CodeActionContext::default(), + work_done_progress_params: lsp::WorkDoneProgressParams::default(), + partial_result_params: lsp::PartialResultParams::default(), + }; + + self.call::(params) + } } -- cgit v1.2.3-70-g09d2