drop descriptor suffix, use hir:: instead

This commit is contained in:
Aleksey Kladov 2018-11-28 01:22:17 +03:00
parent 36b1d20c16
commit 806ea03b64
4 changed files with 19 additions and 20 deletions

View File

@ -25,43 +25,43 @@ impl FnId {
} }
} }
pub(crate) struct FunctionDescriptor { pub(crate) struct Function {
fn_id: FnId, fn_id: FnId,
} }
impl FunctionDescriptor { impl Function {
pub(crate) fn guess_from_source( pub(crate) fn guess_from_source(
db: &impl HirDatabase, db: &impl HirDatabase,
file_id: FileId, file_id: FileId,
fn_def: ast::FnDef, fn_def: ast::FnDef,
) -> FunctionDescriptor { ) -> Function {
let fn_id = FnId::get(db, file_id, fn_def); let fn_id = FnId::get(db, file_id, fn_def);
FunctionDescriptor { fn_id } Function { fn_id }
} }
pub(crate) fn guess_for_name_ref( pub(crate) fn guess_for_name_ref(
db: &impl HirDatabase, db: &impl HirDatabase,
file_id: FileId, file_id: FileId,
name_ref: ast::NameRef, name_ref: ast::NameRef,
) -> Option<FunctionDescriptor> { ) -> Option<Function> {
FunctionDescriptor::guess_for_node(db, file_id, name_ref.syntax()) Function::guess_for_node(db, file_id, name_ref.syntax())
} }
pub(crate) fn guess_for_bind_pat( pub(crate) fn guess_for_bind_pat(
db: &impl HirDatabase, db: &impl HirDatabase,
file_id: FileId, file_id: FileId,
bind_pat: ast::BindPat, bind_pat: ast::BindPat,
) -> Option<FunctionDescriptor> { ) -> Option<Function> {
FunctionDescriptor::guess_for_node(db, file_id, bind_pat.syntax()) Function::guess_for_node(db, file_id, bind_pat.syntax())
} }
fn guess_for_node( fn guess_for_node(
db: &impl HirDatabase, db: &impl HirDatabase,
file_id: FileId, file_id: FileId,
node: SyntaxNodeRef, node: SyntaxNodeRef,
) -> Option<FunctionDescriptor> { ) -> Option<Function> {
let fn_def = node.ancestors().find_map(ast::FnDef::cast)?; let fn_def = node.ancestors().find_map(ast::FnDef::cast)?;
let res = FunctionDescriptor::guess_from_source(db, file_id, fn_def); let res = Function::guess_from_source(db, file_id, fn_def);
Some(res) Some(res)
} }

View File

@ -20,7 +20,7 @@ use crate::{
pub(crate) use self::{ pub(crate) use self::{
path::{Path, PathKind}, path::{Path, PathKind},
module::{Module, ModuleId, Problem, nameres::FileItemId}, module::{Module, ModuleId, Problem, nameres::FileItemId},
function::{FunctionDescriptor, FnScopes}, function::{Function, FnScopes},
}; };
pub use self::function::FnSignatureInfo; pub use self::function::FnSignatureInfo;

View File

@ -371,7 +371,7 @@ mod tests {
use crate::{ use crate::{
AnalysisChange, AnalysisChange,
mock_analysis::{MockAnalysis, analysis_and_position}, mock_analysis::{MockAnalysis, analysis_and_position},
hir::{HirDatabase, module::ModuleDescriptor}, hir::{self, HirDatabase},
input::FilesDatabase, input::FilesDatabase,
}; };
use super::*; use super::*;
@ -380,7 +380,7 @@ mod tests {
let (analysis, pos) = analysis_and_position(fixture); let (analysis, pos) = analysis_and_position(fixture);
let db = analysis.imp.db; let db = analysis.imp.db;
let source_root = db.file_source_root(pos.file_id); let source_root = db.file_source_root(pos.file_id);
let descr = ModuleDescriptor::guess_from_position(&*db, pos) let descr = hir::Module::guess_from_position(&*db, pos)
.unwrap() .unwrap()
.unwrap(); .unwrap();
let module_id = descr.module_id; let module_id = descr.module_id;

View File

@ -21,7 +21,7 @@ use crate::{
db::{self, FileSyntaxQuery, SyntaxDatabase}, db::{self, FileSyntaxQuery, SyntaxDatabase},
hir::{ hir::{
self, self,
FunctionDescriptor, FnSignatureInfo, FnSignatureInfo,
Problem, Problem,
}, },
input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
@ -274,7 +274,7 @@ impl AnalysisImpl {
let syntax = file.syntax(); let syntax = file.syntax();
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) {
if let Some(fn_descr) = if let Some(fn_descr) =
FunctionDescriptor::guess_for_name_ref(&*self.db, position.file_id, name_ref) hir::Function::guess_for_name_ref(&*self.db, position.file_id, name_ref)
{ {
let scope = fn_descr.scope(&*self.db); let scope = fn_descr.scope(&*self.db);
// First try to resolve the symbol locally // First try to resolve the symbol locally
@ -344,14 +344,14 @@ impl AnalysisImpl {
db: &db::RootDatabase, db: &db::RootDatabase,
source_file: &'a SourceFileNode, source_file: &'a SourceFileNode,
position: FilePosition, position: FilePosition,
) -> Option<(ast::BindPat<'a>, FunctionDescriptor)> { ) -> Option<(ast::BindPat<'a>, hir::Function)> {
let syntax = source_file.syntax(); let syntax = source_file.syntax();
if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) {
let descr = FunctionDescriptor::guess_for_bind_pat(db, position.file_id, binding)?; let descr = hir::Function::guess_for_bind_pat(db, position.file_id, binding)?;
return Some((binding, descr)); return Some((binding, descr));
}; };
let name_ref = find_node_at_offset::<ast::NameRef>(syntax, position.offset)?; let name_ref = find_node_at_offset::<ast::NameRef>(syntax, position.offset)?;
let descr = FunctionDescriptor::guess_for_name_ref(db, position.file_id, name_ref)?; let descr = hir::Function::guess_for_name_ref(db, position.file_id, name_ref)?;
let scope = descr.scope(db); let scope = descr.scope(db);
let resolved = scope.resolve_local_name(name_ref)?; let resolved = scope.resolve_local_name(name_ref)?;
let resolved = resolved.ptr().resolve(source_file); let resolved = resolved.ptr().resolve(source_file);
@ -472,8 +472,7 @@ impl AnalysisImpl {
if fs.kind == FN_DEF { if fs.kind == FN_DEF {
let fn_file = self.db.file_syntax(fn_file_id); let fn_file = self.db.file_syntax(fn_file_id);
if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) {
let descr = let descr = hir::Function::guess_from_source(&*self.db, fn_file_id, fn_def);
FunctionDescriptor::guess_from_source(&*self.db, fn_file_id, fn_def);
if let Some(descriptor) = descr.signature_info(&*self.db) { if let Some(descriptor) = descr.signature_info(&*self.db) {
// If we have a calling expression let's find which argument we are on // If we have a calling expression let's find which argument we are on
let mut current_parameter = None; let mut current_parameter = None;