mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
use Source for impl block
This commit is contained in:
parent
f411c2988d
commit
a6e339e822
5 changed files with 20 additions and 17 deletions
|
@ -442,11 +442,8 @@ impl HasSource for Union {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Union {
|
impl Union {
|
||||||
pub fn source(
|
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
|
||||||
self,
|
self.id.source(db).into()
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
|
||||||
) -> (HirFileId, TreeArc<ast::StructDef>) {
|
|
||||||
self.id.source(db)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub(crate) fn documentation_query(
|
||||||
DocDef::Static(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Static(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::Const(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Const(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::Function(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Function(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::Union(it) => docs_from_ast(&*it.source(db).1),
|
DocDef::Union(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::Trait(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Trait(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1),
|
DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1),
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl GenericParams {
|
||||||
match def {
|
match def {
|
||||||
GenericDef::Function(it) => generics.fill(&*it.source(db).ast, start),
|
GenericDef::Function(it) => generics.fill(&*it.source(db).ast, 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).ast, start),
|
||||||
GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, 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
|
||||||
|
@ -82,7 +82,7 @@ impl GenericParams {
|
||||||
generics.fill(&*it.source(db).ast, start + 1);
|
generics.fill(&*it.source(db).ast, start + 1);
|
||||||
}
|
}
|
||||||
GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, start),
|
GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, start),
|
||||||
GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1, start),
|
GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).ast, start),
|
||||||
}
|
}
|
||||||
|
|
||||||
Arc::new(generics)
|
Arc::new(generics)
|
||||||
|
|
|
@ -8,7 +8,7 @@ use ra_syntax::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Const, TypeAlias, Function, HirFileId, AstDatabase,
|
Const, TypeAlias, Function, HirFileId, AstDatabase, HasSource, Source,
|
||||||
HirDatabase, DefDatabase, TraitRef,
|
HirDatabase, DefDatabase, TraitRef,
|
||||||
type_ref::TypeRef,
|
type_ref::TypeRef,
|
||||||
ids::LocationCtx,
|
ids::LocationCtx,
|
||||||
|
@ -44,6 +44,15 @@ pub struct ImplBlock {
|
||||||
impl_id: ImplId,
|
impl_id: ImplId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasSource for ImplBlock {
|
||||||
|
type Ast = TreeArc<ast::ImplBlock>;
|
||||||
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ImplBlock>> {
|
||||||
|
let source_map = db.impls_in_module_with_source_map(self.module).1;
|
||||||
|
let (file_id, source) = self.module.definition_source(db);
|
||||||
|
(file_id, source_map.get(&source, self.impl_id)).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ImplBlock {
|
impl ImplBlock {
|
||||||
pub(crate) fn containing(
|
pub(crate) fn containing(
|
||||||
module_impl_blocks: Arc<ModuleImplBlocks>,
|
module_impl_blocks: Arc<ModuleImplBlocks>,
|
||||||
|
@ -58,13 +67,10 @@ impl ImplBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the syntax of the impl block
|
/// Returns the syntax of the impl block
|
||||||
pub fn source(
|
pub fn source(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ImplBlock>> {
|
||||||
&self,
|
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
|
||||||
) -> (HirFileId, TreeArc<ast::ImplBlock>) {
|
|
||||||
let source_map = db.impls_in_module_with_source_map(self.module).1;
|
let source_map = db.impls_in_module_with_source_map(self.module).1;
|
||||||
let (file_id, source) = self.module.definition_source(db);
|
let (file_id, source) = self.module.definition_source(db);
|
||||||
(file_id, source_map.get(&source, self.impl_id))
|
(file_id, source_map.get(&source, self.impl_id)).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn id(&self) -> ImplId {
|
pub fn id(&self) -> ImplId {
|
||||||
|
|
|
@ -228,12 +228,12 @@ impl NavigationTarget {
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
impl_block: hir::ImplBlock,
|
impl_block: hir::ImplBlock,
|
||||||
) -> NavigationTarget {
|
) -> NavigationTarget {
|
||||||
let (file_id, node) = impl_block.source(db);
|
let src = impl_block.source(db);
|
||||||
NavigationTarget::from_syntax(
|
NavigationTarget::from_syntax(
|
||||||
file_id.as_original_file(),
|
src.file_id.as_original_file(),
|
||||||
"impl".into(),
|
"impl".into(),
|
||||||
None,
|
None,
|
||||||
node.syntax(),
|
src.ast.syntax(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue