Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions crates/hir/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use hir_ty::{
};
use intern::Symbol;
use rustc_hash::FxHashMap;
use syntax::{AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, ToSmolStr, ast::HasName};
use syntax::{AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, ToSmolStr, ast::HasName};

use crate::{HasCrate, Module, ModuleDef, Semantics};

Expand All @@ -29,7 +29,7 @@ pub struct FileSymbol {
pub name: Symbol,
pub def: ModuleDef,
pub loc: DeclarationLocation,
pub container_name: Option<SmolStr>,
pub container_name: Option<Symbol>,
/// Whether this symbol is a doc alias for the original symbol.
pub is_alias: bool,
pub is_assoc: bool,
Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct SymbolCollector<'a> {
db: &'a dyn HirDatabase,
symbols: FxIndexSet<FileSymbol>,
work: Vec<SymbolCollectorWork>,
current_container_name: Option<SmolStr>,
current_container_name: Option<Symbol>,
}

/// Given a [`ModuleId`] and a [`HirDatabase`], use the DefMap for the module's crate to collect
Expand Down Expand Up @@ -108,7 +108,7 @@ impl<'a> SymbolCollector<'a> {
tracing::info!(?work, "SymbolCollector::do_work");
self.db.unwind_if_revision_cancelled();

let parent_name = work.parent.map(|name| name.as_str().to_smolstr());
let parent_name = work.parent.map(|name| Symbol::intern(name.as_str()));
self.with_container_name(parent_name, |s| s.collect_from_module(work.module_id));
}

Expand All @@ -125,7 +125,7 @@ impl<'a> SymbolCollector<'a> {
}
ModuleDefId::AdtId(AdtId::EnumId(id)) => {
this.push_decl(id, name, false, None);
let enum_name = this.db.enum_signature(id).name.as_str().to_smolstr();
let enum_name = Symbol::intern(this.db.enum_signature(id).name.as_str());
this.with_container_name(Some(enum_name), |this| {
let variants = id.enum_variants(this.db);
for (variant_id, variant_name, _) in &variants.variants {
Expand Down Expand Up @@ -328,7 +328,7 @@ impl<'a> SymbolCollector<'a> {
)
.to_smolstr(),
);
self.with_container_name(impl_name, |s| {
self.with_container_name(impl_name.as_deref().map(Symbol::intern), |s| {
for &(ref name, assoc_item_id) in &impl_id.impl_items(self.db).items {
s.push_assoc_item(assoc_item_id, name, None)
}
Expand All @@ -337,14 +337,14 @@ impl<'a> SymbolCollector<'a> {

fn collect_from_trait(&mut self, trait_id: TraitId, trait_do_not_complete: Complete) {
let trait_data = self.db.trait_signature(trait_id);
self.with_container_name(Some(trait_data.name.as_str().into()), |s| {
self.with_container_name(Some(Symbol::intern(trait_data.name.as_str())), |s| {
for &(ref name, assoc_item_id) in &trait_id.trait_items(self.db).items {
s.push_assoc_item(assoc_item_id, name, Some(trait_do_not_complete));
}
});
}

fn with_container_name(&mut self, container_name: Option<SmolStr>, f: impl FnOnce(&mut Self)) {
fn with_container_name(&mut self, container_name: Option<Symbol>, f: impl FnOnce(&mut Self)) {
if let Some(container_name) = container_name {
let prev = self.current_container_name.replace(container_name);
f(self);
Expand Down
3 changes: 2 additions & 1 deletion crates/ide-db/src/ra_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::hash::{BuildHasher, Hash};

use hir::{CfgExpr, FilePositionWrapper, FileRangeWrapper, Semantics};
use hir::{CfgExpr, FilePositionWrapper, FileRangeWrapper, Semantics, Symbol};
use smallvec::SmallVec;
use span::{TextRange, TextSize};
use syntax::{
Expand Down Expand Up @@ -524,6 +524,7 @@ impl_empty_upmap_from_ra_fixture!(
f64,
&str,
String,
Symbol,
SmolStr,
Documentation,
SymbolKind,
Expand Down
13 changes: 9 additions & 4 deletions crates/ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ fn try_lookup_include_path(
Some(NavigationTarget {
file_id,
full_range: TextRange::new(0.into(), size),
name: path.into(),
name: hir::Symbol::intern(&path),
alias: None,
focus_range: None,
kind: None,
Expand Down Expand Up @@ -598,7 +598,13 @@ fn expr_to_nav(
let value_range = value.syntax().text_range();
let navs = navigation_target::orig_range_with_focus_r(db, file_id, value_range, focus_range);
navs.map(|(hir::FileRangeWrapper { file_id, range }, focus_range)| {
NavigationTarget::from_syntax(file_id, "<expr>".into(), focus_range, range, kind)
NavigationTarget::from_syntax(
file_id,
hir::Symbol::intern("<expr>"),
focus_range,
range,
kind,
)
})
}

Expand All @@ -607,7 +613,6 @@ mod tests {
use crate::{GotoDefinitionConfig, fixture};
use ide_db::{FileRange, MiniCore};
use itertools::Itertools;
use syntax::SmolStr;

const TEST_CONFIG: GotoDefinitionConfig<'_> =
GotoDefinitionConfig { minicore: MiniCore::default() };
Expand Down Expand Up @@ -658,7 +663,7 @@ mod tests {
let Some(target) = navs.into_iter().next() else {
panic!("expected single navigation target but encountered none");
};
assert_eq!(target.name, SmolStr::new_inline(expected_name));
assert_eq!(target.name, hir::Symbol::intern(expected_name));
}

#[test]
Expand Down
Loading