aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorCossonLeo2021-10-24 07:55:29 +0000
committerGitHub2021-10-24 07:55:29 +0000
commit971ba8929fcc879c2c24b9ab204849500ffe6fce (patch)
treec3650566971e44da593fab25b208e4af70608fa9 /helix-term/src
parent0cb5e0b2caba61bbcf6f57ce58506882766d5eea (diff)
Filter completion items from language server by starts_with word under cursor (#883)
* filter items by starts_with pre nth char of cursor * add config for filter completion items by starts_with * filter items by starts_with pre nth char of cursor * add config for filter completion items by starts_with * remove completion items pre filter configuratio
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 9d73ba6e..07485f9f 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -4142,6 +4142,7 @@ pub fn completion(cx: &mut Context) {
iter.reverse();
let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count();
let start_offset = cursor.saturating_sub(offset);
+ let prefix = text.slice(start_offset..cursor).to_string();
cx.callback(
future,
@@ -4154,7 +4155,7 @@ pub fn completion(cx: &mut Context) {
return;
}
- let items = match response {
+ let mut items = match response {
Some(lsp::CompletionResponse::Array(items)) => items,
// TODO: do something with is_incomplete
Some(lsp::CompletionResponse::List(lsp::CompletionList {
@@ -4164,6 +4165,18 @@ pub fn completion(cx: &mut Context) {
None => Vec::new(),
};
+ if !prefix.is_empty() {
+ items = items
+ .into_iter()
+ .filter(|item| {
+ item.filter_text
+ .as_ref()
+ .unwrap_or(&item.label)
+ .starts_with(&prefix)
+ })
+ .collect();
+ }
+
if items.is_empty() {
// editor.set_error("No completion available".to_string());
return;