Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/symbols.rs')
-rw-r--r--crates/hir/src/symbols.rs46
1 files changed, 17 insertions, 29 deletions
diff --git a/crates/hir/src/symbols.rs b/crates/hir/src/symbols.rs
index 02905ca2ce..b1f5df681f 100644
--- a/crates/hir/src/symbols.rs
+++ b/crates/hir/src/symbols.rs
@@ -1,6 +1,5 @@
//! File symbol extraction.
-use base_db::FileRange;
use hir_def::{
db::DefDatabase,
item_scope::ItemInNs,
@@ -8,9 +7,9 @@ use hir_def::{
AdtId, AssocItemId, DefWithBodyId, HasModule, ImplId, Lookup, MacroId, ModuleDefId, ModuleId,
TraitId,
};
-use hir_expand::{HirFileId, InFile};
+use hir_expand::HirFileId;
use hir_ty::{db::HirDatabase, display::HirDisplay};
-use syntax::{ast::HasName, AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr};
+use syntax::{ast::HasName, AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, ToSmolStr};
use crate::{Module, ModuleDef, Semantics};
@@ -42,25 +41,6 @@ impl DeclarationLocation {
let root = sema.parse_or_expand(self.hir_file_id);
self.ptr.to_node(&root)
}
-
- pub fn original_range(&self, db: &dyn HirDatabase) -> FileRange {
- if let Some(file_id) = self.hir_file_id.file_id() {
- // fast path to prevent parsing
- return FileRange { file_id, range: self.ptr.text_range() };
- }
- let node = resolve_node(db, self.hir_file_id, &self.ptr);
- node.as_ref().original_file_range_rooted(db.upcast())
- }
-}
-
-fn resolve_node(
- db: &dyn HirDatabase,
- file_id: HirFileId,
- ptr: &SyntaxNodePtr,
-) -> InFile<SyntaxNode> {
- let root = db.parse_or_expand(file_id);
- let node = ptr.to_node(&root);
- InFile::new(file_id, node)
}
/// Represents an outstanding module that the symbol collector must collect symbols from.
@@ -239,7 +219,7 @@ impl<'a> SymbolCollector<'a> {
fn collect_from_trait(&mut self, trait_id: TraitId) {
let trait_data = self.db.trait_data(trait_id);
- self.with_container_name(trait_data.name.as_text(), |s| {
+ self.with_container_name(Some(trait_data.name.as_str().into()), |s| {
for &(_, assoc_item_id) in &trait_data.items {
s.push_assoc_item(assoc_item_id);
}
@@ -258,10 +238,18 @@ impl<'a> SymbolCollector<'a> {
fn def_with_body_id_name(&self, body_id: DefWithBodyId) -> Option<SmolStr> {
match body_id {
- DefWithBodyId::FunctionId(id) => Some(self.db.function_data(id).name.to_smol_str()),
- DefWithBodyId::StaticId(id) => Some(self.db.static_data(id).name.to_smol_str()),
- DefWithBodyId::ConstId(id) => Some(self.db.const_data(id).name.as_ref()?.to_smol_str()),
- DefWithBodyId::VariantId(id) => Some(self.db.enum_variant_data(id).name.to_smol_str()),
+ DefWithBodyId::FunctionId(id) => {
+ Some(self.db.function_data(id).name.display_no_db().to_smolstr())
+ }
+ DefWithBodyId::StaticId(id) => {
+ Some(self.db.static_data(id).name.display_no_db().to_smolstr())
+ }
+ DefWithBodyId::ConstId(id) => {
+ Some(self.db.const_data(id).name.as_ref()?.display_no_db().to_smolstr())
+ }
+ DefWithBodyId::VariantId(id) => {
+ Some(self.db.enum_variant_data(id).name.display_no_db().to_smolstr())
+ }
DefWithBodyId::InTypeConstId(_) => Some("in type const".into()),
}
}
@@ -293,7 +281,7 @@ impl<'a> SymbolCollector<'a> {
if let Some(attrs) = def.attrs(self.db) {
for alias in attrs.doc_aliases() {
self.symbols.push(FileSymbol {
- name: alias,
+ name: alias.as_str().into(),
def,
loc: dec_loc.clone(),
container_name: self.current_container_name.clone(),
@@ -330,7 +318,7 @@ impl<'a> SymbolCollector<'a> {
if let Some(attrs) = def.attrs(self.db) {
for alias in attrs.doc_aliases() {
self.symbols.push(FileSymbol {
- name: alias,
+ name: alias.as_str().into(),
def,
loc: dec_loc.clone(),
container_name: self.current_container_name.clone(),