mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +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,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue