Skip to content

Commit c469936

Browse files
Address review comments part 1
1 parent ba2b48d commit c469936

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

crates/hir-def/src/attr.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! A higher level attributes based on TokenTree, with also some shortcuts.
22
3+
#[cfg(test)]
4+
mod tests;
5+
36
use std::{hash::Hash, ops, sync::Arc};
47

58
use base_db::CrateId;
@@ -238,12 +241,12 @@ impl Attrs {
238241
})
239242
}
240243

241-
pub fn doc_exprs(&self) -> Vec<DocExpr> {
242-
self.by_key("doc").tt_values().map(DocExpr::parse).collect()
244+
pub fn doc_exprs(&self) -> impl Iterator<Item = DocExpr> + '_ {
245+
self.by_key("doc").tt_values().map(DocExpr::parse)
243246
}
244247

245-
pub fn doc_aliases(&self) -> Vec<SmolStr> {
246-
self.doc_exprs().into_iter().flat_map(|doc_expr| doc_expr.aliases()).collect()
248+
pub fn doc_aliases(&self) -> impl Iterator<Item = SmolStr> + '_ {
249+
self.doc_exprs().flat_map(|doc_expr| doc_expr.aliases().to_vec())
247250
}
248251

249252
pub fn is_proc_macro(&self) -> bool {
@@ -288,17 +291,17 @@ impl From<DocAtom> for DocExpr {
288291
}
289292

290293
impl DocExpr {
291-
pub fn parse<S>(tt: &tt::Subtree<S>) -> DocExpr {
294+
fn parse<S>(tt: &tt::Subtree<S>) -> DocExpr {
292295
next_doc_expr(&mut tt.token_trees.iter()).unwrap_or(DocExpr::Invalid)
293296
}
294297

295-
pub fn aliases(self) -> Vec<SmolStr> {
298+
pub fn aliases(&self) -> &[SmolStr] {
296299
match self {
297300
DocExpr::Atom(DocAtom::KeyValue { key, value }) if key == "alias" => {
298-
vec![value]
301+
std::slice::from_ref(value)
299302
}
300303
DocExpr::Alias(aliases) => aliases,
301-
_ => vec![],
304+
_ => &[],
302305
}
303306
}
304307
}
File renamed without changes.

crates/hir-def/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ pub mod import_map;
5353
mod test_db;
5454
#[cfg(test)]
5555
mod macro_expansion_tests;
56-
#[cfg(test)]
57-
mod attr_tests;
5856
mod pretty;
5957

6058
use std::{

crates/ide-completion/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl<'a> CompletionContext<'a> {
549549

550550
fn doc_aliases(&self, scope_def: ScopeDef) -> Vec<SmolStr> {
551551
if let Some(attrs) = scope_def.attrs(self.db) {
552-
attrs.doc_aliases()
552+
attrs.doc_aliases().collect()
553553
} else {
554554
vec![]
555555
}

crates/ide-completion/src/item.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct CompletionItem {
4545
///
4646
/// That is, in `foo.bar$0` lookup of `abracadabra` will be accepted (it
4747
/// contains `bar` sub sequence), and `quux` will rejected.
48-
pub lookup: Option<SmolStr>,
48+
pub lookup: SmolStr,
4949

5050
/// Additional info to show in the UI pop up.
5151
pub detail: Option<String>,
@@ -359,7 +359,7 @@ impl CompletionItem {
359359

360360
/// What string is used for filtering.
361361
pub fn lookup(&self) -> &str {
362-
self.lookup.as_deref().unwrap_or(&self.label)
362+
self.lookup.as_str()
363363
}
364364

365365
pub fn ref_match(&self) -> Option<(String, text_edit::Indel, CompletionRelevance)> {
@@ -415,19 +415,20 @@ impl Builder {
415415
let _p = profile::span("item::Builder::build");
416416

417417
let mut label = self.label;
418-
let mut lookup = self.lookup;
418+
let mut lookup = self.lookup.unwrap_or_else(|| label.clone());
419419
let insert_text = self.insert_text.unwrap_or_else(|| label.to_string());
420420

421+
if let Some(doc_aliases) = self.doc_aliases {
422+
label = SmolStr::from(format!("{label} (alias {doc_aliases})"));
423+
lookup = SmolStr::from(format!("{lookup} {doc_aliases}"));
424+
}
421425
if let [import_edit] = &*self.imports_to_add {
422426
// snippets can have multiple imports, but normal completions only have up to one
423427
if let Some(original_path) = import_edit.original_path.as_ref() {
424-
lookup = lookup.or_else(|| Some(label.clone()));
425428
label = SmolStr::from(format!("{label} (use {original_path})"));
426429
}
427430
} else if let Some(trait_name) = self.trait_name {
428431
label = SmolStr::from(format!("{label} (as {trait_name})"));
429-
} else if let Some(doc_aliases) = self.doc_aliases {
430-
label = SmolStr::from(format!("{label} (alias {doc_aliases})"));
431432
}
432433

433434
let text_edit = match self.text_edit {

0 commit comments

Comments
 (0)