mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Minor cleanup
This commit is contained in:
parent
aa0646be29
commit
fc055281a5
6 changed files with 44 additions and 47 deletions
|
@ -75,6 +75,36 @@ pub struct BodySourceMap {
|
|||
}
|
||||
|
||||
impl Body {
|
||||
pub(crate) fn body_with_source_map_query(
|
||||
db: &impl HirDatabase,
|
||||
def: DefWithBody,
|
||||
) -> (Arc<Body>, Arc<BodySourceMap>) {
|
||||
let mut params = None;
|
||||
|
||||
let (file_id, body) = match def {
|
||||
DefWithBody::Function(f) => {
|
||||
let src = f.source(db);
|
||||
params = src.ast.param_list();
|
||||
(src.file_id, src.ast.body().map(ast::Expr::from))
|
||||
}
|
||||
DefWithBody::Const(c) => {
|
||||
let src = c.source(db);
|
||||
(src.file_id, src.ast.body())
|
||||
}
|
||||
DefWithBody::Static(s) => {
|
||||
let src = s.source(db);
|
||||
(src.file_id, src.ast.body())
|
||||
}
|
||||
};
|
||||
|
||||
let (body, source_map) = lower::lower(db, def.resolver(db), file_id, def, params, body);
|
||||
(Arc::new(body), Arc::new(source_map))
|
||||
}
|
||||
|
||||
pub(crate) fn body_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<Body> {
|
||||
db.body_with_source_map(def).0
|
||||
}
|
||||
|
||||
pub fn params(&self) -> &[PatId] {
|
||||
&self.params
|
||||
}
|
||||
|
@ -542,34 +572,3 @@ impl Pat {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Queries
|
||||
pub(crate) fn body_with_source_map_query(
|
||||
db: &impl HirDatabase,
|
||||
def: DefWithBody,
|
||||
) -> (Arc<Body>, Arc<BodySourceMap>) {
|
||||
let mut params = None;
|
||||
|
||||
let (file_id, body) = match def {
|
||||
DefWithBody::Function(f) => {
|
||||
let src = f.source(db);
|
||||
params = src.ast.param_list();
|
||||
(src.file_id, src.ast.body().map(ast::Expr::from))
|
||||
}
|
||||
DefWithBody::Const(c) => {
|
||||
let src = c.source(db);
|
||||
(src.file_id, src.ast.body())
|
||||
}
|
||||
DefWithBody::Static(s) => {
|
||||
let src = s.source(db);
|
||||
(src.file_id, src.ast.body())
|
||||
}
|
||||
};
|
||||
|
||||
let (body, source_map) = lower::lower(db, def.resolver(db), file_id, def, params, body);
|
||||
(Arc::new(body), Arc::new(source_map))
|
||||
}
|
||||
|
||||
pub(crate) fn body_hir_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<Body> {
|
||||
db.body_with_source_map(def).0
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue