Use more appropriate action for Vim word completions (#28043)

Follow-up of https://github.com/zed-industries/zed/pull/26410

The action does not sort the items the way Vim does, but still better
than the previous state.

Release Notes:

- N/A

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Kirill Bulatov 2025-04-03 13:32:24 -06:00 committed by GitHub
parent 2086f7d85b
commit 3f71ae9897
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 8 deletions

View file

@ -354,8 +354,8 @@
{
"context": "vim_mode == insert && !(showing_code_actions || showing_completions)",
"bindings": {
"ctrl-p": "editor::ShowCompletions",
"ctrl-n": "editor::ShowCompletions"
"ctrl-p": "editor::ShowWordCompletions",
"ctrl-n": "editor::ShowWordCompletions"
}
},
{

View file

@ -4377,7 +4377,7 @@ impl Editor {
);
let words = match completion_settings.words {
WordsCompletionMode::Disabled => Task::ready(HashMap::default()),
WordsCompletionMode::Disabled => Task::ready(BTreeMap::default()),
WordsCompletionMode::Enabled | WordsCompletionMode::Fallback => cx
.background_spawn(async move {
buffer_snapshot.words_in_range(WordsQuery {
@ -4404,7 +4404,7 @@ impl Editor {
let sort_completions = provider
.as_ref()
.map_or(true, |provider| provider.sort_completions());
.map_or(false, |provider| provider.sort_completions());
let filter_completions = provider
.as_ref()
@ -4421,7 +4421,7 @@ impl Editor {
if let Some(provided_completions) = provided_completions.await.log_err().flatten() {
completions.extend(provided_completions);
if completion_settings.words == WordsCompletionMode::Fallback {
words = Task::ready(HashMap::default());
words = Task::ready(BTreeMap::default());
}
}

View file

@ -4120,10 +4120,10 @@ impl BufferSnapshot {
}
}
pub fn words_in_range(&self, query: WordsQuery) -> HashMap<String, Range<Anchor>> {
pub fn words_in_range(&self, query: WordsQuery) -> BTreeMap<String, Range<Anchor>> {
let query_str = query.fuzzy_contents;
if query_str.map_or(false, |query| query.is_empty()) {
return HashMap::default();
return BTreeMap::default();
}
let classifier = CharClassifier::new(self.language.clone().map(|language| LanguageScope {
@ -4135,7 +4135,7 @@ impl BufferSnapshot {
let query_chars = query_str.map(|query| query.chars().collect::<Vec<_>>());
let query_len = query_chars.as_ref().map_or(0, |query| query.len());
let mut words = HashMap::default();
let mut words = BTreeMap::default();
let mut current_word_start_ix = None;
let mut chunk_ix = query.range.start;
for chunk in self.chunks(query.range, false) {