mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
renames
This commit is contained in:
parent
8c737255ff
commit
47be3a3a24
3 changed files with 49 additions and 47 deletions
|
@ -120,38 +120,36 @@ impl<'a> QueryCtx<'a> {
|
||||||
|
|
||||||
fn query_config() -> salsa::QueryConfig<State, Data> {
|
fn query_config() -> salsa::QueryConfig<State, Data> {
|
||||||
let mut res = salsa::QueryConfig::new();
|
let mut res = salsa::QueryConfig::new();
|
||||||
let queries: Vec<SalsaGroundQuery> = vec![
|
let queries: Vec<BoxedGroundQuery> = vec![
|
||||||
queries::FILE_TEXT.into(),
|
queries::FILE_TEXT.into(),
|
||||||
queries::FILE_SET.into(),
|
queries::FILE_SET.into(),
|
||||||
];
|
];
|
||||||
for q in queries {
|
for q in queries {
|
||||||
res = res.with_ground_query(q.query_type, q.f)
|
res = res.with_ground_query(q.query_type, q.f)
|
||||||
}
|
}
|
||||||
let queries: Vec<SalsaQuery> = vec![
|
let mut queries: Vec<BoxedQuery> = vec![
|
||||||
queries::FILE_SYNTAX.into(),
|
queries::FILE_SYNTAX.into(),
|
||||||
::module_map_db::MODULE_DESCR.into(),
|
|
||||||
::module_map_db::RESOLVE_SUBMODULE.into(),
|
|
||||||
::module_map_db::PARENT_MODULE.into(),
|
|
||||||
];
|
];
|
||||||
|
::module_map_db::queries(&mut queries);
|
||||||
for q in queries {
|
for q in queries {
|
||||||
res = res.with_query(q.query_type, q.f);
|
res = res.with_query(q.query_type, q.f);
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SalsaGroundQuery {
|
struct BoxedGroundQuery {
|
||||||
query_type: salsa::QueryTypeId,
|
query_type: salsa::QueryTypeId,
|
||||||
f: Box<Fn(&State, &Data) -> (Data, salsa::OutputFingerprint) + Send + Sync + 'static>,
|
f: Box<Fn(&State, &Data) -> (Data, salsa::OutputFingerprint) + Send + Sync + 'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, R> From<GroundQuery<T, R>> for SalsaGroundQuery
|
impl<T, R> From<GroundQuery<T, R>> for BoxedGroundQuery
|
||||||
where
|
where
|
||||||
T: Send + Sync + 'static,
|
T: Send + Sync + 'static,
|
||||||
R: Send + Sync + 'static,
|
R: Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
fn from(q: GroundQuery<T, R>) -> SalsaGroundQuery
|
fn from(q: GroundQuery<T, R>) -> BoxedGroundQuery
|
||||||
{
|
{
|
||||||
SalsaGroundQuery {
|
BoxedGroundQuery {
|
||||||
query_type: salsa::QueryTypeId(q.id),
|
query_type: salsa::QueryTypeId(q.id),
|
||||||
f: Box::new(move |state, data| {
|
f: Box::new(move |state, data| {
|
||||||
let data: &T = data.downcast_ref().unwrap();
|
let data: &T = data.downcast_ref().unwrap();
|
||||||
|
@ -163,19 +161,19 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SalsaQuery {
|
pub(crate) struct BoxedQuery {
|
||||||
query_type: salsa::QueryTypeId,
|
query_type: salsa::QueryTypeId,
|
||||||
f: Box<Fn(&salsa::QueryCtx<State, Data>, &Data) -> (Data, salsa::OutputFingerprint) + Send + Sync + 'static>,
|
f: Box<Fn(&salsa::QueryCtx<State, Data>, &Data) -> (Data, salsa::OutputFingerprint) + Send + Sync + 'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, R> From<Query<T, R>> for SalsaQuery
|
impl<T, R> From<Query<T, R>> for BoxedQuery
|
||||||
where
|
where
|
||||||
T: Hash + Send + Sync + 'static,
|
T: Hash + Send + Sync + 'static,
|
||||||
R: Hash + Send + Sync + 'static,
|
R: Hash + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
fn from(q: Query<T, R>) -> SalsaQuery
|
fn from(q: Query<T, R>) -> BoxedQuery
|
||||||
{
|
{
|
||||||
SalsaQuery {
|
BoxedQuery {
|
||||||
query_type: salsa::QueryTypeId(q.id),
|
query_type: salsa::QueryTypeId(q.id),
|
||||||
f: Box::new(move |ctx, data| {
|
f: Box::new(move |ctx, data| {
|
||||||
let ctx = QueryCtx { inner: ctx };
|
let ctx = QueryCtx { inner: ctx };
|
||||||
|
|
29
crates/libanalysis/src/module_map_db/descr.rs
Normal file
29
crates/libanalysis/src/module_map_db/descr.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
use libsyntax2::{
|
||||||
|
SmolStr,
|
||||||
|
ast::{self, NameOwner},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Hash)]
|
||||||
|
pub struct ModuleDescr {
|
||||||
|
pub submodules: Vec<Submodule>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ModuleDescr {
|
||||||
|
pub fn new(root: ast::Root) -> ModuleDescr {
|
||||||
|
let submodules = root
|
||||||
|
.modules()
|
||||||
|
.filter_map(|module| {
|
||||||
|
let name = module.name()?.text();
|
||||||
|
if !module.has_semi() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(Submodule { name })
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
ModuleDescr { submodules } }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Hash, PartialEq, Eq, Debug)]
|
||||||
|
pub struct Submodule {
|
||||||
|
pub name: SmolStr,
|
||||||
|
}
|
|
@ -1,12 +1,20 @@
|
||||||
|
mod descr;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use {
|
use {
|
||||||
FileId,
|
FileId,
|
||||||
db::{
|
db::{
|
||||||
Query, QueryCtx
|
BoxedQuery, Query, QueryCtx
|
||||||
},
|
},
|
||||||
module_map::resolve_submodule,
|
module_map::resolve_submodule,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub(crate) fn queries(acc: &mut Vec<BoxedQuery>) {
|
||||||
|
acc.push(MODULE_DESCR.into());
|
||||||
|
acc.push(RESOLVE_SUBMODULE.into());
|
||||||
|
acc.push(PARENT_MODULE.into());
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> QueryCtx<'a> {
|
impl<'a> QueryCtx<'a> {
|
||||||
fn module_descr(&self, file_id: FileId) -> Arc<descr::ModuleDescr> {
|
fn module_descr(&self, file_id: FileId) -> Arc<descr::ModuleDescr> {
|
||||||
self.get(MODULE_DESCR, file_id)
|
self.get(MODULE_DESCR, file_id)
|
||||||
|
@ -52,39 +60,6 @@ pub(crate) const PARENT_MODULE: Query<FileId, Vec<FileId>> = Query {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
mod descr {
|
|
||||||
use libsyntax2::{
|
|
||||||
SmolStr,
|
|
||||||
ast::{self, NameOwner},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Hash)]
|
|
||||||
pub struct ModuleDescr {
|
|
||||||
pub submodules: Vec<Submodule>
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ModuleDescr {
|
|
||||||
pub fn new(root: ast::Root) -> ModuleDescr {
|
|
||||||
let submodules = root
|
|
||||||
.modules()
|
|
||||||
.filter_map(|module| {
|
|
||||||
let name = module.name()?.text();
|
|
||||||
if !module.has_semi() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(Submodule { name })
|
|
||||||
}).collect();
|
|
||||||
|
|
||||||
ModuleDescr { submodules } }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Hash, PartialEq, Eq, Debug)]
|
|
||||||
pub struct Submodule {
|
|
||||||
pub name: SmolStr,
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
Loading…
Reference in a new issue