From dee5b2a983f6a334753be48730868e8dd651b505 Mon Sep 17 00:00:00 2001 From: Matthias Deiml Date: Wed, 9 Nov 2022 10:17:09 +0100 Subject: Add LSP workspace command picker (#3140) * Add workspace command picker * Make command typable * Add optional argument to lsp-workspace-command--- helix-term/src/ui/mod.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index f99dea0b..cca9e9bf 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -390,6 +390,45 @@ pub mod completers { .collect() } + pub fn lsp_workspace_command(editor: &Editor, input: &str) -> Vec { + let matcher = Matcher::default(); + + let (_, doc) = current_ref!(editor); + + let language_server = match doc.language_server() { + Some(language_server) => language_server, + None => { + return vec![]; + } + }; + + let options = match &language_server.capabilities().execute_command_provider { + Some(options) => options, + None => { + return vec![]; + } + }; + + let mut matches: Vec<_> = options + .commands + .iter() + .filter_map(|command| { + matcher + .fuzzy_match(command, input) + .map(|score| (command, score)) + }) + .collect(); + + matches.sort_unstable_by(|(command1, score1), (command2, score2)| { + (Reverse(*score1), command1).cmp(&(Reverse(*score2), command2)) + }); + + matches + .into_iter() + .map(|(command, _score)| ((0..), command.clone().into())) + .collect() + } + pub fn directory(editor: &Editor, input: &str) -> Vec { filename_impl(editor, input, |entry| { let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir()); -- cgit v1.2.3-70-g09d2