mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Merge commit 'baee6b338b
' into sync-from-ra
This commit is contained in:
parent
0155385b57
commit
aa55ce9567
139 changed files with 4248 additions and 1042 deletions
|
@ -427,9 +427,26 @@ impl Builder {
|
|||
let insert_text = self.insert_text.unwrap_or_else(|| label.to_string());
|
||||
|
||||
if !self.doc_aliases.is_empty() {
|
||||
let doc_aliases = self.doc_aliases.into_iter().join(", ");
|
||||
let doc_aliases = self.doc_aliases.iter().join(", ");
|
||||
label = SmolStr::from(format!("{label} (alias {doc_aliases})"));
|
||||
lookup = SmolStr::from(format!("{lookup} {doc_aliases}"));
|
||||
let lookup_doc_aliases = self
|
||||
.doc_aliases
|
||||
.iter()
|
||||
// Don't include aliases in `lookup` that aren't valid identifiers as including
|
||||
// them results in weird completion filtering behavior e.g. `Partial>` matching
|
||||
// `PartialOrd` because it has an alias of ">".
|
||||
.filter(|alias| {
|
||||
let mut chars = alias.chars();
|
||||
chars.next().is_some_and(char::is_alphabetic)
|
||||
&& chars.all(|c| c.is_alphanumeric() || c == '_')
|
||||
})
|
||||
// Deliberately concatenated without separators as adding separators e.g.
|
||||
// `alias1, alias2` results in LSP clients continuing to display the completion even
|
||||
// after typing a comma or space.
|
||||
.join("");
|
||||
if !lookup_doc_aliases.is_empty() {
|
||||
lookup = SmolStr::from(format!("{lookup}{lookup_doc_aliases}"));
|
||||
}
|
||||
}
|
||||
if let [import_edit] = &*self.imports_to_add {
|
||||
// snippets can have multiple imports, but normal completions only have up to one
|
||||
|
|
|
@ -1280,3 +1280,26 @@ fn here_we_go() {
|
|||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completion_filtering_excludes_non_identifier_doc_aliases() {
|
||||
check_edit(
|
||||
"PartialOrdcmporder",
|
||||
r#"
|
||||
#[doc(alias = ">")]
|
||||
#[doc(alias = "cmp")]
|
||||
#[doc(alias = "order")]
|
||||
trait PartialOrd {}
|
||||
|
||||
struct Foo<T: Partial$0
|
||||
"#,
|
||||
r#"
|
||||
#[doc(alias = ">")]
|
||||
#[doc(alias = "cmp")]
|
||||
#[doc(alias = "order")]
|
||||
trait PartialOrd {}
|
||||
|
||||
struct Foo<T: PartialOrd
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue