mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
cleanup + docs + tests
This commit is contained in:
parent
c43cfefdd8
commit
4d5c66986e
7 changed files with 320 additions and 60 deletions
|
@ -9,7 +9,10 @@ use syntax::{
|
|||
AstToken, SyntaxKind, SyntaxToken, TokenAtOffset,
|
||||
};
|
||||
|
||||
use crate::{defs::Definition, generated, RootDatabase};
|
||||
use crate::{
|
||||
defs::{Definition, IdentClass},
|
||||
generated, RootDatabase,
|
||||
};
|
||||
|
||||
pub fn item_name(db: &RootDatabase, item: ItemInNs) -> Option<Name> {
|
||||
match item {
|
||||
|
@ -109,3 +112,16 @@ pub fn is_editable_crate(krate: Crate, db: &RootDatabase) -> bool {
|
|||
let source_root_id = db.file_source_root(root_file);
|
||||
!db.source_root(source_root_id).is_library
|
||||
}
|
||||
|
||||
pub fn get_definition(
|
||||
sema: &Semantics<'_, RootDatabase>,
|
||||
token: SyntaxToken,
|
||||
) -> Option<Definition> {
|
||||
for token in sema.descend_into_macros(token) {
|
||||
let def = IdentClass::classify_token(sema, &token).map(IdentClass::definitions_no_ops);
|
||||
if let Some(&[x]) = def.as_deref() {
|
||||
return Some(x);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue