mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 01:38:13 +00:00
use Source more
This commit is contained in:
parent
91c120ccea
commit
2a1fe26b6d
7 changed files with 39 additions and 64 deletions
|
@ -11,7 +11,7 @@ use ra_syntax::{
|
|||
|
||||
use crate::{
|
||||
Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase,
|
||||
HirDatabase, HirFileId, StructField, FieldSource,
|
||||
HirDatabase, HirFileId, StructField, FieldSource, Source,
|
||||
type_ref::TypeRef, DefDatabase,
|
||||
};
|
||||
|
||||
|
@ -72,15 +72,15 @@ impl EnumVariant {
|
|||
pub(crate) fn source_impl(
|
||||
&self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::EnumVariant>) {
|
||||
let (file_id, enum_def) = self.parent.source(db);
|
||||
let var = variants(&*enum_def)
|
||||
) -> Source<TreeArc<ast::EnumVariant>> {
|
||||
let src = self.parent.source(db);
|
||||
let ast = variants(&*src.ast)
|
||||
.zip(db.enum_data(self.parent).variants.iter())
|
||||
.find(|(_syntax, (id, _))| *id == self.id)
|
||||
.unwrap()
|
||||
.0
|
||||
.to_owned();
|
||||
(file_id, var)
|
||||
Source { file_id: src.file_id, ast }
|
||||
}
|
||||
pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> {
|
||||
db.enum_data(self.parent).variants[self.id].variant_data.clone()
|
||||
|
@ -95,9 +95,9 @@ pub struct EnumData {
|
|||
|
||||
impl EnumData {
|
||||
pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> {
|
||||
let (_file_id, enum_def) = e.source(db);
|
||||
let name = enum_def.name().map(|n| n.as_name());
|
||||
let variants = variants(&*enum_def)
|
||||
let src = e.source(db);
|
||||
let name = src.ast.name().map(|n| n.as_name());
|
||||
let variants = variants(&*src.ast)
|
||||
.map(|var| EnumVariantData {
|
||||
name: var.name().map(|it| it.as_name()),
|
||||
variant_data: Arc::new(VariantData::new(var.kind())),
|
||||
|
@ -215,9 +215,8 @@ impl StructField {
|
|||
(ss.file_id, ss.ast.kind())
|
||||
}
|
||||
VariantDef::EnumVariant(e) => {
|
||||
let (file_id, source) = e.source(db);
|
||||
es = source;
|
||||
(file_id, es.kind())
|
||||
es = e.source(db);
|
||||
(es.file_id, es.ast.kind())
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -456,11 +456,8 @@ pub struct Enum {
|
|||
}
|
||||
|
||||
impl Enum {
|
||||
pub fn source(
|
||||
self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::EnumDef>) {
|
||||
self.id.source(db)
|
||||
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
|
||||
self.id.source(db).into()
|
||||
}
|
||||
|
||||
pub fn module(self, db: &impl HirDatabase) -> Module {
|
||||
|
@ -509,7 +506,7 @@ impl EnumVariant {
|
|||
pub fn source(
|
||||
&self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::EnumVariant>) {
|
||||
) -> Source<TreeArc<ast::EnumVariant>> {
|
||||
self.source_impl(db)
|
||||
}
|
||||
pub fn module(&self, db: &impl HirDatabase) -> Module {
|
||||
|
|
|
@ -77,8 +77,8 @@ pub(crate) fn documentation_query(
|
|||
FieldSource::Pos(..) => return None,
|
||||
},
|
||||
DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast),
|
||||
DocDef::Enum(it) => docs_from_ast(&*it.source(db).1),
|
||||
DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).1),
|
||||
DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast),
|
||||
DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast),
|
||||
DocDef::Static(it) => docs_from_ast(&*it.source(db).1),
|
||||
DocDef::Const(it) => docs_from_ast(&*it.source(db).1),
|
||||
DocDef::Function(it) => docs_from_ast(&*it.source(db).1),
|
||||
|
|
|
@ -71,7 +71,7 @@ impl GenericParams {
|
|||
GenericDef::Function(it) => generics.fill(&*it.source(db).1, start),
|
||||
GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start),
|
||||
GenericDef::Union(it) => generics.fill(&*it.source(db).1, start),
|
||||
GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start),
|
||||
GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start),
|
||||
GenericDef::Trait(it) => {
|
||||
// traits get the Self type as an implicit first type parameter
|
||||
generics.params.push(GenericParam {
|
||||
|
|
|
@ -81,5 +81,5 @@ pub use self::code_model::{
|
|||
StructField, FieldSource,
|
||||
Static, Const, ConstSignature,
|
||||
Trait, TypeAlias, MacroDef, Container,
|
||||
BuiltinType,
|
||||
BuiltinType, Source,
|
||||
};
|
||||
|
|
|
@ -207,12 +207,12 @@ impl NavigationTarget {
|
|||
)
|
||||
}
|
||||
hir::AdtDef::Enum(s) => {
|
||||
let (file_id, node) = s.source(db);
|
||||
let src = s.source(db);
|
||||
NavigationTarget::from_named(
|
||||
file_id.original_file(db),
|
||||
&*node,
|
||||
node.doc_comment_text(),
|
||||
node.short_label(),
|
||||
src.file_id.original_file(db),
|
||||
&*src.ast,
|
||||
src.ast.doc_comment_text(),
|
||||
src.ast.short_label(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -225,24 +225,9 @@ impl NavigationTarget {
|
|||
let nav = match module_def {
|
||||
hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module),
|
||||
hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func),
|
||||
hir::ModuleDef::Struct(s) => {
|
||||
let src = s.source(db);
|
||||
NavigationTarget::from_named(
|
||||
src.file_id.original_file(db),
|
||||
&*src.ast,
|
||||
src.ast.doc_comment_text(),
|
||||
src.ast.short_label(),
|
||||
)
|
||||
}
|
||||
hir::ModuleDef::Union(s) => {
|
||||
let (file_id, node) = s.source(db);
|
||||
NavigationTarget::from_named(
|
||||
file_id.original_file(db),
|
||||
&*node,
|
||||
node.doc_comment_text(),
|
||||
node.short_label(),
|
||||
)
|
||||
}
|
||||
hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()),
|
||||
hir::ModuleDef::Enum(it) => NavigationTarget::from_adt_def(db, it.into()),
|
||||
hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()),
|
||||
hir::ModuleDef::Const(s) => {
|
||||
let (file_id, node) = s.source(db);
|
||||
NavigationTarget::from_named(
|
||||
|
@ -261,22 +246,13 @@ impl NavigationTarget {
|
|||
node.short_label(),
|
||||
)
|
||||
}
|
||||
hir::ModuleDef::Enum(e) => {
|
||||
let (file_id, node) = e.source(db);
|
||||
NavigationTarget::from_named(
|
||||
file_id.original_file(db),
|
||||
&*node,
|
||||
node.doc_comment_text(),
|
||||
node.short_label(),
|
||||
)
|
||||
}
|
||||
hir::ModuleDef::EnumVariant(var) => {
|
||||
let (file_id, node) = var.source(db);
|
||||
let src = var.source(db);
|
||||
NavigationTarget::from_named(
|
||||
file_id.original_file(db),
|
||||
&*node,
|
||||
node.doc_comment_text(),
|
||||
node.short_label(),
|
||||
src.file_id.original_file(db),
|
||||
&*src.ast,
|
||||
src.ast.doc_comment_text(),
|
||||
src.ast.short_label(),
|
||||
)
|
||||
}
|
||||
hir::ModuleDef::Trait(e) => {
|
||||
|
|
|
@ -144,12 +144,12 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
||||
}
|
||||
hir::ModuleDef::Enum(it) => {
|
||||
let it = it.source(db).1;
|
||||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
||||
let src = it.source(db);
|
||||
res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
|
||||
}
|
||||
hir::ModuleDef::EnumVariant(it) => {
|
||||
let it = it.source(db).1;
|
||||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
||||
let src = it.source(db);
|
||||
res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
|
||||
}
|
||||
hir::ModuleDef::Const(it) => {
|
||||
let it = it.source(db).1;
|
||||
|
@ -187,8 +187,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
||||
}
|
||||
hir::AdtDef::Enum(it) => {
|
||||
let it = it.source(db).1;
|
||||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
||||
let src = it.source(db);
|
||||
res.extend(hover_text(
|
||||
src.ast.doc_comment_text(),
|
||||
src.ast.short_label(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue