Move hir to a separate crate
This commit is contained in:
@@ -15,10 +15,10 @@ use crate::{
|
||||
FnId, HirDatabase, SourceItemId,
|
||||
};
|
||||
|
||||
pub(crate) use self::scope::FnScopes;
|
||||
pub use self::scope::FnScopes;
|
||||
|
||||
impl FnId {
|
||||
pub(crate) fn get(db: &impl HirDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId {
|
||||
pub fn get(db: &impl HirDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId {
|
||||
let file_items = db.file_items(file_id);
|
||||
let item_id = file_items.id_of(fn_def.syntax());
|
||||
let item_id = SourceItemId { file_id, item_id };
|
||||
@@ -26,12 +26,12 @@ impl FnId {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Function {
|
||||
pub struct Function {
|
||||
fn_id: FnId,
|
||||
}
|
||||
|
||||
impl Function {
|
||||
pub(crate) fn guess_from_source(
|
||||
pub fn guess_from_source(
|
||||
db: &impl HirDatabase,
|
||||
file_id: FileId,
|
||||
fn_def: ast::FnDef,
|
||||
@@ -40,7 +40,7 @@ impl Function {
|
||||
Function { fn_id }
|
||||
}
|
||||
|
||||
pub(crate) fn guess_for_name_ref(
|
||||
pub fn guess_for_name_ref(
|
||||
db: &impl HirDatabase,
|
||||
file_id: FileId,
|
||||
name_ref: ast::NameRef,
|
||||
@@ -48,7 +48,7 @@ impl Function {
|
||||
Function::guess_for_node(db, file_id, name_ref.syntax())
|
||||
}
|
||||
|
||||
pub(crate) fn guess_for_bind_pat(
|
||||
pub fn guess_for_bind_pat(
|
||||
db: &impl HirDatabase,
|
||||
file_id: FileId,
|
||||
bind_pat: ast::BindPat,
|
||||
@@ -66,11 +66,11 @@ impl Function {
|
||||
Some(res)
|
||||
}
|
||||
|
||||
pub(crate) fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
|
||||
pub fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
|
||||
db.fn_scopes(self.fn_id)
|
||||
}
|
||||
|
||||
pub(crate) fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> {
|
||||
pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> {
|
||||
let syntax = db.fn_syntax(self.fn_id);
|
||||
FnSignatureInfo::new(syntax.borrowed())
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ pub(crate) type ScopeId = Id<ScopeData>;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct FnScopes {
|
||||
pub(crate) self_param: Option<LocalSyntaxPtr>,
|
||||
pub self_param: Option<LocalSyntaxPtr>,
|
||||
scopes: Arena<ScopeData>,
|
||||
scope_for: FxHashMap<LocalSyntaxPtr, ScopeId>,
|
||||
}
|
||||
@@ -27,13 +27,13 @@ pub struct ScopeEntry {
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub(crate) struct ScopeData {
|
||||
pub struct ScopeData {
|
||||
parent: Option<ScopeId>,
|
||||
entries: Vec<ScopeEntry>,
|
||||
}
|
||||
|
||||
impl FnScopes {
|
||||
pub(crate) fn new(fn_def: ast::FnDef) -> FnScopes {
|
||||
pub fn new(fn_def: ast::FnDef) -> FnScopes {
|
||||
let mut scopes = FnScopes {
|
||||
self_param: fn_def
|
||||
.param_list()
|
||||
@@ -49,7 +49,7 @@ impl FnScopes {
|
||||
}
|
||||
scopes
|
||||
}
|
||||
pub(crate) fn entries(&self, scope: ScopeId) -> &[ScopeEntry] {
|
||||
pub fn entries(&self, scope: ScopeId) -> &[ScopeEntry] {
|
||||
&self.scopes[scope].entries
|
||||
}
|
||||
pub fn scope_chain<'a>(&'a self, node: SyntaxNodeRef) -> impl Iterator<Item = ScopeId> + 'a {
|
||||
@@ -57,10 +57,7 @@ impl FnScopes {
|
||||
self.scopes[scope].parent
|
||||
})
|
||||
}
|
||||
pub(crate) fn resolve_local_name<'a>(
|
||||
&'a self,
|
||||
name_ref: ast::NameRef,
|
||||
) -> Option<&'a ScopeEntry> {
|
||||
pub fn resolve_local_name<'a>(&'a self, name_ref: ast::NameRef) -> Option<&'a ScopeEntry> {
|
||||
let mut shadowed = FxHashSet::default();
|
||||
let ret = self
|
||||
.scope_chain(name_ref.syntax())
|
||||
@@ -138,10 +135,10 @@ impl ScopeEntry {
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
pub(crate) fn name(&self) -> &SmolStr {
|
||||
pub fn name(&self) -> &SmolStr {
|
||||
&self.name
|
||||
}
|
||||
pub(crate) fn ptr(&self) -> LocalSyntaxPtr {
|
||||
pub fn ptr(&self) -> LocalSyntaxPtr {
|
||||
self.ptr
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user