mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
remove FnId
This commit is contained in:
parent
efb63a7666
commit
dddbac6877
7 changed files with 26 additions and 45 deletions
|
@ -3,7 +3,6 @@ use std::sync::Arc;
|
|||
use ra_syntax::{
|
||||
SmolStr,
|
||||
SyntaxNode,
|
||||
ast::FnDefNode,
|
||||
};
|
||||
use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, FileId, Cancelable};
|
||||
|
||||
|
@ -12,7 +11,6 @@ use crate::{
|
|||
SourceFileItems, SourceItemId,
|
||||
query_definitions,
|
||||
FnScopes,
|
||||
function::FnId,
|
||||
module::{ModuleId, ModuleTree, ModuleSource,
|
||||
nameres::{ItemMap, InputModuleItems}},
|
||||
ty::{InferenceResult, Ty},
|
||||
|
@ -24,14 +22,10 @@ salsa::query_group! {
|
|||
pub trait HirDatabase: SyntaxDatabase
|
||||
+ AsRef<LocationIntener<DefLoc, DefId>>
|
||||
{
|
||||
fn fn_scopes(fn_id: FnId) -> Arc<FnScopes> {
|
||||
fn fn_scopes(def_id: DefId) -> Arc<FnScopes> {
|
||||
type FnScopesQuery;
|
||||
use fn query_definitions::fn_scopes;
|
||||
}
|
||||
fn fn_syntax(fn_id: FnId) -> FnDefNode {
|
||||
type FnSyntaxQuery;
|
||||
use fn query_definitions::fn_syntax;
|
||||
}
|
||||
|
||||
fn struct_data(def_id: DefId) -> Cancelable<Arc<StructData>> {
|
||||
type StructDataQuery;
|
||||
|
@ -43,7 +37,7 @@ pub trait HirDatabase: SyntaxDatabase
|
|||
use fn query_definitions::enum_data;
|
||||
}
|
||||
|
||||
fn infer(fn_id: FnId) -> Cancelable<Arc<InferenceResult>> {
|
||||
fn infer(def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
|
||||
type InferQuery;
|
||||
use fn query_definitions::infer;
|
||||
}
|
||||
|
|
|
@ -11,43 +11,42 @@ use ra_syntax::{
|
|||
ast::{self, AstNode, DocCommentsOwner, NameOwner},
|
||||
};
|
||||
|
||||
use crate::{ DefId, HirDatabase, ty::InferenceResult, Module };
|
||||
use crate::{DefId, DefKind, HirDatabase, ty::InferenceResult, Module};
|
||||
|
||||
pub use self::scope::FnScopes;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct FnId(pub(crate) DefId);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Function {
|
||||
pub(crate) fn_id: FnId,
|
||||
def_id: DefId,
|
||||
}
|
||||
|
||||
impl Function {
|
||||
pub(crate) fn new(def_id: DefId) -> Function {
|
||||
let fn_id = FnId(def_id);
|
||||
Function { fn_id }
|
||||
Function { def_id }
|
||||
}
|
||||
|
||||
pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode {
|
||||
db.fn_syntax(self.fn_id)
|
||||
let def_loc = self.def_id.loc(db);
|
||||
assert!(def_loc.kind == DefKind::Function);
|
||||
let syntax = db.file_item(def_loc.source_item_id);
|
||||
ast::FnDef::cast(syntax.borrowed()).unwrap().owned()
|
||||
}
|
||||
|
||||
pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
|
||||
db.fn_scopes(self.fn_id)
|
||||
db.fn_scopes(self.def_id)
|
||||
}
|
||||
|
||||
pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> {
|
||||
let syntax = db.fn_syntax(self.fn_id);
|
||||
let syntax = self.syntax(db);
|
||||
FnSignatureInfo::new(syntax.borrowed())
|
||||
}
|
||||
|
||||
pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> {
|
||||
db.infer(self.fn_id)
|
||||
db.infer(self.def_id)
|
||||
}
|
||||
|
||||
pub fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> {
|
||||
self.fn_id.0.module(db)
|
||||
self.def_id.module(db)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -189,7 +189,6 @@ salsa::database_storage! {
|
|||
fn file_item() for db::FileItemQuery;
|
||||
fn input_module_items() for db::InputModuleItemsQuery;
|
||||
fn item_map() for db::ItemMapQuery;
|
||||
fn fn_syntax() for db::FnSyntaxQuery;
|
||||
fn submodules() for db::SubmodulesQuery;
|
||||
fn infer() for db::InferQuery;
|
||||
fn type_for_def() for db::TypeForDefQuery;
|
||||
|
|
|
@ -5,15 +5,15 @@ use std::{
|
|||
|
||||
use rustc_hash::FxHashMap;
|
||||
use ra_syntax::{
|
||||
AstNode, SyntaxNode, SmolStr,
|
||||
ast::{self, FnDef, FnDefNode, NameOwner, ModuleItemOwner}
|
||||
AstNode, SyntaxNode, SmolStr,
|
||||
ast::{self, NameOwner, ModuleItemOwner}
|
||||
};
|
||||
use ra_db::{SourceRootId, FileId, Cancelable,};
|
||||
|
||||
use crate::{
|
||||
SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName,
|
||||
db::HirDatabase,
|
||||
function::{FnScopes, FnId},
|
||||
function::FnScopes,
|
||||
module::{
|
||||
ModuleSource, ModuleSourceNode, ModuleId,
|
||||
imp::Submodule,
|
||||
|
@ -23,22 +23,15 @@ use crate::{
|
|||
adt::{StructData, EnumData},
|
||||
};
|
||||
|
||||
/// Resolve `FnId` to the corresponding `SyntaxNode`
|
||||
pub(super) fn fn_syntax(db: &impl HirDatabase, fn_id: FnId) -> FnDefNode {
|
||||
let def_loc = fn_id.0.loc(db);
|
||||
assert!(def_loc.kind == DefKind::Function);
|
||||
let syntax = db.file_item(def_loc.source_item_id);
|
||||
FnDef::cast(syntax.borrowed()).unwrap().owned()
|
||||
}
|
||||
|
||||
pub(super) fn fn_scopes(db: &impl HirDatabase, fn_id: FnId) -> Arc<FnScopes> {
|
||||
let syntax = db.fn_syntax(fn_id);
|
||||
pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> {
|
||||
let function = Function::new(def_id);
|
||||
let syntax = function.syntax(db);
|
||||
let res = FnScopes::new(syntax.borrowed());
|
||||
Arc::new(res)
|
||||
}
|
||||
|
||||
pub(super) fn infer(db: &impl HirDatabase, fn_id: FnId) -> Cancelable<Arc<InferenceResult>> {
|
||||
let function = Function { fn_id };
|
||||
pub(super) fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
|
||||
let function = Function::new(def_id);
|
||||
ty::infer(db, function).map(Arc::new)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue