mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
completion uses hir scopes
This commit is contained in:
parent
4e4ca27eab
commit
49e746b010
5 changed files with 39 additions and 27 deletions
|
@ -27,7 +27,7 @@ impl Function {
|
|||
Function { fn_id }
|
||||
}
|
||||
|
||||
pub fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
|
||||
pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
|
||||
db.fn_scopes(self.fn_id)
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ pub struct ScopeData {
|
|||
}
|
||||
|
||||
impl FnScopes {
|
||||
pub fn new(fn_def: ast::FnDef) -> FnScopes {
|
||||
pub(crate) fn new(fn_def: ast::FnDef) -> FnScopes {
|
||||
let mut scopes = FnScopes {
|
||||
self_param: fn_def
|
||||
.param_list()
|
||||
|
|
|
@ -74,6 +74,16 @@ pub fn function_from_source(
|
|||
fn_def: ast::FnDef,
|
||||
) -> Cancelable<Option<Function>> {
|
||||
let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?);
|
||||
let res = function_from_module(db, &module, fn_def);
|
||||
Ok(Some(res))
|
||||
}
|
||||
|
||||
pub fn function_from_module(
|
||||
db: &impl HirDatabase,
|
||||
module: &Module,
|
||||
fn_def: ast::FnDef,
|
||||
) -> Function {
|
||||
let file_id = module.source().file_id();
|
||||
let file_items = db.file_items(file_id);
|
||||
let item_id = file_items.id_of(file_id, fn_def.syntax());
|
||||
let source_item_id = SourceItemId {
|
||||
|
@ -86,7 +96,7 @@ pub fn function_from_source(
|
|||
module_id: module.module_id,
|
||||
source_item_id,
|
||||
};
|
||||
Ok(Some(Function::new(def_loc.id(db))))
|
||||
Function::new(def_loc.id(db))
|
||||
}
|
||||
|
||||
pub fn function_from_child_node(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue