mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +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::{
|
use crate::{
|
||||||
Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase,
|
Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase,
|
||||||
HirDatabase, HirFileId, StructField, FieldSource,
|
HirDatabase, HirFileId, StructField, FieldSource, Source,
|
||||||
type_ref::TypeRef, DefDatabase,
|
type_ref::TypeRef, DefDatabase,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -72,15 +72,15 @@ impl EnumVariant {
|
||||||
pub(crate) fn source_impl(
|
pub(crate) fn source_impl(
|
||||||
&self,
|
&self,
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
db: &(impl DefDatabase + AstDatabase),
|
||||||
) -> (HirFileId, TreeArc<ast::EnumVariant>) {
|
) -> Source<TreeArc<ast::EnumVariant>> {
|
||||||
let (file_id, enum_def) = self.parent.source(db);
|
let src = self.parent.source(db);
|
||||||
let var = variants(&*enum_def)
|
let ast = variants(&*src.ast)
|
||||||
.zip(db.enum_data(self.parent).variants.iter())
|
.zip(db.enum_data(self.parent).variants.iter())
|
||||||
.find(|(_syntax, (id, _))| *id == self.id)
|
.find(|(_syntax, (id, _))| *id == self.id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.to_owned();
|
.to_owned();
|
||||||
(file_id, var)
|
Source { file_id: src.file_id, ast }
|
||||||
}
|
}
|
||||||
pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> {
|
pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> {
|
||||||
db.enum_data(self.parent).variants[self.id].variant_data.clone()
|
db.enum_data(self.parent).variants[self.id].variant_data.clone()
|
||||||
|
@ -95,9 +95,9 @@ pub struct EnumData {
|
||||||
|
|
||||||
impl EnumData {
|
impl EnumData {
|
||||||
pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> {
|
pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> {
|
||||||
let (_file_id, enum_def) = e.source(db);
|
let src = e.source(db);
|
||||||
let name = enum_def.name().map(|n| n.as_name());
|
let name = src.ast.name().map(|n| n.as_name());
|
||||||
let variants = variants(&*enum_def)
|
let variants = variants(&*src.ast)
|
||||||
.map(|var| EnumVariantData {
|
.map(|var| EnumVariantData {
|
||||||
name: var.name().map(|it| it.as_name()),
|
name: var.name().map(|it| it.as_name()),
|
||||||
variant_data: Arc::new(VariantData::new(var.kind())),
|
variant_data: Arc::new(VariantData::new(var.kind())),
|
||||||
|
@ -215,9 +215,8 @@ impl StructField {
|
||||||
(ss.file_id, ss.ast.kind())
|
(ss.file_id, ss.ast.kind())
|
||||||
}
|
}
|
||||||
VariantDef::EnumVariant(e) => {
|
VariantDef::EnumVariant(e) => {
|
||||||
let (file_id, source) = e.source(db);
|
es = e.source(db);
|
||||||
es = source;
|
(es.file_id, es.ast.kind())
|
||||||
(file_id, es.kind())
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -456,11 +456,8 @@ pub struct Enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Enum {
|
impl Enum {
|
||||||
pub fn source(
|
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
|
||||||
self,
|
self.id.source(db).into()
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
|
||||||
) -> (HirFileId, TreeArc<ast::EnumDef>) {
|
|
||||||
self.id.source(db)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module(self, db: &impl HirDatabase) -> Module {
|
pub fn module(self, db: &impl HirDatabase) -> Module {
|
||||||
|
@ -509,7 +506,7 @@ impl EnumVariant {
|
||||||
pub fn source(
|
pub fn source(
|
||||||
&self,
|
&self,
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
db: &(impl DefDatabase + AstDatabase),
|
||||||
) -> (HirFileId, TreeArc<ast::EnumVariant>) {
|
) -> Source<TreeArc<ast::EnumVariant>> {
|
||||||
self.source_impl(db)
|
self.source_impl(db)
|
||||||
}
|
}
|
||||||
pub fn module(&self, db: &impl HirDatabase) -> Module {
|
pub fn module(&self, db: &impl HirDatabase) -> Module {
|
||||||
|
|
|
@ -77,8 +77,8 @@ pub(crate) fn documentation_query(
|
||||||
FieldSource::Pos(..) => return None,
|
FieldSource::Pos(..) => return None,
|
||||||
},
|
},
|
||||||
DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::Enum(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).1),
|
DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::Static(it) => docs_from_ast(&*it.source(db).1),
|
DocDef::Static(it) => docs_from_ast(&*it.source(db).1),
|
||||||
DocDef::Const(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),
|
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::Function(it) => generics.fill(&*it.source(db).1, start),
|
||||||
GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start),
|
GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start),
|
||||||
GenericDef::Union(it) => generics.fill(&*it.source(db).1, 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) => {
|
GenericDef::Trait(it) => {
|
||||||
// traits get the Self type as an implicit first type parameter
|
// traits get the Self type as an implicit first type parameter
|
||||||
generics.params.push(GenericParam {
|
generics.params.push(GenericParam {
|
||||||
|
|
|
@ -81,5 +81,5 @@ pub use self::code_model::{
|
||||||
StructField, FieldSource,
|
StructField, FieldSource,
|
||||||
Static, Const, ConstSignature,
|
Static, Const, ConstSignature,
|
||||||
Trait, TypeAlias, MacroDef, Container,
|
Trait, TypeAlias, MacroDef, Container,
|
||||||
BuiltinType,
|
BuiltinType, Source,
|
||||||
};
|
};
|
||||||
|
|
|
@ -207,12 +207,12 @@ impl NavigationTarget {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
hir::AdtDef::Enum(s) => {
|
hir::AdtDef::Enum(s) => {
|
||||||
let (file_id, node) = s.source(db);
|
let src = s.source(db);
|
||||||
NavigationTarget::from_named(
|
NavigationTarget::from_named(
|
||||||
file_id.original_file(db),
|
src.file_id.original_file(db),
|
||||||
&*node,
|
&*src.ast,
|
||||||
node.doc_comment_text(),
|
src.ast.doc_comment_text(),
|
||||||
node.short_label(),
|
src.ast.short_label(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,24 +225,9 @@ impl NavigationTarget {
|
||||||
let nav = match module_def {
|
let nav = match module_def {
|
||||||
hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module),
|
hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module),
|
||||||
hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func),
|
hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func),
|
||||||
hir::ModuleDef::Struct(s) => {
|
hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()),
|
||||||
let src = s.source(db);
|
hir::ModuleDef::Enum(it) => NavigationTarget::from_adt_def(db, it.into()),
|
||||||
NavigationTarget::from_named(
|
hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()),
|
||||||
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::Const(s) => {
|
hir::ModuleDef::Const(s) => {
|
||||||
let (file_id, node) = s.source(db);
|
let (file_id, node) = s.source(db);
|
||||||
NavigationTarget::from_named(
|
NavigationTarget::from_named(
|
||||||
|
@ -261,22 +246,13 @@ impl NavigationTarget {
|
||||||
node.short_label(),
|
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) => {
|
hir::ModuleDef::EnumVariant(var) => {
|
||||||
let (file_id, node) = var.source(db);
|
let src = var.source(db);
|
||||||
NavigationTarget::from_named(
|
NavigationTarget::from_named(
|
||||||
file_id.original_file(db),
|
src.file_id.original_file(db),
|
||||||
&*node,
|
&*src.ast,
|
||||||
node.doc_comment_text(),
|
src.ast.doc_comment_text(),
|
||||||
node.short_label(),
|
src.ast.short_label(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
hir::ModuleDef::Trait(e) => {
|
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()))
|
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
||||||
}
|
}
|
||||||
hir::ModuleDef::Enum(it) => {
|
hir::ModuleDef::Enum(it) => {
|
||||||
let it = it.source(db).1;
|
let src = it.source(db);
|
||||||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
|
||||||
}
|
}
|
||||||
hir::ModuleDef::EnumVariant(it) => {
|
hir::ModuleDef::EnumVariant(it) => {
|
||||||
let it = it.source(db).1;
|
let src = it.source(db);
|
||||||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
|
||||||
}
|
}
|
||||||
hir::ModuleDef::Const(it) => {
|
hir::ModuleDef::Const(it) => {
|
||||||
let it = it.source(db).1;
|
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()))
|
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
||||||
}
|
}
|
||||||
hir::AdtDef::Enum(it) => {
|
hir::AdtDef::Enum(it) => {
|
||||||
let it = it.source(db).1;
|
let src = it.source(db);
|
||||||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
res.extend(hover_text(
|
||||||
|
src.ast.doc_comment_text(),
|
||||||
|
src.ast.short_label(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue