mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-27 22:34:14 +00:00
Merge #2372
2372: Note that debugging infra is broken r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
102f1984c6
@ -10,7 +10,6 @@ use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath
|
||||
hir::db::InternDatabaseStorage,
|
||||
hir::db::AstDatabaseStorage,
|
||||
hir::db::DefDatabaseStorage,
|
||||
hir::db::DefDatabase2Storage,
|
||||
hir::db::HirDatabaseStorage
|
||||
)]
|
||||
#[derive(Debug, Default)]
|
||||
|
@ -1,7 +1,6 @@
|
||||
//! FIXME: write short doc here
|
||||
|
||||
pub(crate) mod src;
|
||||
pub(crate) mod docs;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -9,11 +8,12 @@ use hir_def::{
|
||||
adt::VariantData,
|
||||
body::scope::ExprScopes,
|
||||
builtin_type::BuiltinType,
|
||||
docs::Documentation,
|
||||
nameres::per_ns::PerNs,
|
||||
resolver::{HasResolver, TypeNs},
|
||||
type_ref::TypeRef,
|
||||
AdtId, ContainerId, CrateModuleId, EnumVariantId, HasModule, ImplId, LocalEnumVariantId,
|
||||
LocalStructFieldId, Lookup, ModuleId, StructFieldId, UnionId,
|
||||
ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup,
|
||||
ModuleId, UnionId,
|
||||
};
|
||||
use hir_expand::{
|
||||
diagnostics::DiagnosticSink,
|
||||
@ -1024,18 +1024,17 @@ pub trait HasAttrs {
|
||||
|
||||
impl<T: Into<AttrDef>> HasAttrs for T {
|
||||
fn attrs(self, db: &impl DefDatabase) -> Attrs {
|
||||
let def = self.into();
|
||||
match def {
|
||||
AttrDef::Module(it) => db.attrs(it.id.into()),
|
||||
AttrDef::StructField(it) => db.attrs(StructFieldId::from(it).into()),
|
||||
AttrDef::Adt(it) => db.attrs(AdtId::from(it).into()),
|
||||
AttrDef::Function(it) => db.attrs(it.id.into()),
|
||||
AttrDef::EnumVariant(it) => db.attrs(EnumVariantId::from(it).into()),
|
||||
AttrDef::Static(it) => db.attrs(it.id.into()),
|
||||
AttrDef::Const(it) => db.attrs(it.id.into()),
|
||||
AttrDef::Trait(it) => db.attrs(it.id.into()),
|
||||
AttrDef::TypeAlias(it) => db.attrs(it.id.into()),
|
||||
AttrDef::MacroDef(it) => db.attrs(it.id.into()),
|
||||
}
|
||||
let def: AttrDef = self.into();
|
||||
db.attrs(def.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Docs {
|
||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation>;
|
||||
}
|
||||
impl<T: Into<AttrDef> + Copy> Docs for T {
|
||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||
let def: AttrDef = (*self).into();
|
||||
db.documentation(def.into())
|
||||
}
|
||||
}
|
||||
|
@ -1,97 +0,0 @@
|
||||
//! FIXME: write short doc here
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use ra_syntax::ast;
|
||||
|
||||
use crate::{
|
||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
||||
Adt, Const, Enum, EnumVariant, FieldSource, Function, HasSource, MacroDef, Module, Static,
|
||||
Struct, StructField, Trait, TypeAlias, Union,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum DocDef {
|
||||
Module(Module),
|
||||
StructField(StructField),
|
||||
Adt(Adt),
|
||||
EnumVariant(EnumVariant),
|
||||
Static(Static),
|
||||
Const(Const),
|
||||
Function(Function),
|
||||
Trait(Trait),
|
||||
TypeAlias(TypeAlias),
|
||||
MacroDef(MacroDef),
|
||||
}
|
||||
|
||||
impl_froms!(
|
||||
DocDef: Module,
|
||||
StructField,
|
||||
Adt(Struct, Enum, Union),
|
||||
EnumVariant,
|
||||
Static,
|
||||
Const,
|
||||
Function,
|
||||
Trait,
|
||||
TypeAlias,
|
||||
MacroDef
|
||||
);
|
||||
|
||||
/// Holds documentation
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Documentation(Arc<str>);
|
||||
|
||||
impl Documentation {
|
||||
fn new(s: &str) -> Documentation {
|
||||
Documentation(s.into())
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
&*self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<String> for Documentation {
|
||||
fn into(self) -> String {
|
||||
self.as_str().to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Docs {
|
||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation>;
|
||||
}
|
||||
|
||||
pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> {
|
||||
node.doc_comment_text().map(|it| Documentation::new(&it))
|
||||
}
|
||||
|
||||
pub(crate) fn documentation_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
def: DocDef,
|
||||
) -> Option<Documentation> {
|
||||
match def {
|
||||
DocDef::Module(it) => docs_from_ast(&it.declaration_source(db)?.value),
|
||||
DocDef::StructField(it) => match it.source(db).value {
|
||||
FieldSource::Named(named) => docs_from_ast(&named),
|
||||
FieldSource::Pos(..) => None,
|
||||
},
|
||||
DocDef::Adt(it) => match it {
|
||||
Adt::Struct(it) => docs_from_ast(&it.source(db).value),
|
||||
Adt::Enum(it) => docs_from_ast(&it.source(db).value),
|
||||
Adt::Union(it) => docs_from_ast(&it.source(db).value),
|
||||
},
|
||||
DocDef::EnumVariant(it) => docs_from_ast(&it.source(db).value),
|
||||
DocDef::Static(it) => docs_from_ast(&it.source(db).value),
|
||||
DocDef::Const(it) => docs_from_ast(&it.source(db).value),
|
||||
DocDef::Function(it) => docs_from_ast(&it.source(db).value),
|
||||
DocDef::Trait(it) => docs_from_ast(&it.source(db).value),
|
||||
DocDef::TypeAlias(it) => docs_from_ast(&it.source(db).value),
|
||||
DocDef::MacroDef(it) => docs_from_ast(&it.source(db).value),
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<DocDef> + Copy> Docs for T {
|
||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||
db.documentation((*self).into())
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ use std::sync::Arc;
|
||||
use ra_db::salsa;
|
||||
|
||||
use crate::{
|
||||
debug::HirDebugDatabase,
|
||||
ids,
|
||||
ty::{
|
||||
method_resolution::CrateImplBlocks,
|
||||
@ -18,24 +17,16 @@ use crate::{
|
||||
|
||||
pub use hir_def::db::{
|
||||
BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery,
|
||||
DefDatabase2, DefDatabase2Storage, EnumDataQuery, ExprScopesQuery, FunctionDataQuery,
|
||||
GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, LangItemQuery,
|
||||
ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery, StaticDataQuery,
|
||||
StructDataQuery, TraitDataQuery, TypeAliasDataQuery,
|
||||
DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery,
|
||||
FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage,
|
||||
LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery,
|
||||
StaticDataQuery, StructDataQuery, TraitDataQuery, TypeAliasDataQuery,
|
||||
};
|
||||
pub use hir_expand::db::{
|
||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
||||
ParseMacroQuery,
|
||||
};
|
||||
|
||||
// This database uses `AstDatabase` internally,
|
||||
#[salsa::query_group(DefDatabaseStorage)]
|
||||
#[salsa::requires(AstDatabase)]
|
||||
pub trait DefDatabase: HirDebugDatabase + DefDatabase2 {
|
||||
#[salsa::invoke(crate::code_model::docs::documentation_query)]
|
||||
fn documentation(&self, def: crate::DocDef) -> Option<crate::Documentation>;
|
||||
}
|
||||
|
||||
#[salsa::query_group(HirDatabaseStorage)]
|
||||
#[salsa::requires(salsa::Database)]
|
||||
pub trait HirDatabase: DefDatabase + AstDatabase {
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! XXX: This does not work at the moment.
|
||||
//!
|
||||
//! printf debugging infrastructure for rust-analyzer.
|
||||
//!
|
||||
//! When you print a hir type, like a module, using `eprintln!("{:?}", module)`,
|
||||
|
@ -4,14 +4,14 @@
|
||||
//! are splitting the hir.
|
||||
|
||||
use hir_def::{
|
||||
AdtId, AssocItemId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId,
|
||||
ModuleDefId, StaticId, StructFieldId, StructId, TypeAliasId, UnionId, VariantId,
|
||||
AdtId, AssocItemId, AttrDefId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId,
|
||||
GenericDefId, ModuleDefId, StaticId, StructFieldId, StructId, TypeAliasId, UnionId, VariantId,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ty::{CallableDef, TypableDef},
|
||||
Adt, AssocItem, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef, ModuleDef,
|
||||
Static, StructField, TypeAlias, VariantDef,
|
||||
Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef,
|
||||
ModuleDef, Static, StructField, TypeAlias, VariantDef,
|
||||
};
|
||||
|
||||
impl From<ra_db::CrateId> for Crate {
|
||||
@ -240,3 +240,20 @@ impl From<StructField> for StructFieldId {
|
||||
StructFieldId { parent: def.parent.into(), local_id: def.id }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AttrDef> for AttrDefId {
|
||||
fn from(def: AttrDef) -> Self {
|
||||
match def {
|
||||
AttrDef::Module(it) => AttrDefId::ModuleId(it.id),
|
||||
AttrDef::StructField(it) => AttrDefId::StructFieldId(it.into()),
|
||||
AttrDef::Adt(it) => AttrDefId::AdtId(it.into()),
|
||||
AttrDef::Function(it) => AttrDefId::FunctionId(it.id),
|
||||
AttrDef::EnumVariant(it) => AttrDefId::EnumVariantId(it.into()),
|
||||
AttrDef::Static(it) => AttrDefId::StaticId(it.id),
|
||||
AttrDef::Const(it) => AttrDefId::ConstId(it.id),
|
||||
AttrDef::Trait(it) => AttrDefId::TraitId(it.id),
|
||||
AttrDef::TypeAlias(it) => AttrDefId::TypeAliasId(it.id),
|
||||
AttrDef::MacroDef(it) => AttrDefId::MacroDefId(it.id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,9 +50,8 @@ mod marks;
|
||||
|
||||
pub use crate::{
|
||||
code_model::{
|
||||
docs::{DocDef, Docs, Documentation},
|
||||
src::{HasBodySource, HasSource},
|
||||
Adt, AssocItem, AttrDef, Const, Container, Crate, CrateDependency, DefWithBody, Enum,
|
||||
Adt, AssocItem, AttrDef, Const, Container, Crate, CrateDependency, DefWithBody, Docs, Enum,
|
||||
EnumVariant, FieldSource, Function, GenericDef, GenericParam, HasAttrs, HasBody, ImplBlock,
|
||||
Local, MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField,
|
||||
Trait, TypeAlias, Union, VariantDef,
|
||||
@ -70,6 +69,7 @@ pub use crate::{
|
||||
|
||||
pub use hir_def::{
|
||||
builtin_type::BuiltinType,
|
||||
docs::Documentation,
|
||||
nameres::{per_ns::PerNs, raw::ImportId},
|
||||
path::{Path, PathKind},
|
||||
type_ref::Mutability,
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use std::{panic, sync::Arc};
|
||||
|
||||
use hir_def::{db::DefDatabase2, ModuleId};
|
||||
use hir_def::{db::DefDatabase, ModuleId};
|
||||
use hir_expand::diagnostics::DiagnosticSink;
|
||||
use parking_lot::Mutex;
|
||||
use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase};
|
||||
@ -15,7 +15,6 @@ use crate::{db, debug::HirDebugHelper};
|
||||
db::InternDatabaseStorage,
|
||||
db::AstDatabaseStorage,
|
||||
db::DefDatabaseStorage,
|
||||
db::DefDatabase2Storage,
|
||||
db::HirDatabaseStorage
|
||||
)]
|
||||
#[derive(Debug, Default)]
|
||||
|
@ -11,7 +11,7 @@ use ra_arena::{map::ArenaMap, Arena};
|
||||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase2, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId, HasChildSource,
|
||||
db::DefDatabase, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId, HasChildSource,
|
||||
LocalEnumVariantId, LocalStructFieldId, StructOrUnionId, VariantId,
|
||||
};
|
||||
|
||||
@ -49,10 +49,7 @@ pub struct StructFieldData {
|
||||
}
|
||||
|
||||
impl StructData {
|
||||
pub(crate) fn struct_data_query(
|
||||
db: &impl DefDatabase2,
|
||||
id: StructOrUnionId,
|
||||
) -> Arc<StructData> {
|
||||
pub(crate) fn struct_data_query(db: &impl DefDatabase, id: StructOrUnionId) -> Arc<StructData> {
|
||||
let src = id.source(db);
|
||||
let name = src.value.name().map(|n| n.as_name());
|
||||
let variant_data = VariantData::new(src.value.kind());
|
||||
@ -62,7 +59,7 @@ impl StructData {
|
||||
}
|
||||
|
||||
impl EnumData {
|
||||
pub(crate) fn enum_data_query(db: &impl DefDatabase2, e: EnumId) -> Arc<EnumData> {
|
||||
pub(crate) fn enum_data_query(db: &impl DefDatabase, e: EnumId) -> Arc<EnumData> {
|
||||
let src = e.source(db);
|
||||
let name = src.value.name().map(|n| n.as_name());
|
||||
let mut trace = Trace::new_for_arena();
|
||||
@ -79,7 +76,7 @@ impl EnumData {
|
||||
impl HasChildSource for EnumId {
|
||||
type ChildId = LocalEnumVariantId;
|
||||
type Value = ast::EnumVariant;
|
||||
fn child_source(&self, db: &impl DefDatabase2) -> Source<ArenaMap<Self::ChildId, Self::Value>> {
|
||||
fn child_source(&self, db: &impl DefDatabase) -> Source<ArenaMap<Self::ChildId, Self::Value>> {
|
||||
let src = self.source(db);
|
||||
let mut trace = Trace::new_for_map();
|
||||
lower_enum(&mut trace, &src.value);
|
||||
@ -124,7 +121,7 @@ impl HasChildSource for VariantId {
|
||||
type ChildId = LocalStructFieldId;
|
||||
type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>;
|
||||
|
||||
fn child_source(&self, db: &impl DefDatabase2) -> Source<ArenaMap<Self::ChildId, Self::Value>> {
|
||||
fn child_source(&self, db: &impl DefDatabase) -> Source<ArenaMap<Self::ChildId, Self::Value>> {
|
||||
let src = match self {
|
||||
VariantId::EnumVariantId(it) => {
|
||||
// I don't really like the fact that we call into parent source
|
||||
|
@ -12,7 +12,7 @@ use ra_syntax::{
|
||||
use tt::Subtree;
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase2, path::Path, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup,
|
||||
db::DefDatabase, path::Path, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup,
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||
@ -32,7 +32,7 @@ impl ops::Deref for Attrs {
|
||||
}
|
||||
|
||||
impl Attrs {
|
||||
pub(crate) fn attrs_query(db: &impl DefDatabase2, def: AttrDefId) -> Attrs {
|
||||
pub(crate) fn attrs_query(db: &impl DefDatabase, def: AttrDefId) -> Attrs {
|
||||
match def {
|
||||
AttrDefId::ModuleId(module) => {
|
||||
let def_map = db.crate_def_map(module.krate);
|
||||
@ -162,7 +162,7 @@ impl Attr {
|
||||
fn attrs_from_ast<D, N>(src: AstId<N>, db: &D) -> Attrs
|
||||
where
|
||||
N: ast::AttrsOwner,
|
||||
D: DefDatabase2,
|
||||
D: DefDatabase,
|
||||
{
|
||||
let hygiene = Hygiene::new(db, src.file_id());
|
||||
Attr::from_attrs_owner(&src.to_node(db), &hygiene)
|
||||
@ -172,7 +172,7 @@ fn attrs_from_loc<T, D>(node: T, db: &D) -> Attrs
|
||||
where
|
||||
T: HasSource,
|
||||
T::Value: ast::AttrsOwner,
|
||||
D: DefDatabase2,
|
||||
D: DefDatabase,
|
||||
{
|
||||
let src = node.source(db);
|
||||
let hygiene = Hygiene::new(db, src.file_id);
|
||||
|
@ -13,7 +13,7 @@ use ra_syntax::{ast, AstNode, AstPtr};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase2,
|
||||
db::DefDatabase,
|
||||
expr::{Expr, ExprId, Pat, PatId},
|
||||
nameres::CrateDefMap,
|
||||
path::Path,
|
||||
@ -28,7 +28,7 @@ pub struct Expander {
|
||||
}
|
||||
|
||||
impl Expander {
|
||||
pub fn new(db: &impl DefDatabase2, current_file_id: HirFileId, module: ModuleId) -> Expander {
|
||||
pub fn new(db: &impl DefDatabase, current_file_id: HirFileId, module: ModuleId) -> Expander {
|
||||
let crate_def_map = db.crate_def_map(module.krate);
|
||||
let hygiene = Hygiene::new(db, current_file_id);
|
||||
Expander { crate_def_map, current_file_id, hygiene, module }
|
||||
@ -36,7 +36,7 @@ impl Expander {
|
||||
|
||||
fn enter_expand(
|
||||
&mut self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
macro_call: ast::MacroCall,
|
||||
) -> Option<(Mark, ast::Expr)> {
|
||||
let ast_id = AstId::new(
|
||||
@ -67,7 +67,7 @@ impl Expander {
|
||||
None
|
||||
}
|
||||
|
||||
fn exit(&mut self, db: &impl DefDatabase2, mark: Mark) {
|
||||
fn exit(&mut self, db: &impl DefDatabase, mark: Mark) {
|
||||
self.hygiene = Hygiene::new(db, mark.file_id);
|
||||
self.current_file_id = mark.file_id;
|
||||
std::mem::forget(mark);
|
||||
@ -81,7 +81,7 @@ impl Expander {
|
||||
Path::from_src(path, &self.hygiene)
|
||||
}
|
||||
|
||||
fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option<MacroDefId> {
|
||||
fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> {
|
||||
self.crate_def_map.resolve_path(db, self.module.module_id, path).0.get_macros()
|
||||
}
|
||||
}
|
||||
@ -142,7 +142,7 @@ pub struct BodySourceMap {
|
||||
|
||||
impl Body {
|
||||
pub(crate) fn body_with_source_map_query(
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
def: DefWithBodyId,
|
||||
) -> (Arc<Body>, Arc<BodySourceMap>) {
|
||||
let mut params = None;
|
||||
@ -169,12 +169,12 @@ impl Body {
|
||||
(Arc::new(body), Arc::new(source_map))
|
||||
}
|
||||
|
||||
pub(crate) fn body_query(db: &impl DefDatabase2, def: DefWithBodyId) -> Arc<Body> {
|
||||
pub(crate) fn body_query(db: &impl DefDatabase, def: DefWithBodyId) -> Arc<Body> {
|
||||
db.body_with_source_map(def).0
|
||||
}
|
||||
|
||||
fn new(
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
expander: Expander,
|
||||
params: Option<ast::ParamList>,
|
||||
body: Option<ast::Expr>,
|
||||
|
@ -17,7 +17,7 @@ use test_utils::tested_by;
|
||||
use crate::{
|
||||
body::{Body, BodySourceMap, Expander, PatPtr},
|
||||
builtin_type::{BuiltinFloat, BuiltinInt},
|
||||
db::DefDatabase2,
|
||||
db::DefDatabase,
|
||||
expr::{
|
||||
ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp,
|
||||
MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
|
||||
@ -28,7 +28,7 @@ use crate::{
|
||||
};
|
||||
|
||||
pub(super) fn lower(
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
expander: Expander,
|
||||
params: Option<ast::ParamList>,
|
||||
body: Option<ast::Expr>,
|
||||
@ -57,7 +57,7 @@ struct ExprCollector<DB> {
|
||||
|
||||
impl<'a, DB> ExprCollector<&'a DB>
|
||||
where
|
||||
DB: DefDatabase2,
|
||||
DB: DefDatabase,
|
||||
{
|
||||
fn collect(
|
||||
mut self,
|
||||
|
@ -7,7 +7,7 @@ use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::{
|
||||
body::Body,
|
||||
db::DefDatabase2,
|
||||
db::DefDatabase,
|
||||
expr::{Expr, ExprId, Pat, PatId, Statement},
|
||||
DefWithBodyId,
|
||||
};
|
||||
@ -45,7 +45,7 @@ pub struct ScopeData {
|
||||
}
|
||||
|
||||
impl ExprScopes {
|
||||
pub(crate) fn expr_scopes_query(db: &impl DefDatabase2, def: DefWithBodyId) -> Arc<ExprScopes> {
|
||||
pub(crate) fn expr_scopes_query(db: &impl DefDatabase, def: DefWithBodyId) -> Arc<ExprScopes> {
|
||||
let body = db.body(def);
|
||||
Arc::new(ExprScopes::new(&*body))
|
||||
}
|
||||
@ -176,7 +176,7 @@ mod tests {
|
||||
use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
|
||||
use test_utils::{assert_eq_text, covers, extract_offset};
|
||||
|
||||
use crate::{db::DefDatabase2, test_db::TestDB, FunctionId, ModuleDefId};
|
||||
use crate::{db::DefDatabase, test_db::TestDB, FunctionId, ModuleDefId};
|
||||
|
||||
fn find_function(db: &TestDB, file_id: FileId) -> FunctionId {
|
||||
let krate = db.test_crate();
|
||||
|
@ -9,7 +9,7 @@ use hir_expand::{
|
||||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase2,
|
||||
db::DefDatabase,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource,
|
||||
ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
|
||||
@ -26,7 +26,7 @@ pub struct FunctionData {
|
||||
}
|
||||
|
||||
impl FunctionData {
|
||||
pub(crate) fn fn_data_query(db: &impl DefDatabase2, func: FunctionId) -> Arc<FunctionData> {
|
||||
pub(crate) fn fn_data_query(db: &impl DefDatabase, func: FunctionId) -> Arc<FunctionData> {
|
||||
let src = func.lookup(db).source(db);
|
||||
let name = src.value.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
|
||||
let mut params = Vec::new();
|
||||
@ -74,7 +74,7 @@ pub struct TypeAliasData {
|
||||
|
||||
impl TypeAliasData {
|
||||
pub(crate) fn type_alias_data_query(
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
typ: TypeAliasId,
|
||||
) -> Arc<TypeAliasData> {
|
||||
let node = typ.lookup(db).source(db).value;
|
||||
@ -92,7 +92,7 @@ pub struct TraitData {
|
||||
}
|
||||
|
||||
impl TraitData {
|
||||
pub(crate) fn trait_data_query(db: &impl DefDatabase2, tr: TraitId) -> Arc<TraitData> {
|
||||
pub(crate) fn trait_data_query(db: &impl DefDatabase, tr: TraitId) -> Arc<TraitData> {
|
||||
let src = tr.source(db);
|
||||
let name = src.value.name().map(|n| n.as_name());
|
||||
let auto = src.value.is_auto();
|
||||
@ -144,7 +144,7 @@ pub struct ImplData {
|
||||
}
|
||||
|
||||
impl ImplData {
|
||||
pub(crate) fn impl_data_query(db: &impl DefDatabase2, id: ImplId) -> Arc<ImplData> {
|
||||
pub(crate) fn impl_data_query(db: &impl DefDatabase, id: ImplId) -> Arc<ImplData> {
|
||||
let src = id.source(db);
|
||||
let items = db.ast_id_map(src.file_id);
|
||||
|
||||
@ -198,12 +198,12 @@ pub struct ConstData {
|
||||
}
|
||||
|
||||
impl ConstData {
|
||||
pub(crate) fn const_data_query(db: &impl DefDatabase2, konst: ConstId) -> Arc<ConstData> {
|
||||
pub(crate) fn const_data_query(db: &impl DefDatabase, konst: ConstId) -> Arc<ConstData> {
|
||||
let node = konst.lookup(db).source(db).value;
|
||||
const_data_for(&node)
|
||||
}
|
||||
|
||||
pub(crate) fn static_data_query(db: &impl DefDatabase2, konst: StaticId) -> Arc<ConstData> {
|
||||
pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc<ConstData> {
|
||||
let node = konst.source(db).value;
|
||||
const_data_for(&node)
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ use crate::{
|
||||
attr::Attrs,
|
||||
body::{scope::ExprScopes, Body, BodySourceMap},
|
||||
data::{ConstData, FunctionData, ImplData, TraitData, TypeAliasData},
|
||||
docs::Documentation,
|
||||
generics::GenericParams,
|
||||
lang_item::{LangItemTarget, LangItems},
|
||||
nameres::{
|
||||
@ -40,8 +41,8 @@ pub trait InternDatabase: SourceDatabase {
|
||||
fn intern_impl(&self, loc: ItemLoc<ast::ImplBlock>) -> crate::ImplId;
|
||||
}
|
||||
|
||||
#[salsa::query_group(DefDatabase2Storage)]
|
||||
pub trait DefDatabase2: InternDatabase + AstDatabase {
|
||||
#[salsa::query_group(DefDatabaseStorage)]
|
||||
pub trait DefDatabase: InternDatabase + AstDatabase {
|
||||
#[salsa::invoke(RawItems::raw_items_with_source_map_query)]
|
||||
fn raw_items_with_source_map(
|
||||
&self,
|
||||
@ -101,4 +102,9 @@ pub trait DefDatabase2: InternDatabase + AstDatabase {
|
||||
|
||||
#[salsa::invoke(LangItems::lang_item_query)]
|
||||
fn lang_item(&self, start_crate: CrateId, item: SmolStr) -> Option<LangItemTarget>;
|
||||
|
||||
// FIXME(https://github.com/rust-analyzer/rust-analyzer/issues/2148#issuecomment-550519102)
|
||||
// Remove this query completely, in favor of `Attrs::docs` method
|
||||
#[salsa::invoke(Documentation::documentation_query)]
|
||||
fn documentation(&self, def: AttrDefId) -> Option<Documentation>;
|
||||
}
|
||||
|
68
crates/ra_hir_def/src/docs.rs
Normal file
68
crates/ra_hir_def/src/docs.rs
Normal file
@ -0,0 +1,68 @@
|
||||
//! FIXME: write short doc here
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_expand::either::Either;
|
||||
use ra_syntax::ast;
|
||||
|
||||
use crate::{db::DefDatabase, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup};
|
||||
|
||||
/// Holds documentation
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Documentation(Arc<str>);
|
||||
|
||||
impl Into<String> for Documentation {
|
||||
fn into(self) -> String {
|
||||
self.as_str().to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl Documentation {
|
||||
fn new(s: &str) -> Documentation {
|
||||
Documentation(s.into())
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
&*self.0
|
||||
}
|
||||
|
||||
pub(crate) fn documentation_query(
|
||||
db: &impl DefDatabase,
|
||||
def: AttrDefId,
|
||||
) -> Option<Documentation> {
|
||||
match def {
|
||||
AttrDefId::ModuleId(module) => {
|
||||
let def_map = db.crate_def_map(module.krate);
|
||||
let src = def_map[module.module_id].declaration_source(db)?;
|
||||
docs_from_ast(&src.value)
|
||||
}
|
||||
AttrDefId::StructFieldId(it) => {
|
||||
let src = it.parent.child_source(db);
|
||||
match &src.value[it.local_id] {
|
||||
Either::A(_tuple) => None,
|
||||
Either::B(record) => docs_from_ast(record),
|
||||
}
|
||||
}
|
||||
AttrDefId::AdtId(it) => match it {
|
||||
AdtId::StructId(it) => docs_from_ast(&it.0.source(db).value),
|
||||
AdtId::EnumId(it) => docs_from_ast(&it.source(db).value),
|
||||
AdtId::UnionId(it) => docs_from_ast(&it.0.source(db).value),
|
||||
},
|
||||
AttrDefId::EnumVariantId(it) => {
|
||||
let src = it.parent.child_source(db);
|
||||
docs_from_ast(&src.value[it.local_id])
|
||||
}
|
||||
AttrDefId::StaticId(it) => docs_from_ast(&it.source(db).value),
|
||||
AttrDefId::TraitId(it) => docs_from_ast(&it.source(db).value),
|
||||
AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id.to_node(db)),
|
||||
AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
||||
AttrDefId::FunctionId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
||||
AttrDefId::TypeAliasId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
||||
AttrDefId::ImplId(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> {
|
||||
node.doc_comment_text().map(|it| Documentation::new(&it))
|
||||
}
|
@ -8,7 +8,7 @@ use hir_expand::name::{self, AsName, Name};
|
||||
use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner};
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase2,
|
||||
db::DefDatabase,
|
||||
type_ref::{TypeBound, TypeRef},
|
||||
AdtId, AstItemDef, ContainerId, GenericDefId, HasSource, Lookup,
|
||||
};
|
||||
@ -42,7 +42,7 @@ pub struct WherePredicate {
|
||||
|
||||
impl GenericParams {
|
||||
pub(crate) fn generic_params_query(
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
def: GenericDefId,
|
||||
) -> Arc<GenericParams> {
|
||||
let parent_generics = parent_generic_def(db, def).map(|it| db.generic_params(it));
|
||||
@ -50,7 +50,7 @@ impl GenericParams {
|
||||
}
|
||||
|
||||
fn new(
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
def: GenericDefId,
|
||||
parent_params: Option<Arc<GenericParams>>,
|
||||
) -> GenericParams {
|
||||
@ -168,7 +168,7 @@ impl GenericParams {
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_generic_def(db: &impl DefDatabase2, def: GenericDefId) -> Option<GenericDefId> {
|
||||
fn parent_generic_def(db: &impl DefDatabase, def: GenericDefId) -> Option<GenericDefId> {
|
||||
let container = match def {
|
||||
GenericDefId::FunctionId(it) => it.lookup(db).container,
|
||||
GenericDefId::TypeAliasId(it) => it.lookup(db).container,
|
||||
|
@ -8,7 +8,7 @@ use ra_syntax::SmolStr;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase2, AdtId, AttrDefId, CrateId, EnumId, FunctionId, ImplId, ModuleDefId, ModuleId,
|
||||
db::DefDatabase, AdtId, AttrDefId, CrateId, EnumId, FunctionId, ImplId, ModuleDefId, ModuleId,
|
||||
StaticId, StructId, TraitId,
|
||||
};
|
||||
|
||||
@ -33,7 +33,7 @@ impl LangItems {
|
||||
}
|
||||
|
||||
/// Salsa query. This will look for lang items in a specific crate.
|
||||
pub(crate) fn crate_lang_items_query(db: &impl DefDatabase2, krate: CrateId) -> Arc<LangItems> {
|
||||
pub(crate) fn crate_lang_items_query(db: &impl DefDatabase, krate: CrateId) -> Arc<LangItems> {
|
||||
let mut lang_items = LangItems::default();
|
||||
|
||||
let crate_def_map = db.crate_def_map(krate);
|
||||
@ -47,7 +47,7 @@ impl LangItems {
|
||||
}
|
||||
|
||||
pub(crate) fn module_lang_items_query(
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
module: ModuleId,
|
||||
) -> Option<Arc<LangItems>> {
|
||||
let mut lang_items = LangItems::default();
|
||||
@ -62,7 +62,7 @@ impl LangItems {
|
||||
/// Salsa query. Look for a lang item, starting from the specified crate and recursively
|
||||
/// traversing its dependencies.
|
||||
pub(crate) fn lang_item_query(
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
start_crate: CrateId,
|
||||
item: SmolStr,
|
||||
) -> Option<LangItemTarget> {
|
||||
@ -76,7 +76,7 @@ impl LangItems {
|
||||
.find_map(|dep| db.lang_item(dep.crate_id, item.clone()))
|
||||
}
|
||||
|
||||
fn collect_lang_items(&mut self, db: &impl DefDatabase2, module: ModuleId) {
|
||||
fn collect_lang_items(&mut self, db: &impl DefDatabase, module: ModuleId) {
|
||||
// Look for impl targets
|
||||
let def_map = db.crate_def_map(module.krate);
|
||||
let module_data = &def_map[module.module_id];
|
||||
@ -106,7 +106,7 @@ impl LangItems {
|
||||
|
||||
fn collect_lang_item<T>(
|
||||
&mut self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
item: T,
|
||||
constructor: fn(T) -> LangItemTarget,
|
||||
) where
|
||||
|
@ -20,6 +20,7 @@ pub mod generics;
|
||||
pub mod resolver;
|
||||
pub mod data;
|
||||
pub mod lang_item;
|
||||
pub mod docs;
|
||||
|
||||
mod trace;
|
||||
|
||||
@ -47,7 +48,7 @@ pub enum ModuleSource {
|
||||
|
||||
impl ModuleSource {
|
||||
pub fn new(
|
||||
db: &impl db::DefDatabase2,
|
||||
db: &impl db::DefDatabase,
|
||||
file_id: Option<FileId>,
|
||||
decl_id: Option<AstId<ast::Module>>,
|
||||
) -> ModuleSource {
|
||||
@ -66,10 +67,7 @@ impl ModuleSource {
|
||||
}
|
||||
|
||||
// FIXME: this methods do not belong here
|
||||
pub fn from_position(
|
||||
db: &impl db::DefDatabase2,
|
||||
position: ra_db::FilePosition,
|
||||
) -> ModuleSource {
|
||||
pub fn from_position(db: &impl db::DefDatabase, position: ra_db::FilePosition) -> ModuleSource {
|
||||
let parse = db.parse(position.file_id);
|
||||
match &ra_syntax::algo::find_node_at_offset::<ast::Module>(
|
||||
parse.tree().syntax(),
|
||||
@ -83,7 +81,7 @@ impl ModuleSource {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_child_node(db: &impl db::DefDatabase2, child: Source<&SyntaxNode>) -> ModuleSource {
|
||||
pub fn from_child_node(db: &impl db::DefDatabase, child: Source<&SyntaxNode>) -> ModuleSource {
|
||||
if let Some(m) =
|
||||
child.value.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi())
|
||||
{
|
||||
@ -95,7 +93,7 @@ impl ModuleSource {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_file_id(db: &impl db::DefDatabase2, file_id: FileId) -> ModuleSource {
|
||||
pub fn from_file_id(db: &impl db::DefDatabase, file_id: FileId) -> ModuleSource {
|
||||
let source_file = db.parse(file_id).tree();
|
||||
ModuleSource::SourceFile(source_file)
|
||||
}
|
||||
@ -210,14 +208,14 @@ pub struct FunctionLoc {
|
||||
|
||||
impl Intern for FunctionLoc {
|
||||
type ID = FunctionId;
|
||||
fn intern(self, db: &impl db::DefDatabase2) -> FunctionId {
|
||||
fn intern(self, db: &impl db::DefDatabase) -> FunctionId {
|
||||
db.intern_function(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Lookup for FunctionId {
|
||||
type Data = FunctionLoc;
|
||||
fn lookup(&self, db: &impl db::DefDatabase2) -> FunctionLoc {
|
||||
fn lookup(&self, db: &impl db::DefDatabase) -> FunctionLoc {
|
||||
db.lookup_intern_function(*self)
|
||||
}
|
||||
}
|
||||
@ -300,14 +298,14 @@ pub struct ConstLoc {
|
||||
|
||||
impl Intern for ConstLoc {
|
||||
type ID = ConstId;
|
||||
fn intern(self, db: &impl db::DefDatabase2) -> ConstId {
|
||||
fn intern(self, db: &impl db::DefDatabase) -> ConstId {
|
||||
db.intern_const(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Lookup for ConstId {
|
||||
type Data = ConstLoc;
|
||||
fn lookup(&self, db: &impl db::DefDatabase2) -> ConstLoc {
|
||||
fn lookup(&self, db: &impl db::DefDatabase) -> ConstLoc {
|
||||
db.lookup_intern_const(*self)
|
||||
}
|
||||
}
|
||||
@ -348,14 +346,14 @@ pub struct TypeAliasLoc {
|
||||
|
||||
impl Intern for TypeAliasLoc {
|
||||
type ID = TypeAliasId;
|
||||
fn intern(self, db: &impl db::DefDatabase2) -> TypeAliasId {
|
||||
fn intern(self, db: &impl db::DefDatabase) -> TypeAliasId {
|
||||
db.intern_type_alias(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Lookup for TypeAliasId {
|
||||
type Data = TypeAliasLoc;
|
||||
fn lookup(&self, db: &impl db::DefDatabase2) -> TypeAliasLoc {
|
||||
fn lookup(&self, db: &impl db::DefDatabase) -> TypeAliasLoc {
|
||||
db.lookup_intern_type_alias(*self)
|
||||
}
|
||||
}
|
||||
@ -509,20 +507,20 @@ impl_froms!(
|
||||
|
||||
trait Intern {
|
||||
type ID;
|
||||
fn intern(self, db: &impl db::DefDatabase2) -> Self::ID;
|
||||
fn intern(self, db: &impl db::DefDatabase) -> Self::ID;
|
||||
}
|
||||
|
||||
pub trait Lookup {
|
||||
type Data;
|
||||
fn lookup(&self, db: &impl db::DefDatabase2) -> Self::Data;
|
||||
fn lookup(&self, db: &impl db::DefDatabase) -> Self::Data;
|
||||
}
|
||||
|
||||
pub trait HasModule {
|
||||
fn module(&self, db: &impl db::DefDatabase2) -> ModuleId;
|
||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId;
|
||||
}
|
||||
|
||||
impl HasModule for FunctionLoc {
|
||||
fn module(&self, db: &impl db::DefDatabase2) -> ModuleId {
|
||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||
match self.container {
|
||||
ContainerId::ModuleId(it) => it,
|
||||
ContainerId::ImplId(it) => it.module(db),
|
||||
@ -532,7 +530,7 @@ impl HasModule for FunctionLoc {
|
||||
}
|
||||
|
||||
impl HasModule for TypeAliasLoc {
|
||||
fn module(&self, db: &impl db::DefDatabase2) -> ModuleId {
|
||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||
match self.container {
|
||||
ContainerId::ModuleId(it) => it,
|
||||
ContainerId::ImplId(it) => it.module(db),
|
||||
@ -542,7 +540,7 @@ impl HasModule for TypeAliasLoc {
|
||||
}
|
||||
|
||||
impl HasModule for ConstLoc {
|
||||
fn module(&self, db: &impl db::DefDatabase2) -> ModuleId {
|
||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||
match self.container {
|
||||
ContainerId::ModuleId(it) => it,
|
||||
ContainerId::ImplId(it) => it.module(db),
|
||||
@ -553,13 +551,13 @@ impl HasModule for ConstLoc {
|
||||
|
||||
pub trait HasSource {
|
||||
type Value;
|
||||
fn source(&self, db: &impl db::DefDatabase2) -> Source<Self::Value>;
|
||||
fn source(&self, db: &impl db::DefDatabase) -> Source<Self::Value>;
|
||||
}
|
||||
|
||||
impl HasSource for FunctionLoc {
|
||||
type Value = ast::FnDef;
|
||||
|
||||
fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::FnDef> {
|
||||
fn source(&self, db: &impl db::DefDatabase) -> Source<ast::FnDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
Source::new(self.ast_id.file_id(), node)
|
||||
}
|
||||
@ -568,7 +566,7 @@ impl HasSource for FunctionLoc {
|
||||
impl HasSource for TypeAliasLoc {
|
||||
type Value = ast::TypeAliasDef;
|
||||
|
||||
fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::TypeAliasDef> {
|
||||
fn source(&self, db: &impl db::DefDatabase) -> Source<ast::TypeAliasDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
Source::new(self.ast_id.file_id(), node)
|
||||
}
|
||||
@ -577,7 +575,7 @@ impl HasSource for TypeAliasLoc {
|
||||
impl HasSource for ConstLoc {
|
||||
type Value = ast::ConstDef;
|
||||
|
||||
fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::ConstDef> {
|
||||
fn source(&self, db: &impl db::DefDatabase) -> Source<ast::ConstDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
Source::new(self.ast_id.file_id(), node)
|
||||
}
|
||||
@ -588,6 +586,6 @@ pub trait HasChildSource {
|
||||
type Value;
|
||||
fn child_source(
|
||||
&self,
|
||||
db: &impl db::DefDatabase2,
|
||||
db: &impl db::DefDatabase,
|
||||
) -> Source<ArenaMap<Self::ChildId, Self::Value>>;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
use crate::{
|
||||
builtin_type::BuiltinType,
|
||||
db::DefDatabase2,
|
||||
db::DefDatabase,
|
||||
nameres::{
|
||||
diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs, raw::ImportId,
|
||||
},
|
||||
@ -220,7 +220,7 @@ impl CrateDefMap {
|
||||
pub(crate) fn crate_def_map_query(
|
||||
// Note that this doesn't have `+ AstDatabase`!
|
||||
// This gurantess that `CrateDefMap` is stable across reparses.
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
krate: CrateId,
|
||||
) -> Arc<CrateDefMap> {
|
||||
let _p = profile("crate_def_map_query");
|
||||
@ -262,7 +262,7 @@ impl CrateDefMap {
|
||||
|
||||
pub fn add_diagnostics(
|
||||
&self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
module: CrateModuleId,
|
||||
sink: &mut DiagnosticSink,
|
||||
) {
|
||||
@ -271,7 +271,7 @@ impl CrateDefMap {
|
||||
|
||||
pub fn resolve_path(
|
||||
&self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
original_module: CrateModuleId,
|
||||
path: &Path,
|
||||
) -> (PerNs, Option<usize>) {
|
||||
@ -295,7 +295,7 @@ impl ModuleData {
|
||||
/// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
|
||||
pub fn definition_source(
|
||||
&self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
) -> Source<Either<ast::SourceFile, ast::Module>> {
|
||||
if let Some(file_id) = self.definition {
|
||||
let sf = db.parse(file_id).tree();
|
||||
@ -307,7 +307,7 @@ impl ModuleData {
|
||||
|
||||
/// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
|
||||
/// `None` for the crate root.
|
||||
pub fn declaration_source(&self, db: &impl DefDatabase2) -> Option<Source<ast::Module>> {
|
||||
pub fn declaration_source(&self, db: &impl DefDatabase) -> Option<Source<ast::Module>> {
|
||||
let decl = self.declaration?;
|
||||
let value = decl.to_node(db);
|
||||
Some(Source { file_id: decl.file_id(), value })
|
||||
@ -319,7 +319,7 @@ mod diagnostics {
|
||||
use ra_db::RelativePathBuf;
|
||||
use ra_syntax::{ast, AstPtr};
|
||||
|
||||
use crate::{db::DefDatabase2, diagnostics::UnresolvedModule, nameres::CrateModuleId, AstId};
|
||||
use crate::{db::DefDatabase, diagnostics::UnresolvedModule, nameres::CrateModuleId, AstId};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub(super) enum DefDiagnostic {
|
||||
@ -333,7 +333,7 @@ mod diagnostics {
|
||||
impl DefDiagnostic {
|
||||
pub(super) fn add_to(
|
||||
&self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
target_module: CrateModuleId,
|
||||
sink: &mut DiagnosticSink,
|
||||
) {
|
||||
|
@ -13,7 +13,7 @@ use test_utils::tested_by;
|
||||
|
||||
use crate::{
|
||||
attr::Attrs,
|
||||
db::DefDatabase2,
|
||||
db::DefDatabase,
|
||||
nameres::{
|
||||
diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
|
||||
per_ns::PerNs, raw, CrateDefMap, ModuleData, Resolution, ResolveMode,
|
||||
@ -24,7 +24,7 @@ use crate::{
|
||||
StructOrUnionId, TraitId, TypeAliasLoc, UnionId,
|
||||
};
|
||||
|
||||
pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> CrateDefMap {
|
||||
pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
|
||||
let crate_graph = db.crate_graph();
|
||||
|
||||
// populate external prelude
|
||||
@ -108,7 +108,7 @@ struct DefCollector<'a, DB> {
|
||||
|
||||
impl<DB> DefCollector<'_, DB>
|
||||
where
|
||||
DB: DefDatabase2,
|
||||
DB: DefDatabase,
|
||||
{
|
||||
fn collect(&mut self) {
|
||||
let crate_graph = self.db.crate_graph();
|
||||
@ -530,7 +530,7 @@ struct ModCollector<'a, D> {
|
||||
|
||||
impl<DB> ModCollector<'_, &'_ mut DefCollector<'_, DB>>
|
||||
where
|
||||
DB: DefDatabase2,
|
||||
DB: DefDatabase,
|
||||
{
|
||||
fn collect(&mut self, items: &[raw::RawItem]) {
|
||||
// Note: don't assert that inserted value is fresh: it's simply not true
|
||||
@ -798,12 +798,12 @@ mod tests {
|
||||
use ra_db::{fixture::WithFixture, SourceDatabase};
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
use crate::{db::DefDatabase2, test_db::TestDB};
|
||||
use crate::{db::DefDatabase, test_db::TestDB};
|
||||
|
||||
use super::*;
|
||||
|
||||
fn do_collect_defs(
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
def_map: CrateDefMap,
|
||||
monitor: MacroStackMonitor,
|
||||
) -> CrateDefMap {
|
||||
|
@ -3,7 +3,7 @@ use hir_expand::name::Name;
|
||||
use ra_db::{FileId, RelativePathBuf};
|
||||
use ra_syntax::SmolStr;
|
||||
|
||||
use crate::{db::DefDatabase2, HirFileId};
|
||||
use crate::{db::DefDatabase, HirFileId};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(super) struct ModDir {
|
||||
@ -40,7 +40,7 @@ impl ModDir {
|
||||
|
||||
pub(super) fn resolve_declaration(
|
||||
&self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
file_id: HirFileId,
|
||||
name: &Name,
|
||||
attr_path: Option<&SmolStr>,
|
||||
|
@ -15,7 +15,7 @@ use ra_db::Edition;
|
||||
use test_utils::tested_by;
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase2,
|
||||
db::DefDatabase,
|
||||
nameres::{per_ns::PerNs, CrateDefMap},
|
||||
path::{Path, PathKind},
|
||||
AdtId, CrateModuleId, EnumVariantId, ModuleDefId, ModuleId,
|
||||
@ -63,7 +63,7 @@ impl CrateDefMap {
|
||||
// the result.
|
||||
pub(super) fn resolve_path_fp_with_macro(
|
||||
&self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
mode: ResolveMode,
|
||||
original_module: CrateModuleId,
|
||||
path: &Path,
|
||||
@ -216,7 +216,7 @@ impl CrateDefMap {
|
||||
|
||||
fn resolve_name_in_module(
|
||||
&self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
module: CrateModuleId,
|
||||
name: &Name,
|
||||
) -> PerNs {
|
||||
@ -243,7 +243,7 @@ impl CrateDefMap {
|
||||
from_crate_root.or(from_extern_prelude)
|
||||
}
|
||||
|
||||
fn resolve_in_prelude(&self, db: &impl DefDatabase2, name: &Name) -> PerNs {
|
||||
fn resolve_in_prelude(&self, db: &impl DefDatabase, name: &Name) -> PerNs {
|
||||
if let Some(prelude) = self.prelude {
|
||||
let keep;
|
||||
let def_map = if prelude.krate == self.krate {
|
||||
|
@ -18,7 +18,7 @@ use test_utils::tested_by;
|
||||
|
||||
use crate::{
|
||||
attr::{Attr, Attrs},
|
||||
db::DefDatabase2,
|
||||
db::DefDatabase,
|
||||
path::Path,
|
||||
FileAstId, HirFileId, ModuleSource, Source,
|
||||
};
|
||||
@ -67,14 +67,14 @@ impl ImportSourceMap {
|
||||
|
||||
impl RawItems {
|
||||
pub(crate) fn raw_items_query(
|
||||
db: &(impl DefDatabase2 + AstDatabase),
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
file_id: HirFileId,
|
||||
) -> Arc<RawItems> {
|
||||
db.raw_items_with_source_map(file_id).0
|
||||
}
|
||||
|
||||
pub(crate) fn raw_items_with_source_map_query(
|
||||
db: &(impl DefDatabase2 + AstDatabase),
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
file_id: HirFileId,
|
||||
) -> (Arc<RawItems>, Arc<ImportSourceMap>) {
|
||||
let mut collector = RawItemsCollector {
|
||||
|
@ -10,7 +10,7 @@ use insta::assert_snapshot;
|
||||
use ra_db::{fixture::WithFixture, SourceDatabase};
|
||||
use test_utils::covers;
|
||||
|
||||
use crate::{db::DefDatabase2, nameres::*, test_db::TestDB, CrateModuleId};
|
||||
use crate::{db::DefDatabase, nameres::*, test_db::TestDB, CrateModuleId};
|
||||
|
||||
fn def_map(fixtute: &str) -> String {
|
||||
let dm = compute_crate_def_map(fixtute);
|
||||
|
@ -11,7 +11,7 @@ use rustc_hash::FxHashSet;
|
||||
use crate::{
|
||||
body::scope::{ExprScopes, ScopeId},
|
||||
builtin_type::BuiltinType,
|
||||
db::DefDatabase2,
|
||||
db::DefDatabase,
|
||||
expr::{ExprId, PatId},
|
||||
generics::GenericParams,
|
||||
nameres::{per_ns::PerNs, CrateDefMap},
|
||||
@ -87,7 +87,7 @@ pub enum ValueNs {
|
||||
|
||||
impl Resolver {
|
||||
/// Resolve known trait from std, like `std::futures::Future`
|
||||
pub fn resolve_known_trait(&self, db: &impl DefDatabase2, path: &Path) -> Option<TraitId> {
|
||||
pub fn resolve_known_trait(&self, db: &impl DefDatabase, path: &Path) -> Option<TraitId> {
|
||||
let res = self.resolve_module_path(db, path).take_types()?;
|
||||
match res {
|
||||
ModuleDefId::TraitId(it) => Some(it),
|
||||
@ -96,7 +96,7 @@ impl Resolver {
|
||||
}
|
||||
|
||||
/// Resolve known struct from std, like `std::boxed::Box`
|
||||
pub fn resolve_known_struct(&self, db: &impl DefDatabase2, path: &Path) -> Option<StructId> {
|
||||
pub fn resolve_known_struct(&self, db: &impl DefDatabase, path: &Path) -> Option<StructId> {
|
||||
let res = self.resolve_module_path(db, path).take_types()?;
|
||||
match res {
|
||||
ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it),
|
||||
@ -105,7 +105,7 @@ impl Resolver {
|
||||
}
|
||||
|
||||
/// Resolve known enum from std, like `std::result::Result`
|
||||
pub fn resolve_known_enum(&self, db: &impl DefDatabase2, path: &Path) -> Option<EnumId> {
|
||||
pub fn resolve_known_enum(&self, db: &impl DefDatabase, path: &Path) -> Option<EnumId> {
|
||||
let res = self.resolve_module_path(db, path).take_types()?;
|
||||
match res {
|
||||
ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it),
|
||||
@ -114,7 +114,7 @@ impl Resolver {
|
||||
}
|
||||
|
||||
/// pub only for source-binder
|
||||
pub fn resolve_module_path(&self, db: &impl DefDatabase2, path: &Path) -> PerNs {
|
||||
pub fn resolve_module_path(&self, db: &impl DefDatabase, path: &Path) -> PerNs {
|
||||
let (item_map, module) = match self.module() {
|
||||
Some(it) => it,
|
||||
None => return PerNs::none(),
|
||||
@ -128,7 +128,7 @@ impl Resolver {
|
||||
|
||||
pub fn resolve_path_in_type_ns(
|
||||
&self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
path: &Path,
|
||||
) -> Option<(TypeNs, Option<usize>)> {
|
||||
if path.is_type_relative() {
|
||||
@ -184,7 +184,7 @@ impl Resolver {
|
||||
|
||||
pub fn resolve_path_in_type_ns_fully(
|
||||
&self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
path: &Path,
|
||||
) -> Option<TypeNs> {
|
||||
let (res, unresolved) = self.resolve_path_in_type_ns(db, path)?;
|
||||
@ -196,7 +196,7 @@ impl Resolver {
|
||||
|
||||
pub fn resolve_path_in_value_ns<'p>(
|
||||
&self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
path: &'p Path,
|
||||
) -> Option<ResolveValueResult> {
|
||||
if path.is_type_relative() {
|
||||
@ -296,7 +296,7 @@ impl Resolver {
|
||||
|
||||
pub fn resolve_path_in_value_ns_fully(
|
||||
&self,
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
path: &Path,
|
||||
) -> Option<ValueNs> {
|
||||
match self.resolve_path_in_value_ns(db, path)? {
|
||||
@ -305,18 +305,18 @@ impl Resolver {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option<MacroDefId> {
|
||||
pub fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> {
|
||||
let (item_map, module) = self.module()?;
|
||||
item_map.resolve_path(db, module, path).0.get_macros()
|
||||
}
|
||||
|
||||
pub fn process_all_names(&self, db: &impl DefDatabase2, f: &mut dyn FnMut(Name, ScopeDef)) {
|
||||
pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) {
|
||||
for scope in self.scopes.iter().rev() {
|
||||
scope.process_names(db, f);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn traits_in_scope(&self, db: &impl DefDatabase2) -> FxHashSet<TraitId> {
|
||||
pub fn traits_in_scope(&self, db: &impl DefDatabase) -> FxHashSet<TraitId> {
|
||||
let mut traits = FxHashSet::default();
|
||||
for scope in &self.scopes {
|
||||
if let Scope::ModuleScope(m) = scope {
|
||||
@ -378,7 +378,7 @@ pub enum ScopeDef {
|
||||
}
|
||||
|
||||
impl Scope {
|
||||
fn process_names(&self, db: &impl DefDatabase2, f: &mut dyn FnMut(Name, ScopeDef)) {
|
||||
fn process_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) {
|
||||
match self {
|
||||
Scope::ModuleScope(m) => {
|
||||
// FIXME: should we provide `self` here?
|
||||
@ -425,17 +425,13 @@ impl Scope {
|
||||
}
|
||||
|
||||
// needs arbitrary_self_types to be a method... or maybe move to the def?
|
||||
pub fn resolver_for_expr(
|
||||
db: &impl DefDatabase2,
|
||||
owner: DefWithBodyId,
|
||||
expr_id: ExprId,
|
||||
) -> Resolver {
|
||||
pub fn resolver_for_expr(db: &impl DefDatabase, owner: DefWithBodyId, expr_id: ExprId) -> Resolver {
|
||||
let scopes = db.expr_scopes(owner);
|
||||
resolver_for_scope(db, owner, scopes.scope_for(expr_id))
|
||||
}
|
||||
|
||||
pub fn resolver_for_scope(
|
||||
db: &impl DefDatabase2,
|
||||
db: &impl DefDatabase,
|
||||
owner: DefWithBodyId,
|
||||
scope_id: Option<ScopeId>,
|
||||
) -> Resolver {
|
||||
@ -454,7 +450,7 @@ impl Resolver {
|
||||
self
|
||||
}
|
||||
|
||||
fn push_generic_params_scope(self, db: &impl DefDatabase2, def: GenericDefId) -> Resolver {
|
||||
fn push_generic_params_scope(self, db: &impl DefDatabase, def: GenericDefId) -> Resolver {
|
||||
let params = db.generic_params(def);
|
||||
if params.params.is_empty() {
|
||||
self
|
||||
@ -487,24 +483,24 @@ impl Resolver {
|
||||
|
||||
pub trait HasResolver {
|
||||
/// Builds a resolver for type references inside this def.
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver;
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver;
|
||||
}
|
||||
|
||||
impl HasResolver for ModuleId {
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
let def_map = db.crate_def_map(self.krate);
|
||||
Resolver::default().push_module_scope(def_map, self.module_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasResolver for TraitId {
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
self.module(db).resolver(db).push_generic_params_scope(db, self.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<AdtId>> HasResolver for T {
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
let def = self.into();
|
||||
let module = match def {
|
||||
AdtId::StructId(it) => it.0.module(db),
|
||||
@ -520,13 +516,13 @@ impl<T: Into<AdtId>> HasResolver for T {
|
||||
}
|
||||
|
||||
impl HasResolver for FunctionId {
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl HasResolver for DefWithBodyId {
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
match self {
|
||||
DefWithBodyId::ConstId(c) => c.resolver(db),
|
||||
DefWithBodyId::FunctionId(f) => f.resolver(db),
|
||||
@ -536,25 +532,25 @@ impl HasResolver for DefWithBodyId {
|
||||
}
|
||||
|
||||
impl HasResolver for ConstId {
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
self.lookup(db).container.resolver(db)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasResolver for StaticId {
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
self.module(db).resolver(db)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasResolver for TypeAliasId {
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl HasResolver for ContainerId {
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
match self {
|
||||
ContainerId::TraitId(it) => it.resolver(db),
|
||||
ContainerId::ImplId(it) => it.resolver(db),
|
||||
@ -564,7 +560,7 @@ impl HasResolver for ContainerId {
|
||||
}
|
||||
|
||||
impl HasResolver for GenericDefId {
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
match self {
|
||||
GenericDefId::FunctionId(inner) => inner.resolver(db),
|
||||
GenericDefId::AdtId(adt) => adt.resolver(db),
|
||||
@ -578,7 +574,7 @@ impl HasResolver for GenericDefId {
|
||||
}
|
||||
|
||||
impl HasResolver for ImplId {
|
||||
fn resolver(self, db: &impl DefDatabase2) -> Resolver {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
self.module(db)
|
||||
.resolver(db)
|
||||
.push_generic_params_scope(db, self.into())
|
||||
|
@ -12,7 +12,7 @@ use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath
|
||||
ra_db::SourceDatabaseStorage,
|
||||
hir_expand::db::AstDatabaseStorage,
|
||||
crate::db::InternDatabaseStorage,
|
||||
crate::db::DefDatabase2Storage
|
||||
crate::db::DefDatabaseStorage
|
||||
)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct TestDB {
|
||||
|
@ -22,7 +22,6 @@ use crate::{
|
||||
hir::db::InternDatabaseStorage,
|
||||
hir::db::AstDatabaseStorage,
|
||||
hir::db::DefDatabaseStorage,
|
||||
hir::db::DefDatabase2Storage,
|
||||
hir::db::HirDatabaseStorage
|
||||
)]
|
||||
#[derive(Debug)]
|
||||
|
Loading…
Reference in New Issue
Block a user