on master help sign in
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

commit971ba8929fcc879c2c24b9ab204849500ffe6fce authorCossonLeo <20379044+cossonleo@users.noreply.github.com> dateSun 24 Oct 2021, 15:55 (5 years ago) parent0cb5e0b
1 file changed+14−1
helix-term/src/commands.rs+14−1
helix-term/src/commands.rs+14−1
@@ -4142,6 +4142,7 @@ pub fn completion(cx: &mut Context) {
41424142 iter.reverse();
41434143 let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count();
41444144 let start_offset = cursor.saturating_sub(offset);
4145+ let prefix = text.slice(start_offset..cursor).to_string();
41454146
41464147 cx.callback(
41474148 future,
@@ -4154,7 +4155,7 @@ pub fn completion(cx: &mut Context) {
41544155 return;
41554156 }
41564157
4157− let items = match response {
4158+ let mut items = match response {
41584159 Some(lsp::CompletionResponse::Array(items)) => items,
41594160 // TODO: do something with is_incomplete
41604161 Some(lsp::CompletionResponse::List(lsp::CompletionList {
@@ -4164,6 +4165,18 @@ pub fn completion(cx: &mut Context) {
41644165 None => Vec::new(),
41654166 };
41664167
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+
41674180 if items.is_empty() {
41684181 // editor.set_error("No completion available".to_string());
41694182 return;