mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-11 20:58:54 +00:00
move ids to HIR
This commit is contained in:
parent
11168c464c
commit
f66e5b6e6b
10 changed files with 71 additions and 80 deletions
|
@ -5,9 +5,8 @@ use salsa::{self, Database};
|
|||
use ra_db::{LocationIntener, BaseDatabase};
|
||||
|
||||
use crate::{
|
||||
hir,
|
||||
hir::{self, DefId, DefLoc, FnId, SourceItemId},
|
||||
symbol_index,
|
||||
loc2id::{IdMaps, DefId, DefLoc, FnId},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -21,6 +20,12 @@ pub(crate) struct RootDatabase {
|
|||
id_maps: Arc<IdMaps>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct IdMaps {
|
||||
fns: LocationIntener<SourceItemId, FnId>,
|
||||
defs: LocationIntener<DefLoc, DefId>,
|
||||
}
|
||||
|
||||
impl salsa::Database for RootDatabase {
|
||||
fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> {
|
||||
&self.runtime
|
||||
|
|
|
@ -9,13 +9,13 @@ use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase};
|
|||
use crate::{
|
||||
FileId,
|
||||
hir::{
|
||||
DefLoc, DefId, FnId,
|
||||
SourceFileItems, SourceItemId,
|
||||
query_definitions,
|
||||
function::{FnScopes},
|
||||
module::{ModuleId, ModuleTree, ModuleSource,
|
||||
nameres::{ItemMap, InputModuleItems}},
|
||||
},
|
||||
loc2id::{DefLoc, DefId, FnId},
|
||||
Cancelable,
|
||||
};
|
||||
|
||||
|
|
|
@ -11,12 +11,11 @@ use ra_syntax::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
hir::{HirDatabase, SourceItemId},
|
||||
hir::{FnId, HirDatabase, SourceItemId},
|
||||
FileId,
|
||||
};
|
||||
|
||||
pub(crate) use self::scope::FnScopes;
|
||||
pub(crate) use crate::loc2id::FnId;
|
||||
|
||||
impl FnId {
|
||||
pub(crate) fn get(db: &impl HirDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId {
|
||||
|
|
|
@ -14,11 +14,11 @@ mod path;
|
|||
use std::ops::Index;
|
||||
|
||||
use ra_syntax::{SyntaxNodeRef, SyntaxNode};
|
||||
use ra_db::{LocationIntener, SourceRootId};
|
||||
|
||||
use crate::{
|
||||
FileId,
|
||||
hir::db::HirDatabase,
|
||||
loc2id::{DefId, DefLoc},
|
||||
Cancelable,
|
||||
arena::{Arena, Id},
|
||||
};
|
||||
|
@ -31,6 +31,49 @@ pub(crate) use self::{
|
|||
|
||||
pub use self::function::FnSignatureInfo;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct FnId(u32);
|
||||
ra_db::impl_numeric_id!(FnId);
|
||||
|
||||
impl FnId {
|
||||
pub(crate) fn from_loc(
|
||||
db: &impl AsRef<LocationIntener<SourceItemId, FnId>>,
|
||||
loc: &SourceItemId,
|
||||
) -> FnId {
|
||||
db.as_ref().loc2id(loc)
|
||||
}
|
||||
pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<SourceItemId, FnId>>) -> SourceItemId {
|
||||
db.as_ref().id2loc(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct DefId(u32);
|
||||
ra_db::impl_numeric_id!(DefId);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub(crate) enum DefLoc {
|
||||
Module {
|
||||
id: ModuleId,
|
||||
source_root: SourceRootId,
|
||||
},
|
||||
Item {
|
||||
source_item_id: SourceItemId,
|
||||
},
|
||||
}
|
||||
|
||||
impl DefId {
|
||||
pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc {
|
||||
db.as_ref().id2loc(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl DefLoc {
|
||||
pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId {
|
||||
db.as_ref().loc2id(&self)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum Def {
|
||||
Module(Module),
|
||||
Item,
|
||||
|
|
|
@ -15,9 +15,8 @@ use relative_path::RelativePathBuf;
|
|||
|
||||
use crate::{
|
||||
FileId, FilePosition, Cancelable,
|
||||
hir::{Path, PathKind, HirDatabase, SourceItemId},
|
||||
hir::{DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId},
|
||||
arena::{Arena, Id},
|
||||
loc2id::{DefLoc, DefId},
|
||||
};
|
||||
|
||||
pub(crate) use self::nameres::ModuleScope;
|
||||
|
|
|
@ -28,8 +28,8 @@ use ra_db::SourceRootId;
|
|||
|
||||
use crate::{
|
||||
Cancelable, FileId,
|
||||
loc2id::{DefId, DefLoc},
|
||||
hir::{
|
||||
DefId, DefLoc,
|
||||
SourceItemId, SourceFileItemId, SourceFileItems,
|
||||
Path, PathKind,
|
||||
HirDatabase,
|
||||
|
|
|
@ -13,9 +13,10 @@ use ra_db::SourceRootId;
|
|||
use crate::{
|
||||
FileId, Cancelable,
|
||||
hir::{
|
||||
FnId,
|
||||
SourceFileItems, SourceItemId,
|
||||
db::HirDatabase,
|
||||
function::{FnId, FnScopes},
|
||||
function::FnScopes,
|
||||
module::{
|
||||
ModuleSource, ModuleSourceNode, ModuleId,
|
||||
imp::Submodule,
|
||||
|
|
|
@ -20,7 +20,6 @@ macro_rules! ctry {
|
|||
|
||||
mod arena;
|
||||
mod db;
|
||||
mod loc2id;
|
||||
mod imp;
|
||||
mod completion;
|
||||
mod hir;
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
use ra_db::SourceRootId;
|
||||
|
||||
use crate::{
|
||||
hir::{SourceItemId, ModuleId},
|
||||
};
|
||||
|
||||
use ra_db::{NumericId, LocationIntener};
|
||||
|
||||
macro_rules! impl_numeric_id {
|
||||
($id:ident) => {
|
||||
impl NumericId for $id {
|
||||
fn from_u32(id: u32) -> Self {
|
||||
$id(id)
|
||||
}
|
||||
fn to_u32(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct FnId(u32);
|
||||
impl_numeric_id!(FnId);
|
||||
|
||||
impl FnId {
|
||||
pub(crate) fn from_loc(
|
||||
db: &impl AsRef<LocationIntener<SourceItemId, FnId>>,
|
||||
loc: &SourceItemId,
|
||||
) -> FnId {
|
||||
db.as_ref().loc2id(loc)
|
||||
}
|
||||
pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<SourceItemId, FnId>>) -> SourceItemId {
|
||||
db.as_ref().id2loc(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct DefId(u32);
|
||||
impl_numeric_id!(DefId);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub(crate) enum DefLoc {
|
||||
Module {
|
||||
id: ModuleId,
|
||||
source_root: SourceRootId,
|
||||
},
|
||||
Item {
|
||||
source_item_id: SourceItemId,
|
||||
},
|
||||
}
|
||||
|
||||
impl DefId {
|
||||
pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc {
|
||||
db.as_ref().id2loc(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl DefLoc {
|
||||
pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId {
|
||||
db.as_ref().loc2id(&self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct IdMaps {
|
||||
pub(crate) fns: LocationIntener<SourceItemId, FnId>,
|
||||
pub(crate) defs: LocationIntener<DefLoc, DefId>,
|
||||
}
|
|
@ -38,6 +38,20 @@ pub use crate::{
|
|||
loc2id::{LocationIntener, NumericId},
|
||||
};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_numeric_id {
|
||||
($id:ident) => {
|
||||
impl $crate::NumericId for $id {
|
||||
fn from_u32(id: u32) -> Self {
|
||||
$id(id)
|
||||
}
|
||||
fn to_u32(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub trait BaseDatabase: salsa::Database {
|
||||
fn check_canceled(&self) -> Cancelable<()> {
|
||||
if self.salsa_runtime().is_current_revision_canceled() {
|
||||
|
|
Loading…
Reference in a new issue