internal: Remove synstructure const hack support

This commit is contained in:
Lukas Wirth 2024-03-08 11:36:37 +01:00
parent 09b9a921a8
commit 558feeab61
8 changed files with 48 additions and 68 deletions

View file

@ -176,14 +176,12 @@ impl NavigationTarget {
impl TryToNav for FileSymbol {
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
let root = db.parse_or_expand(self.loc.hir_file_id);
self.loc.ptr.to_node(&root);
Some(
orig_range_with_focus(
orig_range_with_focus_r(
db,
self.loc.hir_file_id,
&self.loc.ptr.to_node(&root),
Some(self.loc.name_ptr.to_node(&root)),
self.loc.ptr.text_range(),
Some(self.loc.name_ptr.text_range()),
)
.map(|(FileRange { file_id, range: full_range }, focus_range)| {
NavigationTarget {
@ -722,7 +720,21 @@ fn orig_range_with_focus(
value: &SyntaxNode,
name: Option<impl AstNode>,
) -> UpmappingResult<(FileRange, Option<TextRange>)> {
let Some(name) = name else { return orig_range(db, hir_file, value) };
orig_range_with_focus_r(
db,
hir_file,
value.text_range(),
name.map(|it| it.syntax().text_range()),
)
}
fn orig_range_with_focus_r(
db: &RootDatabase,
hir_file: HirFileId,
value: TextRange,
name: Option<TextRange>,
) -> UpmappingResult<(FileRange, Option<TextRange>)> {
let Some(name) = name else { return orig_range_r(db, hir_file, value) };
let call_kind =
|| db.lookup_intern_macro_call(hir_file.macro_file().unwrap().macro_call_id).kind;
@ -733,9 +745,9 @@ fn orig_range_with_focus(
.definition_range(db)
};
let value_range = InFile::new(hir_file, value).original_file_range_opt(db);
let value_range = InFile::new(hir_file, value).original_node_file_range_opt(db);
let ((call_site_range, call_site_focus), def_site) =
match InFile::new(hir_file, name.syntax()).original_file_range_opt(db) {
match InFile::new(hir_file, name).original_node_file_range_opt(db) {
// call site name
Some((focus_range, ctxt)) if ctxt.is_root() => {
// Try to upmap the node as well, if it ends up in the def site, go back to the call site
@ -802,7 +814,7 @@ fn orig_range_with_focus(
}
}
// lost name? can't happen for single tokens
None => return orig_range(db, hir_file, value),
None => return orig_range_r(db, hir_file, value),
};
UpmappingResult {
@ -845,6 +857,17 @@ fn orig_range(
}
}
fn orig_range_r(
db: &RootDatabase,
hir_file: HirFileId,
value: TextRange,
) -> UpmappingResult<(FileRange, Option<TextRange>)> {
UpmappingResult {
call_site: (InFile::new(hir_file, value).original_node_file_range(db).0, None),
def_site: None,
}
}
#[cfg(test)]
mod tests {
use expect_test::expect;