From 11c0a5bb60f9377526a588c11c68d5471ae46aa3 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 10 May 2020 16:08:28 +0100 Subject: Highlight mutable statics as mutable --- crates/ra_hir_def/src/data.rs | 31 ++++++++++++++++++++++++++----- crates/ra_hir_def/src/db.rs | 6 +++--- 2 files changed, 29 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index e7eb2bb11..e2130d931 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -251,11 +251,6 @@ impl ConstData { Arc::new(ConstData::new(db, vis_default, node)) } - pub(crate) fn static_data_query(db: &dyn DefDatabase, konst: StaticId) -> Arc { - let node = konst.lookup(db).source(db); - Arc::new(ConstData::new(db, RawVisibility::private(), node)) - } - fn new( db: &dyn DefDatabase, vis_default: RawVisibility, @@ -270,6 +265,32 @@ impl ConstData { } } +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct StaticData { + pub name: Option, + pub type_ref: TypeRef, + pub visibility: RawVisibility, + pub mutable: bool, +} + +impl StaticData { + pub(crate) fn static_data_query(db: &dyn DefDatabase, konst: StaticId) -> Arc { + let node = konst.lookup(db).source(db); + let ctx = LowerCtx::new(db, node.file_id); + + let name = node.value.name().map(|n| n.as_name()); + let type_ref = TypeRef::from_ast_opt(&ctx, node.value.ascribed_type()); + let mutable = node.value.mut_token().is_some(); + let visibility = RawVisibility::from_ast_with_default( + db, + RawVisibility::private(), + node.map(|n| n.visibility()), + ); + + Arc::new(StaticData { name, type_ref, visibility, mutable }) + } +} + fn collect_items_in_macros( db: &dyn DefDatabase, expander: &mut Expander, diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index 5dc7395f5..e665ab45d 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs @@ -10,7 +10,7 @@ use crate::{ adt::{EnumData, StructData}, attr::Attrs, body::{scope::ExprScopes, Body, BodySourceMap}, - data::{ConstData, FunctionData, ImplData, TraitData, TypeAliasData}, + data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData}, docs::Documentation, generics::GenericParams, lang_item::{LangItemTarget, LangItems}, @@ -77,8 +77,8 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast { #[salsa::invoke(ConstData::const_data_query)] fn const_data(&self, konst: ConstId) -> Arc; - #[salsa::invoke(ConstData::static_data_query)] - fn static_data(&self, konst: StaticId) -> Arc; + #[salsa::invoke(StaticData::static_data_query)] + fn static_data(&self, konst: StaticId) -> Arc; #[salsa::invoke(Body::body_with_source_map_query)] fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc, Arc); -- cgit v1.2.3