};
use ide_db::{defs::Definition, RootDatabase};
use syntax::{
- ast::{self, NameOwner},
+ ast::{self, HasName},
match_ast, AstNode, SmolStr, TextRange,
};
}
pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
- let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
+ let name = module.name(db).map(|it| it.to_smol_str()).unwrap_or_default();
if let Some(src) = module.declaration_source(db) {
let node = src.syntax();
let full_range = node.original_file_range(db);
module.to_nav(db)
}
- #[cfg(test)]
- pub(crate) fn assert_match(&self, expected: &str) {
- let actual = self.debug_render();
- test_utils::assert_eq_text!(expected.trim(), actual.trim(),);
- }
-
#[cfg(test)]
pub(crate) fn debug_render(&self) -> String {
let mut buf = format!(
/// Allows `NavigationTarget` to be created from a `NameOwner`
pub(crate) fn from_named(
db: &RootDatabase,
- node: InFile<&dyn ast::NameOwner>,
+ node: InFile<&dyn ast::HasName>,
kind: SymbolKind,
) -> NavigationTarget {
let name = node.value.name().map(|it| it.text().into()).unwrap_or_else(|| "_".into());
impl<D> TryToNav for D
where
D: HasSource + ToNavFromAst + Copy + HasAttrs + HirDisplay,
- D::Ast: ast::NameOwner,
+ D::Ast: ast::HasName,
{
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
let src = self.source(db)?;
let mut res = NavigationTarget::from_named(
db,
- src.as_ref().map(|it| it as &dyn ast::NameOwner),
+ src.as_ref().map(|it| it as &dyn ast::HasName),
D::KIND,
);
res.docs = self.docs(db);
impl ToNav for hir::Module {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
let src = self.definition_source(db);
- let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default();
+ let name = self.name(db).map(|it| it.to_smol_str()).unwrap_or_default();
let (syntax, focus) = match &src.value {
ModuleSource::SourceFile(node) => (node.syntax(), None),
ModuleSource::Module(node) => {
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
let src = self.source(db)?;
let derive_attr = self.is_builtin_derive(db);
- let frange = if let Some(item) = &derive_attr {
- item.syntax().original_file_range(db)
- } else {
- src.syntax().original_file_range(db)
+ let frange = match &derive_attr {
+ Some(item) => item.syntax().original_file_range(db),
+ None => src.syntax().original_file_range(db),
};
let focus_range = if derive_attr.is_some() {
None
impl TryToNav for hir::MacroDef {
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
let src = self.source(db)?;
- let name_owner: &dyn ast::NameOwner = match &src.value {
+ let name_owner: &dyn ast::HasName = match &src.value {
Either::Left(it) => it,
Either::Right(it) => it,
};
- log::debug!("nav target {:#?}", name_owner.syntax());
+ tracing::debug!("nav target {:#?}", name_owner.syntax());
let mut res = NavigationTarget::from_named(
db,
src.as_ref().with_value(name_owner),
let full_range = src.with_value(&node).original_file_range(db);
let name = match self.name(db) {
- Some(it) => it.to_string().into(),
+ Some(it) => it.to_smol_str(),
None => "".into(),
};
let kind = if self.is_self(db) {
let FileRange { file_id, range } = src.with_value(node).original_file_range(db);
let focus_range =
src.value.lifetime().and_then(|lt| lt.lifetime_ident_token()).map(|lt| lt.text_range());
- let name = self.name(db).to_string().into();
+ let name = self.name(db).to_smol_str();
NavigationTarget {
file_id,
name,
.map(|it| it.syntax().text_range());
Some(NavigationTarget {
file_id: src.file_id.original_file(db),
- name: self.name(db).to_string().into(),
+ name: self.name(db).to_smol_str(),
kind: Some(SymbolKind::TypeParam),
full_range,
focus_range,
let full_range = src.value.syntax().text_range();
Some(NavigationTarget {
file_id: src.file_id.original_file(db),
- name: self.name(db).to_string().into(),
+ name: self.name(db).to_smol_str(),
kind: Some(SymbolKind::LifetimeParam),
full_range,
focus_range: Some(full_range),
let full_range = src.value.syntax().text_range();
Some(NavigationTarget {
file_id: src.file_id.original_file(db),
- name: self.name(db).to_string().into(),
+ name: self.name(db).to_smol_str(),
kind: Some(SymbolKind::ConstParam),
full_range,
focus_range: src.value.name().map(|n| n.syntax().text_range()),