mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
remove Cancelable from source binders
This commit is contained in:
parent
a36b2cf377
commit
11f3c8afb2
16 changed files with 68 additions and 90 deletions
|
@ -109,7 +109,7 @@ impl Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds a child module with the specified name.
|
/// Finds a child module with the specified name.
|
||||||
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> {
|
||||||
self.child_impl(db, name)
|
self.child_impl(db, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl Module {
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
source_root_id: SourceRootId,
|
source_root_id: SourceRootId,
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
) -> Cancelable<Self> {
|
) -> Self {
|
||||||
let module_tree = db.module_tree(source_root_id);
|
let module_tree = db.module_tree(source_root_id);
|
||||||
let def_loc = DefLoc {
|
let def_loc = DefLoc {
|
||||||
kind: DefKind::Module,
|
kind: DefKind::Module,
|
||||||
|
@ -27,8 +27,7 @@ impl Module {
|
||||||
source_item_id: module_id.source(&module_tree),
|
source_item_id: module_id.source(&module_tree),
|
||||||
};
|
};
|
||||||
let def_id = def_loc.id(db);
|
let def_id = def_loc.id(db);
|
||||||
let module = Module::new(def_id);
|
Module::new(def_id)
|
||||||
Ok(module)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
|
pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
|
||||||
|
@ -84,15 +83,15 @@ impl Module {
|
||||||
let loc = self.def_id.loc(db);
|
let loc = self.def_id.loc(db);
|
||||||
let module_tree = db.module_tree(loc.source_root_id);
|
let module_tree = db.module_tree(loc.source_root_id);
|
||||||
let module_id = loc.module_id.crate_root(&module_tree);
|
let module_id = loc.module_id.crate_root(&module_tree);
|
||||||
Module::from_module_id(db, loc.source_root_id, module_id)
|
Ok(Module::from_module_id(db, loc.source_root_id, module_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds a child module with the specified name.
|
/// Finds a child module with the specified name.
|
||||||
pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> {
|
||||||
let loc = self.def_id.loc(db);
|
let loc = self.def_id.loc(db);
|
||||||
let module_tree = db.module_tree(loc.source_root_id);
|
let module_tree = db.module_tree(loc.source_root_id);
|
||||||
let child_id = ctry!(loc.module_id.child(&module_tree, name));
|
let child_id = loc.module_id.child(&module_tree, name)?;
|
||||||
Module::from_module_id(db, loc.source_root_id, child_id).map(Some)
|
Some(Module::from_module_id(db, loc.source_root_id, child_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterates over all child modules.
|
/// Iterates over all child modules.
|
||||||
|
@ -106,7 +105,7 @@ impl Module {
|
||||||
.module_id
|
.module_id
|
||||||
.children(&module_tree)
|
.children(&module_tree)
|
||||||
.map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id))
|
.map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id))
|
||||||
.collect::<Cancelable<Vec<_>>>()?;
|
.collect::<Vec<_>>();
|
||||||
Ok(children.into_iter())
|
Ok(children.into_iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +113,11 @@ impl Module {
|
||||||
let loc = self.def_id.loc(db);
|
let loc = self.def_id.loc(db);
|
||||||
let module_tree = db.module_tree(loc.source_root_id);
|
let module_tree = db.module_tree(loc.source_root_id);
|
||||||
let parent_id = ctry!(loc.module_id.parent(&module_tree));
|
let parent_id = ctry!(loc.module_id.parent(&module_tree));
|
||||||
Module::from_module_id(db, loc.source_root_id, parent_id).map(Some)
|
Ok(Some(Module::from_module_id(
|
||||||
|
db,
|
||||||
|
loc.source_root_id,
|
||||||
|
parent_id,
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a `ModuleScope`: a set of items, visible in this module.
|
/// Returns a `ModuleScope`: a set of items, visible in this module.
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub trait HirDatabase: SyntaxDatabase
|
||||||
use fn crate::module_tree::Submodule::submodules_query;
|
use fn crate::module_tree::Submodule::submodules_query;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<InputModuleItems>> {
|
fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<InputModuleItems> {
|
||||||
type InputModuleItemsQuery;
|
type InputModuleItemsQuery;
|
||||||
use fn query_definitions::input_module_items;
|
use fn query_definitions::input_module_items;
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ impl DefId {
|
||||||
let loc = self.loc(db);
|
let loc = self.loc(db);
|
||||||
let res = match loc.kind {
|
let res = match loc.kind {
|
||||||
DefKind::Module => {
|
DefKind::Module => {
|
||||||
let module = Module::from_module_id(db, loc.source_root_id, loc.module_id)?;
|
let module = Module::from_module_id(db, loc.source_root_id, loc.module_id);
|
||||||
Def::Module(module)
|
Def::Module(module)
|
||||||
}
|
}
|
||||||
DefKind::Function => {
|
DefKind::Function => {
|
||||||
|
@ -208,7 +208,11 @@ impl DefId {
|
||||||
/// For a module, returns that module; for any other def, returns the containing module.
|
/// For a module, returns that module; for any other def, returns the containing module.
|
||||||
pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> {
|
pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> {
|
||||||
let loc = self.loc(db);
|
let loc = self.loc(db);
|
||||||
Module::from_module_id(db, loc.source_root_id, loc.module_id)
|
Ok(Module::from_module_id(
|
||||||
|
db,
|
||||||
|
loc.source_root_id,
|
||||||
|
loc.module_id,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the containing crate.
|
/// Returns the containing crate.
|
||||||
|
|
|
@ -196,7 +196,7 @@ pub(crate) fn impls_in_module(
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
) -> Cancelable<Arc<ModuleImplBlocks>> {
|
) -> Cancelable<Arc<ModuleImplBlocks>> {
|
||||||
let mut result = ModuleImplBlocks::new();
|
let mut result = ModuleImplBlocks::new();
|
||||||
let module = Module::from_module_id(db, source_root_id, module_id)?;
|
let module = Module::from_module_id(db, source_root_id, module_id);
|
||||||
result.collect(db, module)?;
|
result.collect(db, module)?;
|
||||||
Ok(Arc::new(result))
|
Ok(Arc::new(result))
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,7 @@ use crate::{
|
||||||
fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) {
|
fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) {
|
||||||
let (db, pos) = MockDatabase::with_position(fixture);
|
let (db, pos) = MockDatabase::with_position(fixture);
|
||||||
let source_root = db.file_source_root(pos.file_id);
|
let source_root = db.file_source_root(pos.file_id);
|
||||||
let module = crate::source_binder::module_from_position(&db, pos)
|
let module = crate::source_binder::module_from_position(&db, pos).unwrap();
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
let module_id = module.def_id.loc(&db).module_id;
|
let module_id = module.def_id.loc(&db).module_id;
|
||||||
(db.item_map(source_root).unwrap(), module_id)
|
(db.item_map(source_root).unwrap(), module_id)
|
||||||
}
|
}
|
||||||
|
@ -242,9 +240,7 @@ fn item_map_across_crates() {
|
||||||
db.set_crate_graph(crate_graph);
|
db.set_crate_graph(crate_graph);
|
||||||
|
|
||||||
let source_root = db.file_source_root(main_id);
|
let source_root = db.file_source_root(main_id);
|
||||||
let module = crate::source_binder::module_from_file_id(&db, main_id)
|
let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
let module_id = module.def_id.loc(&db).module_id;
|
let module_id = module.def_id.loc(&db).module_id;
|
||||||
let item_map = db.item_map(source_root).unwrap();
|
let item_map = db.item_map(source_root).unwrap();
|
||||||
|
|
||||||
|
@ -296,9 +292,7 @@ fn import_across_source_roots() {
|
||||||
|
|
||||||
db.set_crate_graph(crate_graph);
|
db.set_crate_graph(crate_graph);
|
||||||
|
|
||||||
let module = crate::source_binder::module_from_file_id(&db, main_id)
|
let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
let module_id = module.def_id.loc(&db).module_id;
|
let module_id = module.def_id.loc(&db).module_id;
|
||||||
let item_map = db.item_map(source_root).unwrap();
|
let item_map = db.item_map(source_root).unwrap();
|
||||||
|
|
||||||
|
@ -341,9 +335,7 @@ fn reexport_across_crates() {
|
||||||
db.set_crate_graph(crate_graph);
|
db.set_crate_graph(crate_graph);
|
||||||
|
|
||||||
let source_root = db.file_source_root(main_id);
|
let source_root = db.file_source_root(main_id);
|
||||||
let module = crate::source_binder::module_from_file_id(&db, main_id)
|
let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
let module_id = module.def_id.loc(&db).module_id;
|
let module_id = module.def_id.loc(&db).module_id;
|
||||||
let item_map = db.item_map(source_root).unwrap();
|
let item_map = db.item_map(source_root).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub(super) fn input_module_items(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
source_root_id: SourceRootId,
|
source_root_id: SourceRootId,
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
) -> Cancelable<Arc<InputModuleItems>> {
|
) -> Arc<InputModuleItems> {
|
||||||
let module_tree = db.module_tree(source_root_id);
|
let module_tree = db.module_tree(source_root_id);
|
||||||
let source = module_id.source(&module_tree);
|
let source = module_id.source(&module_tree);
|
||||||
let file_id = source.file_id;
|
let file_id = source.file_id;
|
||||||
|
@ -90,7 +90,7 @@ pub(super) fn input_module_items(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(Arc::new(res))
|
Arc::new(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn item_map(
|
pub(super) fn item_map(
|
||||||
|
@ -101,11 +101,8 @@ pub(super) fn item_map(
|
||||||
let module_tree = db.module_tree(source_root);
|
let module_tree = db.module_tree(source_root);
|
||||||
let input = module_tree
|
let input = module_tree
|
||||||
.modules()
|
.modules()
|
||||||
.map(|id| {
|
.map(|id| (id, db.input_module_items(source_root, id)))
|
||||||
let items = db.input_module_items(source_root, id)?;
|
.collect::<FxHashMap<_, _>>();
|
||||||
Ok((id, items))
|
|
||||||
})
|
|
||||||
.collect::<Cancelable<FxHashMap<_, _>>>()?;
|
|
||||||
|
|
||||||
let resolver = Resolver::new(db, &input, source_root, module_tree);
|
let resolver = Resolver::new(db, &input, source_root, module_tree);
|
||||||
let res = resolver.resolve()?;
|
let res = resolver.resolve()?;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
///
|
///
|
||||||
/// So, this modules should not be used during hir construction, it exists
|
/// So, this modules should not be used during hir construction, it exists
|
||||||
/// purely for "IDE needs".
|
/// purely for "IDE needs".
|
||||||
use ra_db::{FileId, FilePosition, Cancelable};
|
use ra_db::{FileId, FilePosition};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
SmolStr, TextRange, SyntaxNode,
|
SmolStr, TextRange, SyntaxNode,
|
||||||
ast::{self, AstNode, NameOwner},
|
ast::{self, AstNode, NameOwner},
|
||||||
|
@ -18,7 +18,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Locates the module by `FileId`. Picks topmost module in the file.
|
/// Locates the module by `FileId`. Picks topmost module in the file.
|
||||||
pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Cancelable<Option<Module>> {
|
pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Option<Module> {
|
||||||
let module_source = SourceItemId {
|
let module_source = SourceItemId {
|
||||||
file_id: file_id.into(),
|
file_id: file_id.into(),
|
||||||
item_id: None,
|
item_id: None,
|
||||||
|
@ -31,25 +31,22 @@ pub fn module_from_declaration(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
decl: &ast::Module,
|
decl: &ast::Module,
|
||||||
) -> Cancelable<Option<Module>> {
|
) -> Option<Module> {
|
||||||
let parent_module = module_from_file_id(db, file_id)?;
|
let parent_module = module_from_file_id(db, file_id);
|
||||||
let child_name = decl.name();
|
let child_name = decl.name();
|
||||||
match (parent_module, child_name) {
|
match (parent_module, child_name) {
|
||||||
(Some(parent_module), Some(child_name)) => {
|
(Some(parent_module), Some(child_name)) => {
|
||||||
if let Some(child) = parent_module.child(db, &child_name.as_name())? {
|
if let Some(child) = parent_module.child(db, &child_name.as_name()) {
|
||||||
return Ok(Some(child));
|
return Some(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
Ok(None)
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Locates the module by position in the source code.
|
/// Locates the module by position in the source code.
|
||||||
pub fn module_from_position(
|
pub fn module_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Module> {
|
||||||
db: &impl HirDatabase,
|
|
||||||
position: FilePosition,
|
|
||||||
) -> Cancelable<Option<Module>> {
|
|
||||||
let file = db.source_file(position.file_id);
|
let file = db.source_file(position.file_id);
|
||||||
match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) {
|
match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) {
|
||||||
Some(m) if !m.has_semi() => module_from_inline(db, position.file_id.into(), m),
|
Some(m) if !m.has_semi() => module_from_inline(db, position.file_id.into(), m),
|
||||||
|
@ -61,7 +58,7 @@ fn module_from_inline(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
module: &ast::Module,
|
module: &ast::Module,
|
||||||
) -> Cancelable<Option<Module>> {
|
) -> Option<Module> {
|
||||||
assert!(!module.has_semi());
|
assert!(!module.has_semi());
|
||||||
let file_id = file_id.into();
|
let file_id = file_id.into();
|
||||||
let file_items = db.file_items(file_id);
|
let file_items = db.file_items(file_id);
|
||||||
|
@ -78,7 +75,7 @@ pub fn module_from_child_node(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
child: &SyntaxNode,
|
child: &SyntaxNode,
|
||||||
) -> Cancelable<Option<Module>> {
|
) -> Option<Module> {
|
||||||
if let Some(m) = child
|
if let Some(m) = child
|
||||||
.ancestors()
|
.ancestors()
|
||||||
.filter_map(ast::Module::cast)
|
.filter_map(ast::Module::cast)
|
||||||
|
@ -90,22 +87,16 @@ pub fn module_from_child_node(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Cancelable<Option<Module>> {
|
fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Option<Module> {
|
||||||
let source_root_id = db.file_source_root(source.file_id.as_original_file());
|
let source_root_id = db.file_source_root(source.file_id.as_original_file());
|
||||||
let module_tree = db.module_tree(source_root_id);
|
let module_tree = db.module_tree(source_root_id);
|
||||||
let module_id = ctry!(module_tree.find_module_by_source(source));
|
let module_id = module_tree.find_module_by_source(source)?;
|
||||||
Ok(Some(Module::from_module_id(db, source_root_id, module_id)?))
|
Some(Module::from_module_id(db, source_root_id, module_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn function_from_position(
|
pub fn function_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Function> {
|
||||||
db: &impl HirDatabase,
|
|
||||||
position: FilePosition,
|
|
||||||
) -> Cancelable<Option<Function>> {
|
|
||||||
let file = db.source_file(position.file_id);
|
let file = db.source_file(position.file_id);
|
||||||
let fn_def = ctry!(find_node_at_offset::<ast::FnDef>(
|
let fn_def = find_node_at_offset::<ast::FnDef>(file.syntax(), position.offset)?;
|
||||||
file.syntax(),
|
|
||||||
position.offset
|
|
||||||
));
|
|
||||||
function_from_source(db, position.file_id, fn_def)
|
function_from_source(db, position.file_id, fn_def)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,10 +104,10 @@ pub fn function_from_source(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
fn_def: &ast::FnDef,
|
fn_def: &ast::FnDef,
|
||||||
) -> Cancelable<Option<Function>> {
|
) -> Option<Function> {
|
||||||
let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?);
|
let module = module_from_child_node(db, file_id, fn_def.syntax())?;
|
||||||
let res = function_from_module(db, &module, fn_def);
|
let res = function_from_module(db, &module, fn_def);
|
||||||
Ok(Some(res))
|
Some(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn function_from_module(
|
pub fn function_from_module(
|
||||||
|
@ -145,21 +136,18 @@ pub fn function_from_child_node(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
node: &SyntaxNode,
|
node: &SyntaxNode,
|
||||||
) -> Cancelable<Option<Function>> {
|
) -> Option<Function> {
|
||||||
let fn_def = ctry!(node.ancestors().find_map(ast::FnDef::cast));
|
let fn_def = node.ancestors().find_map(ast::FnDef::cast)?;
|
||||||
function_from_source(db, file_id, fn_def)
|
function_from_source(db, file_id, fn_def)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn macro_symbols(
|
pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, TextRange)> {
|
||||||
db: &impl HirDatabase,
|
let module = match module_from_file_id(db, file_id) {
|
||||||
file_id: FileId,
|
|
||||||
) -> Cancelable<Vec<(SmolStr, TextRange)>> {
|
|
||||||
let module = match module_from_file_id(db, file_id)? {
|
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => return Ok(Vec::new()),
|
None => return Vec::new(),
|
||||||
};
|
};
|
||||||
let loc = module.def_id.loc(db);
|
let loc = module.def_id.loc(db);
|
||||||
let items = db.input_module_items(loc.source_root_id, loc.module_id)?;
|
let items = db.input_module_items(loc.source_root_id, loc.module_id);
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
|
|
||||||
for macro_call_id in items
|
for macro_call_id in items
|
||||||
|
@ -184,5 +172,5 @@ pub fn macro_symbols(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(res)
|
res
|
||||||
}
|
}
|
||||||
|
|
|
@ -320,9 +320,7 @@ fn infer(content: &str) -> String {
|
||||||
.descendants()
|
.descendants()
|
||||||
.filter_map(ast::FnDef::cast)
|
.filter_map(ast::FnDef::cast)
|
||||||
{
|
{
|
||||||
let func = source_binder::function_from_source(&db, file_id, fn_def)
|
let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap();
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
let inference_result = func.infer(&db).unwrap();
|
let inference_result = func.infer(&db).unwrap();
|
||||||
let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap();
|
let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap();
|
||||||
let mut types = Vec::new();
|
let mut types = Vec::new();
|
||||||
|
@ -404,9 +402,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
let func = source_binder::function_from_position(&db, pos)
|
let func = source_binder::function_from_position(&db, pos).unwrap();
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
{
|
{
|
||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
func.infer(&db).unwrap();
|
func.infer(&db).unwrap();
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl<'a> CompletionContext<'a> {
|
||||||
original_file: &'a SourceFile,
|
original_file: &'a SourceFile,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
) -> Cancelable<Option<CompletionContext<'a>>> {
|
) -> Cancelable<Option<CompletionContext<'a>>> {
|
||||||
let module = source_binder::module_from_position(db, position)?;
|
let module = source_binder::module_from_position(db, position);
|
||||||
let leaf =
|
let leaf =
|
||||||
ctry!(find_leaf_at_offset(original_file.syntax(), position.offset).left_biased());
|
ctry!(find_leaf_at_offset(original_file.syntax(), position.offset).left_biased());
|
||||||
let mut ctx = CompletionContext {
|
let mut ctx = CompletionContext {
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub(crate) fn reference_definition(
|
||||||
) -> Cancelable<ReferenceResult> {
|
) -> Cancelable<ReferenceResult> {
|
||||||
use self::ReferenceResult::*;
|
use self::ReferenceResult::*;
|
||||||
if let Some(function) =
|
if let Some(function) =
|
||||||
hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())?
|
hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())
|
||||||
{
|
{
|
||||||
let scope = function.scopes(db)?;
|
let scope = function.scopes(db)?;
|
||||||
// First try to resolve the symbol locally
|
// First try to resolve the symbol locally
|
||||||
|
@ -77,8 +77,7 @@ pub(crate) fn reference_definition(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Then try module name resolution
|
// Then try module name resolution
|
||||||
if let Some(module) =
|
if let Some(module) = hir::source_binder::module_from_child_node(db, file_id, name_ref.syntax())
|
||||||
hir::source_binder::module_from_child_node(db, file_id, name_ref.syntax())?
|
|
||||||
{
|
{
|
||||||
if let Some(path) = name_ref
|
if let Some(path) = name_ref
|
||||||
.syntax()
|
.syntax()
|
||||||
|
@ -111,7 +110,7 @@ fn name_definition(
|
||||||
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
|
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
|
||||||
if module.has_semi() {
|
if module.has_semi() {
|
||||||
if let Some(child_module) =
|
if let Some(child_module) =
|
||||||
hir::source_binder::module_from_declaration(db, file_id, module)?
|
hir::source_binder::module_from_declaration(db, file_id, module)
|
||||||
{
|
{
|
||||||
let nav = NavigationTarget::from_module(db, child_module)?;
|
let nav = NavigationTarget::from_module(db, child_module)?;
|
||||||
return Ok(Some(vec![nav]));
|
return Ok(Some(vec![nav]));
|
||||||
|
|
|
@ -72,7 +72,7 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable<Option
|
||||||
db,
|
db,
|
||||||
frange.file_id,
|
frange.file_id,
|
||||||
parent_fn
|
parent_fn
|
||||||
)?);
|
));
|
||||||
let infer = function.infer(db)?;
|
let infer = function.infer(db)?;
|
||||||
let syntax_mapping = function.body_syntax_mapping(db)?;
|
let syntax_mapping = function.body_syntax_mapping(db)?;
|
||||||
if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) {
|
if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) {
|
||||||
|
|
|
@ -100,7 +100,7 @@ impl db::RootDatabase {
|
||||||
impl db::RootDatabase {
|
impl db::RootDatabase {
|
||||||
/// Returns `Vec` for the same reason as `parent_module`
|
/// Returns `Vec` for the same reason as `parent_module`
|
||||||
pub(crate) fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
|
pub(crate) fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
|
||||||
let module = match source_binder::module_from_file_id(self, file_id)? {
|
let module = match source_binder::module_from_file_id(self, file_id) {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => return Ok(Vec::new()),
|
None => return Ok(Vec::new()),
|
||||||
};
|
};
|
||||||
|
@ -147,7 +147,7 @@ impl db::RootDatabase {
|
||||||
db,
|
db,
|
||||||
position.file_id,
|
position.file_id,
|
||||||
binding.syntax(),
|
binding.syntax(),
|
||||||
)?);
|
));
|
||||||
return Ok(Some((binding, descr)));
|
return Ok(Some((binding, descr)));
|
||||||
};
|
};
|
||||||
let name_ref = ctry!(find_node_at_offset::<ast::NameRef>(syntax, position.offset));
|
let name_ref = ctry!(find_node_at_offset::<ast::NameRef>(syntax, position.offset));
|
||||||
|
@ -155,7 +155,7 @@ impl db::RootDatabase {
|
||||||
db,
|
db,
|
||||||
position.file_id,
|
position.file_id,
|
||||||
name_ref.syntax(),
|
name_ref.syntax(),
|
||||||
)?);
|
));
|
||||||
let scope = descr.scopes(db)?;
|
let scope = descr.scopes(db)?;
|
||||||
let resolved = ctry!(scope.resolve_local_name(name_ref));
|
let resolved = ctry!(scope.resolve_local_name(name_ref));
|
||||||
let resolved = resolved.ptr().resolve(source_file);
|
let resolved = resolved.ptr().resolve(source_file);
|
||||||
|
@ -179,7 +179,7 @@ impl db::RootDatabase {
|
||||||
fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)),
|
fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)),
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
if let Some(m) = source_binder::module_from_file_id(self, file_id)? {
|
if let Some(m) = source_binder::module_from_file_id(self, file_id) {
|
||||||
for (name_node, problem) in m.problems(self)? {
|
for (name_node, problem) in m.problems(self)? {
|
||||||
let source_root = self.file_source_root(file_id);
|
let source_root = self.file_source_root(file_id);
|
||||||
let diag = match problem {
|
let diag = match problem {
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub(crate) fn parent_module(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
) -> Cancelable<Vec<NavigationTarget>> {
|
) -> Cancelable<Vec<NavigationTarget>> {
|
||||||
let module = match hir::source_binder::module_from_position(db, position)? {
|
let module = match hir::source_binder::module_from_position(db, position) {
|
||||||
None => return Ok(Vec::new()),
|
None => return Ok(Vec::new()),
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
};
|
};
|
||||||
|
|
|
@ -75,8 +75,7 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Opt
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let range = module.syntax().range();
|
let range = module.syntax().range();
|
||||||
let module =
|
let module = hir::source_binder::module_from_child_node(db, file_id, module.syntax())?;
|
||||||
hir::source_binder::module_from_child_node(db, file_id, module.syntax()).ok()??;
|
|
||||||
|
|
||||||
// FIXME: thread cancellation instead of `.ok`ing
|
// FIXME: thread cancellation instead of `.ok`ing
|
||||||
let path = module
|
let path = module
|
||||||
|
|
|
@ -63,7 +63,7 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Cancelable<Arc<Sy
|
||||||
.map(move |(name, ptr)| FileSymbol { name, ptr, file_id })
|
.map(move |(name, ptr)| FileSymbol { name, ptr, file_id })
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
for (name, text_range) in hir::source_binder::macro_symbols(db, file_id)? {
|
for (name, text_range) in hir::source_binder::macro_symbols(db, file_id) {
|
||||||
let node = find_covering_node(source_file.syntax(), text_range);
|
let node = find_covering_node(source_file.syntax(), text_range);
|
||||||
let ptr = LocalSyntaxPtr::new(node);
|
let ptr = LocalSyntaxPtr::new(node);
|
||||||
symbols.push(FileSymbol { file_id, name, ptr })
|
symbols.push(FileSymbol { file_id, name, ptr })
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue