mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-08 21:13:55 +00:00
use Source for statics and consts
This commit is contained in:
parent
4f94af3c4a
commit
46bc8675ed
@ -761,12 +761,17 @@ pub struct Const {
|
|||||||
pub(crate) id: ConstId,
|
pub(crate) id: ConstId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasSource for Const {
|
||||||
|
type Ast = TreeArc<ast::ConstDef>;
|
||||||
|
|
||||||
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> {
|
||||||
|
self.id.source(db).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Const {
|
impl Const {
|
||||||
pub fn source(
|
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> {
|
||||||
self,
|
self.id.source(db).into()
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
|
||||||
) -> (HirFileId, TreeArc<ast::ConstDef>) {
|
|
||||||
self.id.source(db)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module(self, db: &impl DefDatabase) -> Module {
|
pub fn module(self, db: &impl DefDatabase) -> Module {
|
||||||
@ -819,7 +824,7 @@ impl ConstSignature {
|
|||||||
db: &(impl DefDatabase + AstDatabase),
|
db: &(impl DefDatabase + AstDatabase),
|
||||||
konst: Const,
|
konst: Const,
|
||||||
) -> Arc<ConstSignature> {
|
) -> Arc<ConstSignature> {
|
||||||
let (_, node) = konst.source(db);
|
let node = konst.source(db).ast;
|
||||||
const_signature_for(&*node)
|
const_signature_for(&*node)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -827,7 +832,7 @@ impl ConstSignature {
|
|||||||
db: &(impl DefDatabase + AstDatabase),
|
db: &(impl DefDatabase + AstDatabase),
|
||||||
konst: Static,
|
konst: Static,
|
||||||
) -> Arc<ConstSignature> {
|
) -> Arc<ConstSignature> {
|
||||||
let (_, node) = konst.source(db);
|
let node = konst.source(db).ast;
|
||||||
const_signature_for(&*node)
|
const_signature_for(&*node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -844,12 +849,17 @@ pub struct Static {
|
|||||||
pub(crate) id: StaticId,
|
pub(crate) id: StaticId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasSource for Static {
|
||||||
|
type Ast = TreeArc<ast::StaticDef>;
|
||||||
|
|
||||||
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> {
|
||||||
|
self.id.source(db).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Static {
|
impl Static {
|
||||||
pub fn source(
|
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> {
|
||||||
self,
|
self.id.source(db).into()
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
|
||||||
) -> (HirFileId, TreeArc<ast::StaticDef>) {
|
|
||||||
self.id.source(db)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module(self, db: &impl DefDatabase) -> Module {
|
pub fn module(self, db: &impl DefDatabase) -> Module {
|
||||||
|
@ -79,8 +79,8 @@ pub(crate) fn documentation_query(
|
|||||||
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).ast),
|
DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::EnumVariant(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::Static(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::Const(it) => docs_from_ast(&*it.source(db).1),
|
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).1),
|
||||||
DocDef::Trait(it) => docs_from_ast(&*it.source(db).1),
|
DocDef::Trait(it) => docs_from_ast(&*it.source(db).1),
|
||||||
|
@ -1018,9 +1018,9 @@ pub(crate) fn body_with_source_map_query(
|
|||||||
|
|
||||||
match def {
|
match def {
|
||||||
DefWithBody::Const(ref c) => {
|
DefWithBody::Const(ref c) => {
|
||||||
let (file_id, src) = c.source(db);
|
let src = c.source(db);
|
||||||
collector = ExprCollector::new(def, file_id, def.resolver(db), db);
|
collector = ExprCollector::new(def, src.file_id, def.resolver(db), db);
|
||||||
collector.collect_const_body(&src)
|
collector.collect_const_body(&src.ast)
|
||||||
}
|
}
|
||||||
DefWithBody::Function(ref f) => {
|
DefWithBody::Function(ref f) => {
|
||||||
let src = f.source(db);
|
let src = f.source(db);
|
||||||
@ -1028,9 +1028,9 @@ pub(crate) fn body_with_source_map_query(
|
|||||||
collector.collect_fn_body(&src.ast)
|
collector.collect_fn_body(&src.ast)
|
||||||
}
|
}
|
||||||
DefWithBody::Static(ref s) => {
|
DefWithBody::Static(ref s) => {
|
||||||
let (file_id, src) = s.source(db);
|
let src = s.source(db);
|
||||||
collector = ExprCollector::new(def, file_id, def.resolver(db), db);
|
collector = ExprCollector::new(def, src.file_id, def.resolver(db), db);
|
||||||
collector.collect_static_body(&src)
|
collector.collect_static_body(&src.ast)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,12 +126,11 @@ impl Completions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
|
pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
|
||||||
let (_file_id, ast_node) = constant.source(ctx.db);
|
let ast_node = constant.source(ctx.db).ast;
|
||||||
let name = match ast_node.name() {
|
let name = match ast_node.name() {
|
||||||
Some(name) => name,
|
Some(name) => name,
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
let (_, ast_node) = constant.source(ctx.db);
|
|
||||||
let detail = const_label(&ast_node);
|
let detail = const_label(&ast_node);
|
||||||
|
|
||||||
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
|
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
|
||||||
|
@ -212,24 +212,8 @@ impl NavigationTarget {
|
|||||||
hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()),
|
hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()),
|
||||||
hir::ModuleDef::Enum(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::Union(it) => NavigationTarget::from_adt_def(db, it.into()),
|
||||||
hir::ModuleDef::Const(s) => {
|
hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it),
|
||||||
let (file_id, node) = s.source(db);
|
hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it),
|
||||||
NavigationTarget::from_named(
|
|
||||||
file_id.original_file(db),
|
|
||||||
&*node,
|
|
||||||
node.doc_comment_text(),
|
|
||||||
node.short_label(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
hir::ModuleDef::Static(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::EnumVariant(var) => {
|
hir::ModuleDef::EnumVariant(var) => {
|
||||||
let src = var.source(db);
|
let src = var.source(db);
|
||||||
NavigationTarget::from_named(
|
NavigationTarget::from_named(
|
||||||
@ -281,16 +265,8 @@ impl NavigationTarget {
|
|||||||
|
|
||||||
pub(crate) fn from_impl_item(db: &RootDatabase, impl_item: hir::ImplItem) -> NavigationTarget {
|
pub(crate) fn from_impl_item(db: &RootDatabase, impl_item: hir::ImplItem) -> NavigationTarget {
|
||||||
match impl_item {
|
match impl_item {
|
||||||
ImplItem::Method(f) => NavigationTarget::from_function(db, f),
|
ImplItem::Method(it) => NavigationTarget::from_function(db, it),
|
||||||
ImplItem::Const(c) => {
|
ImplItem::Const(it) => NavigationTarget::from_def_source(db, it),
|
||||||
let (file_id, node) = c.source(db);
|
|
||||||
NavigationTarget::from_named(
|
|
||||||
file_id.original_file(db),
|
|
||||||
&*node,
|
|
||||||
node.doc_comment_text(),
|
|
||||||
node.short_label(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ImplItem::TypeAlias(a) => {
|
ImplItem::TypeAlias(a) => {
|
||||||
let (file_id, node) = a.source(db);
|
let (file_id, node) = a.source(db);
|
||||||
NavigationTarget::from_named(
|
NavigationTarget::from_named(
|
||||||
|
@ -115,8 +115,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||||||
res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
|
res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
|
||||||
}
|
}
|
||||||
hir::ImplItem::Const(it) => {
|
hir::ImplItem::Const(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::ImplItem::TypeAlias(it) => {
|
hir::ImplItem::TypeAlias(it) => {
|
||||||
let it = it.source(db).1;
|
let it = it.source(db).1;
|
||||||
@ -152,12 +152,12 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||||||
res.extend(hover_text(src.ast.doc_comment_text(), src.ast.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 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::Static(it) => {
|
hir::ModuleDef::Static(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::Trait(it) => {
|
hir::ModuleDef::Trait(it) => {
|
||||||
let it = it.source(db).1;
|
let it = it.source(db).1;
|
||||||
|
Loading…
Reference in New Issue
Block a user