cleanup + docs + tests

This commit is contained in:
Adenine 2023-07-07 23:03:55 -04:00
parent c43cfefdd8
commit 4d5c66986e
7 changed files with 320 additions and 60 deletions

View file

@ -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
}