Lifetime reference search

This commit is contained in:
Lukas Wirth 2020-12-16 21:35:15 +01:00
parent 067067a6c1
commit 55faa2daa3
12 changed files with 373 additions and 41 deletions

View file

@ -9,7 +9,7 @@ use ide_db::{defs::Definition, RootDatabase};
use syntax::{
ast::{self, NameOwner},
match_ast, AstNode, SmolStr,
SyntaxKind::{self, IDENT_PAT, TYPE_PARAM},
SyntaxKind::{self, IDENT_PAT, LIFETIME_PARAM, TYPE_PARAM},
TextRange,
};
@ -182,6 +182,7 @@ impl TryToNav for Definition {
Definition::SelfType(it) => Some(it.to_nav(db)),
Definition::Local(it) => Some(it.to_nav(db)),
Definition::TypeParam(it) => Some(it.to_nav(db)),
Definition::LifetimeParam(it) => Some(it.to_nav(db)),
}
}
}
@ -376,6 +377,23 @@ impl ToNav for hir::TypeParam {
}
}
impl ToNav for hir::LifetimeParam {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
let src = self.source(db);
let full_range = src.value.syntax().text_range();
NavigationTarget {
file_id: src.file_id.original_file(db),
name: self.name(db).to_string().into(),
kind: LIFETIME_PARAM,
full_range,
focus_range: Some(full_range),
container_name: None,
description: None,
docs: None,
}
}
}
pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<Documentation> {
let parse = db.parse(symbol.file_id);
let node = symbol.ptr.to_node(parse.tree().syntax());