make navigation target go to original file location

This commit is contained in:
Jake Heinz 2021-11-27 13:48:50 +00:00
parent a7370c5725
commit e033d8c2a2
3 changed files with 27 additions and 21 deletions

View file

@ -170,7 +170,7 @@ impl NavigationTarget {
impl ToNav for FileSymbol {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
NavigationTarget {
file_id: self.file_id.original_file(db),
file_id: self.original_file_id,
name: self.name.clone(),
kind: Some(match self.kind {
FileSymbolKind::Function => SymbolKind::Function,
@ -517,7 +517,7 @@ impl TryToNav for hir::ConstParam {
/// e.g. `struct Name`, `enum Name`, `fn Name`
pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> {
let sema = Semantics::new(db);
let syntax = sema.parse_or_expand(symbol.file_id)?;
let syntax = sema.parse_or_expand(symbol.hir_file_id)?;
let node = symbol.ptr.to_node(&syntax);
match_ast! {

View file

@ -133,7 +133,7 @@ fn get_name_definition(
import_candidate: &FileSymbol,
) -> Option<Definition> {
let _p = profile::span("get_name_definition");
let file_id = import_candidate.file_id;
let file_id = import_candidate.hir_file_id;
let candidate_node = import_candidate.ptr.to_node(&sema.parse_or_expand(file_id)?);
let candidate_name_node = if candidate_node.kind() != NAME {

View file

@ -371,7 +371,8 @@ impl Query {
/// possible.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct FileSymbol {
pub file_id: HirFileId,
pub hir_file_id: HirFileId,
pub original_file_id: FileId,
pub name: SmolStr,
pub kind: FileSymbolKind,
pub range: TextRange,
@ -478,7 +479,8 @@ fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> {
},
range: node.text_range(),
ptr,
file_id: file_id.into(),
hir_file_id: file_id.into(),
original_file_id: file_id,
name_range: Some(name_range),
container_name: None,
})
@ -505,10 +507,11 @@ fn collect_symbols_from_item_scope(
{
let loc = id.lookup(db);
let source = loc.source(db);
let name = source.value.name()?;
let file_id = loc.id.file_id();
let name_range = name.syntax().text_range();
let name = source.value.name()?;
let name_range = source.with_value(name.syntax()).original_file_range(db.upcast());
let hir_file_id = loc.id.file_id();
let name = name.text().into();
let ptr = SyntaxNodePtr::new(source.value.syntax());
@ -532,10 +535,11 @@ fn collect_symbols_from_item_scope(
Some(FileSymbol {
name,
kind,
range: source.value.syntax().text_range(),
range: source.with_value(source.value.syntax()).original_file_range(db.upcast()).range,
container_name,
file_id,
name_range: Some(name_range),
hir_file_id,
original_file_id: name_range.file_id,
name_range: Some(name_range.range),
ptr,
})
}
@ -548,18 +552,19 @@ fn collect_symbols_from_item_scope(
let loc = id.lookup(db);
let source = loc.source(db);
let name = source.value.name()?;
let file_id = loc.id.file_id();
let name_range = name.syntax().text_range();
let name_range = source.with_value(name.syntax()).original_file_range(db.upcast());
let hir_file_id = loc.id.file_id();
let name = name.text().into();
let ptr = SyntaxNodePtr::new(source.value.syntax());
Some(FileSymbol {
name,
kind,
range: source.value.syntax().text_range(),
range: source.with_value(source.value.syntax()).original_file_range(db.upcast()).range,
container_name: None,
file_id,
name_range: Some(name_range),
hir_file_id,
original_file_id: name_range.file_id,
name_range: Some(name_range.range),
ptr,
})
}
@ -568,21 +573,22 @@ fn collect_symbols_from_item_scope(
let def_map = module_id.def_map(db);
let module_data = &def_map[module_id.local_id];
let declaration = module_data.origin.declaration()?;
let file_id = declaration.file_id;
let hir_file_id = declaration.file_id;
let module = declaration.to_node(db.upcast());
let name = module.name()?;
let name_range = name.syntax().text_range();
let name_range = declaration.with_value(name.syntax()).original_file_range(db.upcast());
let name = name.text().into();
let ptr = SyntaxNodePtr::new(module.syntax());
Some(FileSymbol {
name,
kind: FileSymbolKind::Module,
range: module.syntax().text_range(),
range: declaration.with_value(module.syntax()).original_file_range(db.upcast()).range,
container_name: None,
file_id,
name_range: Some(name_range),
hir_file_id,
original_file_id: name_range.file_id,
name_range: Some(name_range.range),
ptr,
})
}