mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
use names everywhere
This commit is contained in:
parent
63f54d234f
commit
e066050671
3 changed files with 51 additions and 30 deletions
|
@ -8,14 +8,14 @@
|
|||
use ra_db::{FileId, FilePosition, Cancelable};
|
||||
use ra_editor::find_node_at_offset;
|
||||
use ra_syntax::{
|
||||
ast::{self, AstNode},
|
||||
ast::{self, AstNode, NameOwner},
|
||||
SyntaxNodeRef,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
HirDatabase, Module, Function, SourceItemId,
|
||||
module::ModuleSource,
|
||||
DefKind, DefLoc
|
||||
DefKind, DefLoc, AsName,
|
||||
};
|
||||
|
||||
/// Locates the module by `FileId`. Picks topmost module in the file.
|
||||
|
@ -24,6 +24,25 @@ pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Cancelable
|
|||
module_from_source(db, module_source)
|
||||
}
|
||||
|
||||
/// Locates the child module by `mod child;` declaration.
|
||||
pub fn module_from_declaration(
|
||||
db: &impl HirDatabase,
|
||||
file_id: FileId,
|
||||
decl: ast::Module,
|
||||
) -> Cancelable<Option<Module>> {
|
||||
let parent_module = module_from_file_id(db, file_id)?;
|
||||
let child_name = decl.name();
|
||||
match (parent_module, child_name) {
|
||||
(Some(parent_module), Some(child_name)) => {
|
||||
if let Some(child) = parent_module.child(&child_name.as_name()) {
|
||||
return Ok(Some(child));
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
/// Locates the module by position in the source code.
|
||||
pub fn module_from_position(
|
||||
db: &impl HirDatabase,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue