mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Simplify
This commit is contained in:
parent
e0b06cb672
commit
151180057b
2 changed files with 3 additions and 16 deletions
|
@ -282,7 +282,9 @@ where
|
||||||
let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
|
let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
|
||||||
let module = Module::from_definition(db, Source::new(src.file_id, module_src))?;
|
let module = Module::from_definition(db, Source::new(src.file_id, module_src))?;
|
||||||
let ctx = LocationCtx::new(db, module.id, src.file_id);
|
let ctx = LocationCtx::new(db, module.id, src.file_id);
|
||||||
Some(DEF::from_ast(ctx, &src.value))
|
let items = db.ast_id_map(src.file_id);
|
||||||
|
let item_id = items.ast_id(&src.value);
|
||||||
|
Some(DEF::from_ast_id(ctx, item_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Container {
|
enum Container {
|
||||||
|
|
|
@ -94,25 +94,10 @@ impl<'a, DB> LocationCtx<&'a DB> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, DB: AstDatabase + InternDatabase> LocationCtx<&'a DB> {
|
|
||||||
pub fn to_def<N, DEF>(self, ast: &N) -> DEF
|
|
||||||
where
|
|
||||||
N: AstNode,
|
|
||||||
DEF: AstItemDef<N>,
|
|
||||||
{
|
|
||||||
DEF::from_ast(self, ast)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
|
pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
|
||||||
fn intern(db: &impl InternDatabase, loc: ItemLoc<N>) -> Self;
|
fn intern(db: &impl InternDatabase, loc: ItemLoc<N>) -> Self;
|
||||||
fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<N>;
|
fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<N>;
|
||||||
|
|
||||||
fn from_ast(ctx: LocationCtx<&(impl AstDatabase + InternDatabase)>, ast: &N) -> Self {
|
|
||||||
let items = ctx.db.ast_id_map(ctx.file_id);
|
|
||||||
let item_id = items.ast_id(ast);
|
|
||||||
Self::from_ast_id(ctx, item_id)
|
|
||||||
}
|
|
||||||
fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId<N>) -> Self {
|
fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId<N>) -> Self {
|
||||||
let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) };
|
let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) };
|
||||||
Self::intern(ctx.db, loc)
|
Self::intern(ctx.db, loc)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue