on master help sign in
Filter completion items from language server by starts_with word under cursor (#883)
971ba89CossonLeo
helix-term/src/commands.rs+14−1
@@ -4142,6 +4142,7 @@ pub fn completion(cx: &mut Context) {
4142 iter.reverse();
4142 iter.reverse();
4143 let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count();
4143 let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count();
4144 let start_offset = cursor.saturating_sub(offset);
4144 let start_offset = cursor.saturating_sub(offset);
4145+ let prefix = text.slice(start_offset..cursor).to_string();
4145
4146
4146 cx.callback(
4147 cx.callback(
4147 future,
4148 future,
@@ -4154,7 +4155,7 @@ pub fn completion(cx: &mut Context) {
4154 return;
4155 return;
4155 }
4156 }
4156
4157
4157− let items = match response {
4158+ let mut items = match response {
4158 Some(lsp::CompletionResponse::Array(items)) => items,
4159 Some(lsp::CompletionResponse::Array(items)) => items,
4159 // TODO: do something with is_incomplete
4160 // TODO: do something with is_incomplete
4160 Some(lsp::CompletionResponse::List(lsp::CompletionList {
4161 Some(lsp::CompletionResponse::List(lsp::CompletionList {
@@ -4164,6 +4165,18 @@ pub fn completion(cx: &mut Context) {
4164 None => Vec::new(),
4165 None => Vec::new(),
4165 };
4166 };
4166
4167
4168+ if !prefix.is_empty() {
4169+ items = items
4170+ .into_iter()
4171+ .filter(|item| {
4172+ item.filter_text
4173+ .as_ref()
4174+ .unwrap_or(&item.label)
4175+ .starts_with(&prefix)
4176+ })
4177+ .collect();
4178+ }
4179+
4167 if items.is_empty() {
4180 if items.is_empty() {
4168 // editor.set_error("No completion available".to_string());
4181 // editor.set_error("No completion available".to_string());
4169 return;
4182 return;