Skip to content

Commit 91581be

Browse files
committed
update tests
1 parent 4bb7702 commit 91581be

File tree

3 files changed

+19
-56
lines changed

3 files changed

+19
-56
lines changed

crates/ide-completion/src/item.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,12 @@ impl Builder {
440440
chars.next().is_some_and(unicode_ident::is_xid_start)
441441
&& chars.all(unicode_ident::is_xid_continue)
442442
})
443-
.join(", ");
443+
// Deliberately concatenated without separators as adding separators e.g.
444+
// `alias1, alias2` results in LSP clients continuing to display the completion even
445+
// after typing a comma or space.
446+
.join("");
444447
if !lookup_doc_aliases.is_empty() {
445-
lookup = SmolStr::from(format!("{lookup} {lookup_doc_aliases}"));
448+
lookup = SmolStr::from(format!("{lookup}{lookup_doc_aliases}"));
446449
}
447450
}
448451
if let [import_edit] = &*self.imports_to_add {
@@ -567,12 +570,9 @@ impl Builder {
567570

568571
#[cfg(test)]
569572
mod tests {
570-
use ide_db::SymbolKind;
571573
use itertools::Itertools;
572574
use test_utils::assert_eq_text;
573575

574-
use crate::{CompletionItem, CompletionItemKind};
575-
576576
use super::{
577577
CompletionRelevance, CompletionRelevancePostfixMatch, CompletionRelevanceTypeMatch,
578578
};
@@ -647,19 +647,4 @@ mod tests {
647647

648648
check_relevance_score_ordered(expected_relevance_order);
649649
}
650-
651-
#[test]
652-
fn exclude_non_identifier_aliases_from_lookup() {
653-
let mut item = CompletionItem::new(
654-
CompletionItemKind::SymbolKind(SymbolKind::Trait),
655-
Default::default(),
656-
"PartialOrd",
657-
);
658-
let aliases = [">", "<", "<=", ">="];
659-
item.doc_aliases(aliases.iter().map(|&alias| alias.into()).collect());
660-
let item = item.build(&Default::default());
661-
for alias in aliases {
662-
assert!(!item.lookup().contains(alias));
663-
}
664-
}
665650
}

crates/ide-completion/src/tests.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ mod type_pos;
2323
mod use_tree;
2424
mod visibility;
2525

26-
use std::ops::ControlFlow;
27-
2826
use expect_test::Expect;
2927
use hir::PrefixKind;
3028
use ide_db::{
@@ -187,29 +185,11 @@ pub(crate) fn check_edit_with_config(
187185
let (db, position) = position(ra_fixture_before);
188186
let completions: Vec<CompletionItem> =
189187
crate::completions(&db, &config, position, None).unwrap();
190-
let matching = completions
188+
let (completion,) = completions
191189
.iter()
192-
// Match IDE behavior by considering completions as matching if `what` is a subsequence
193-
// of the completion's lookup text.
194-
.filter(|it| {
195-
let mut lookup = it.lookup().chars();
196-
what.chars().all(|c| lookup.contains(&c))
197-
})
198-
// Select the first exact match if one exists, or the first subsequence match if not
199-
.try_fold(None, |first_match, completion| {
200-
let exact_match = completion.lookup() == what;
201-
if exact_match {
202-
ControlFlow::Break(completion)
203-
} else {
204-
ControlFlow::Continue(first_match.or(Some(completion)))
205-
}
206-
});
207-
let completion = match matching {
208-
ControlFlow::Continue(first_match) => first_match
209-
.unwrap_or_else(|| panic!("can't find {what:?} completion in {completions:#?}")),
210-
ControlFlow::Break(exact_match) => exact_match,
211-
};
212-
190+
.filter(|it| it.lookup() == what)
191+
.collect_tuple()
192+
.unwrap_or_else(|| panic!("can't find {what:?} completion in {completions:#?}"));
213193
let mut actual = db.file_text(position.file_id).to_string();
214194

215195
let mut combined_edit = completion.text_edit.clone();

crates/ide-completion/src/tests/special.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,26 +1282,24 @@ fn here_we_go() {
12821282
}
12831283

12841284
#[test]
1285-
fn completion_filtering_excludes_non_identifier_aliases() {
1286-
// Catch panic instead of using `#[should_panic]` as style check bans
1287-
// `#[should_panic]`. Making `check_edit` return a result would require
1288-
// a lot of test changes.
1289-
std::panic::catch_unwind(|| {
1290-
check_edit(
1291-
"Partial>",
1292-
r#"
1285+
fn completion_filtering_excludes_non_identifier_doc_aliases() {
1286+
check_edit(
1287+
"PartialOrdcmporder",
1288+
r#"
12931289
#[doc(alias = ">")]
1290+
#[doc(alias = "cmp")]
1291+
#[doc(alias = "order")]
12941292
trait PartialOrd {}
12951293
12961294
struct Foo<T: Partial$0
12971295
"#,
1298-
r#"
1296+
r#"
12991297
#[doc(alias = ">")]
1298+
#[doc(alias = "cmp")]
1299+
#[doc(alias = "order")]
13001300
trait PartialOrd {}
13011301
13021302
struct Foo<T: PartialOrd
13031303
"#,
1304-
)
1305-
})
1306-
.unwrap_err();
1304+
);
13071305
}

0 commit comments

Comments
 (0)