Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4d5c669

Browse files
committed
cleanup + docs + tests
1 parent c43cfef commit 4d5c669

File tree

7 files changed

+318
-58
lines changed

7 files changed

+318
-58
lines changed

crates/ide-db/src/helpers.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use syntax::{
99
AstToken, SyntaxKind, SyntaxToken, TokenAtOffset,
1010
};
1111

12-
use crate::{defs::Definition, generated, RootDatabase};
12+
use crate::{
13+
defs::{Definition, IdentClass},
14+
generated, RootDatabase,
15+
};
1316

1417
pub fn item_name(db: &RootDatabase, item: ItemInNs) -> Option<Name> {
1518
match item {
@@ -109,3 +112,16 @@ pub fn is_editable_crate(krate: Crate, db: &RootDatabase) -> bool {
109112
let source_root_id = db.file_source_root(root_file);
110113
!db.source_root(source_root_id).is_library
111114
}
115+
116+
pub fn get_definition(
117+
sema: &Semantics<'_, RootDatabase>,
118+
token: SyntaxToken,
119+
) -> Option<Definition> {
120+
for token in sema.descend_into_macros(token) {
121+
let def = IdentClass::classify_token(sema, &token).map(IdentClass::definitions_no_ops);
122+
if let Some(&[x]) = def.as_deref() {
123+
return Some(x);
124+
}
125+
}
126+
None
127+
}

crates/ide/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,10 @@ impl Analysis {
726726
self.with_db(|db| move_item::move_item(db, range, direction))
727727
}
728728

729-
pub fn get_recursive_memory_layout(&self, position: FilePosition) -> Cancellable<Option<RecursiveMemoryLayout>> {
729+
pub fn get_recursive_memory_layout(
730+
&self,
731+
position: FilePosition,
732+
) -> Cancellable<Option<RecursiveMemoryLayout>> {
730733
self.with_db(|db| view_memory_layout(db, position))
731734
}
732735

crates/ide/src/static_index.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
44
use std::collections::HashMap;
55

6-
use hir::{db::HirDatabase, Crate, Module, Semantics};
6+
use hir::{db::HirDatabase, Crate, Module};
7+
use ide_db::helpers::get_definition;
78
use ide_db::{
89
base_db::{FileId, FileRange, SourceDatabaseExt},
9-
defs::{Definition, IdentClass},
10+
defs::Definition,
1011
FxHashSet, RootDatabase,
1112
};
12-
use syntax::{AstNode, SyntaxKind::*, SyntaxToken, TextRange, T};
13+
use syntax::{AstNode, SyntaxKind::*, TextRange, T};
1314

1415
use crate::{
1516
hover::hover_for_definition,
@@ -214,16 +215,6 @@ impl StaticIndex<'_> {
214215
}
215216
}
216217

217-
fn get_definition(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) -> Option<Definition> {
218-
for token in sema.descend_into_macros(token) {
219-
let def = IdentClass::classify_token(sema, &token).map(IdentClass::definitions_no_ops);
220-
if let Some(&[it]) = def.as_deref() {
221-
return Some(it);
222-
}
223-
}
224-
None
225-
}
226-
227218
#[cfg(test)]
228219
mod tests {
229220
use crate::{fixture, StaticIndex};

0 commit comments

Comments
 (0)