aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/mod.rs
diff options
context:
space:
mode:
authorMatthias Deiml2022-11-09 09:17:09 +0000
committerGitHub2022-11-09 09:17:09 +0000
commitdee5b2a983f6a334753be48730868e8dd651b505 (patch)
tree3fe0e73147ccef4e4fc5703686646da6bf7dfb0e /helix-term/src/ui/mod.rs
parent3e84434c695379dd2b56415c5cec46990488d007 (diff)
Add LSP workspace command picker (#3140)
* Add workspace command picker * Make command typable * Add optional argument to lsp-workspace-command
Diffstat (limited to 'helix-term/src/ui/mod.rs')
-rw-r--r--helix-term/src/ui/mod.rs39
1 files changed, 39 insertions, 0 deletions
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<Completion> {
+ 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<Completion> {
filename_impl(editor, input, |entry| {
let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir());