mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Address review comments part 1
This commit is contained in:
parent
ba2b48d1b8
commit
c469936aac
5 changed files with 19 additions and 17 deletions
|
@ -1,5 +1,8 @@
|
|||
//! A higher level attributes based on TokenTree, with also some shortcuts.
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::{hash::Hash, ops, sync::Arc};
|
||||
|
||||
use base_db::CrateId;
|
||||
|
@ -238,12 +241,12 @@ impl Attrs {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn doc_exprs(&self) -> Vec<DocExpr> {
|
||||
self.by_key("doc").tt_values().map(DocExpr::parse).collect()
|
||||
pub fn doc_exprs(&self) -> impl Iterator<Item = DocExpr> + '_ {
|
||||
self.by_key("doc").tt_values().map(DocExpr::parse)
|
||||
}
|
||||
|
||||
pub fn doc_aliases(&self) -> Vec<SmolStr> {
|
||||
self.doc_exprs().into_iter().flat_map(|doc_expr| doc_expr.aliases()).collect()
|
||||
pub fn doc_aliases(&self) -> impl Iterator<Item = SmolStr> + '_ {
|
||||
self.doc_exprs().flat_map(|doc_expr| doc_expr.aliases().to_vec())
|
||||
}
|
||||
|
||||
pub fn is_proc_macro(&self) -> bool {
|
||||
|
@ -288,17 +291,17 @@ impl From<DocAtom> for DocExpr {
|
|||
}
|
||||
|
||||
impl DocExpr {
|
||||
pub fn parse<S>(tt: &tt::Subtree<S>) -> DocExpr {
|
||||
fn parse<S>(tt: &tt::Subtree<S>) -> DocExpr {
|
||||
next_doc_expr(&mut tt.token_trees.iter()).unwrap_or(DocExpr::Invalid)
|
||||
}
|
||||
|
||||
pub fn aliases(self) -> Vec<SmolStr> {
|
||||
pub fn aliases(&self) -> &[SmolStr] {
|
||||
match self {
|
||||
DocExpr::Atom(DocAtom::KeyValue { key, value }) if key == "alias" => {
|
||||
vec![value]
|
||||
std::slice::from_ref(value)
|
||||
}
|
||||
DocExpr::Alias(aliases) => aliases,
|
||||
_ => vec![],
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,8 +53,6 @@ pub mod import_map;
|
|||
mod test_db;
|
||||
#[cfg(test)]
|
||||
mod macro_expansion_tests;
|
||||
#[cfg(test)]
|
||||
mod attr_tests;
|
||||
mod pretty;
|
||||
|
||||
use std::{
|
||||
|
|
|
@ -549,7 +549,7 @@ impl<'a> CompletionContext<'a> {
|
|||
|
||||
fn doc_aliases(&self, scope_def: ScopeDef) -> Vec<SmolStr> {
|
||||
if let Some(attrs) = scope_def.attrs(self.db) {
|
||||
attrs.doc_aliases()
|
||||
attrs.doc_aliases().collect()
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ pub struct CompletionItem {
|
|||
///
|
||||
/// That is, in `foo.bar$0` lookup of `abracadabra` will be accepted (it
|
||||
/// contains `bar` sub sequence), and `quux` will rejected.
|
||||
pub lookup: Option<SmolStr>,
|
||||
pub lookup: SmolStr,
|
||||
|
||||
/// Additional info to show in the UI pop up.
|
||||
pub detail: Option<String>,
|
||||
|
@ -359,7 +359,7 @@ impl CompletionItem {
|
|||
|
||||
/// What string is used for filtering.
|
||||
pub fn lookup(&self) -> &str {
|
||||
self.lookup.as_deref().unwrap_or(&self.label)
|
||||
self.lookup.as_str()
|
||||
}
|
||||
|
||||
pub fn ref_match(&self) -> Option<(String, text_edit::Indel, CompletionRelevance)> {
|
||||
|
@ -415,19 +415,20 @@ impl Builder {
|
|||
let _p = profile::span("item::Builder::build");
|
||||
|
||||
let mut label = self.label;
|
||||
let mut lookup = self.lookup;
|
||||
let mut lookup = self.lookup.unwrap_or_else(|| label.clone());
|
||||
let insert_text = self.insert_text.unwrap_or_else(|| label.to_string());
|
||||
|
||||
if let Some(doc_aliases) = self.doc_aliases {
|
||||
label = SmolStr::from(format!("{label} (alias {doc_aliases})"));
|
||||
lookup = SmolStr::from(format!("{lookup} {doc_aliases}"));
|
||||
}
|
||||
if let [import_edit] = &*self.imports_to_add {
|
||||
// snippets can have multiple imports, but normal completions only have up to one
|
||||
if let Some(original_path) = import_edit.original_path.as_ref() {
|
||||
lookup = lookup.or_else(|| Some(label.clone()));
|
||||
label = SmolStr::from(format!("{label} (use {original_path})"));
|
||||
}
|
||||
} else if let Some(trait_name) = self.trait_name {
|
||||
label = SmolStr::from(format!("{label} (as {trait_name})"));
|
||||
} else if let Some(doc_aliases) = self.doc_aliases {
|
||||
label = SmolStr::from(format!("{label} (alias {doc_aliases})"));
|
||||
}
|
||||
|
||||
let text_edit = match self.text_edit {
|
||||
|
|
Loading…
Reference in a new issue