aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model.rs4
-rw-r--r--crates/ra_hir_def/src/data.rs31
-rw-r--r--crates/ra_hir_def/src/db.rs6
-rw-r--r--crates/ra_hir_ty/src/infer.rs8
-rw-r--r--crates/ra_ide/src/snapshots/highlight_strings.html4
-rw-r--r--crates/ra_ide/src/snapshots/highlighting.html9
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs21
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs7
-rw-r--r--crates/ra_toolchain/src/lib.rs7
-rw-r--r--crates/rust-analyzer/src/main_loop.rs11
-rw-r--r--crates/rust-analyzer/src/world.rs38
11 files changed, 99 insertions, 47 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index be18c845c..3fc2eccdd 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -678,6 +678,10 @@ impl Static {
678 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { 678 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
679 db.static_data(self.id).name.clone() 679 db.static_data(self.id).name.clone()
680 } 680 }
681
682 pub fn is_mut(self, db: &dyn HirDatabase) -> bool {
683 db.static_data(self.id).mutable
684 }
681} 685}
682 686
683#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 687#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
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 {
251 Arc::new(ConstData::new(db, vis_default, node)) 251 Arc::new(ConstData::new(db, vis_default, node))
252 } 252 }
253 253
254 pub(crate) fn static_data_query(db: &dyn DefDatabase, konst: StaticId) -> Arc<ConstData> {
255 let node = konst.lookup(db).source(db);
256 Arc::new(ConstData::new(db, RawVisibility::private(), node))
257 }
258
259 fn new<N: NameOwner + TypeAscriptionOwner + VisibilityOwner>( 254 fn new<N: NameOwner + TypeAscriptionOwner + VisibilityOwner>(
260 db: &dyn DefDatabase, 255 db: &dyn DefDatabase,
261 vis_default: RawVisibility, 256 vis_default: RawVisibility,
@@ -270,6 +265,32 @@ impl ConstData {
270 } 265 }
271} 266}
272 267
268#[derive(Debug, Clone, PartialEq, Eq)]
269pub struct StaticData {
270 pub name: Option<Name>,
271 pub type_ref: TypeRef,
272 pub visibility: RawVisibility,
273 pub mutable: bool,
274}
275
276impl StaticData {
277 pub(crate) fn static_data_query(db: &dyn DefDatabase, konst: StaticId) -> Arc<StaticData> {
278 let node = konst.lookup(db).source(db);
279 let ctx = LowerCtx::new(db, node.file_id);
280
281 let name = node.value.name().map(|n| n.as_name());
282 let type_ref = TypeRef::from_ast_opt(&ctx, node.value.ascribed_type());
283 let mutable = node.value.mut_token().is_some();
284 let visibility = RawVisibility::from_ast_with_default(
285 db,
286 RawVisibility::private(),
287 node.map(|n| n.visibility()),
288 );
289
290 Arc::new(StaticData { name, type_ref, visibility, mutable })
291 }
292}
293
273fn collect_items_in_macros( 294fn collect_items_in_macros(
274 db: &dyn DefDatabase, 295 db: &dyn DefDatabase,
275 expander: &mut Expander, 296 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::{
10 adt::{EnumData, StructData}, 10 adt::{EnumData, StructData},
11 attr::Attrs, 11 attr::Attrs,
12 body::{scope::ExprScopes, Body, BodySourceMap}, 12 body::{scope::ExprScopes, Body, BodySourceMap},
13 data::{ConstData, FunctionData, ImplData, TraitData, TypeAliasData}, 13 data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData},
14 docs::Documentation, 14 docs::Documentation,
15 generics::GenericParams, 15 generics::GenericParams,
16 lang_item::{LangItemTarget, LangItems}, 16 lang_item::{LangItemTarget, LangItems},
@@ -77,8 +77,8 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
77 #[salsa::invoke(ConstData::const_data_query)] 77 #[salsa::invoke(ConstData::const_data_query)]
78 fn const_data(&self, konst: ConstId) -> Arc<ConstData>; 78 fn const_data(&self, konst: ConstId) -> Arc<ConstData>;
79 79
80 #[salsa::invoke(ConstData::static_data_query)] 80 #[salsa::invoke(StaticData::static_data_query)]
81 fn static_data(&self, konst: StaticId) -> Arc<ConstData>; 81 fn static_data(&self, konst: StaticId) -> Arc<StaticData>;
82 82
83 #[salsa::invoke(Body::body_with_source_map_query)] 83 #[salsa::invoke(Body::body_with_source_map_query)]
84 fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>); 84 fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index a21ad8d86..fb7c6cd8c 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -22,7 +22,7 @@ use rustc_hash::FxHashMap;
22 22
23use hir_def::{ 23use hir_def::{
24 body::Body, 24 body::Body,
25 data::{ConstData, FunctionData}, 25 data::{ConstData, FunctionData, StaticData},
26 expr::{BindingAnnotation, ExprId, PatId}, 26 expr::{BindingAnnotation, ExprId, PatId},
27 lang_item::LangItemTarget, 27 lang_item::LangItemTarget,
28 path::{path, Path}, 28 path::{path, Path},
@@ -71,7 +71,7 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
71 match def { 71 match def {
72 DefWithBodyId::ConstId(c) => ctx.collect_const(&db.const_data(c)), 72 DefWithBodyId::ConstId(c) => ctx.collect_const(&db.const_data(c)),
73 DefWithBodyId::FunctionId(f) => ctx.collect_fn(&db.function_data(f)), 73 DefWithBodyId::FunctionId(f) => ctx.collect_fn(&db.function_data(f)),
74 DefWithBodyId::StaticId(s) => ctx.collect_const(&db.static_data(s)), 74 DefWithBodyId::StaticId(s) => ctx.collect_static(&db.static_data(s)),
75 } 75 }
76 76
77 ctx.infer_body(); 77 ctx.infer_body();
@@ -485,6 +485,10 @@ impl<'a> InferenceContext<'a> {
485 self.return_ty = self.make_ty(&data.type_ref); 485 self.return_ty = self.make_ty(&data.type_ref);
486 } 486 }
487 487
488 fn collect_static(&mut self, data: &StaticData) {
489 self.return_ty = self.make_ty(&data.type_ref);
490 }
491
488 fn collect_fn(&mut self, data: &FunctionData) { 492 fn collect_fn(&mut self, data: &FunctionData) {
489 let body = Arc::clone(&self.body); // avoid borrow checker problem 493 let body = Arc::clone(&self.body); // avoid borrow checker problem
490 let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver) 494 let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver)
diff --git a/crates/ra_ide/src/snapshots/highlight_strings.html b/crates/ra_ide/src/snapshots/highlight_strings.html
index de06daf72..752b487e8 100644
--- a/crates/ra_ide/src/snapshots/highlight_strings.html
+++ b/crates/ra_ide/src/snapshots/highlight_strings.html
@@ -27,13 +27,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
27.keyword.unsafe { color: #BC8383; font-weight: bold; } 27.keyword.unsafe { color: #BC8383; font-weight: bold; }
28.control { font-style: italic; } 28.control { font-style: italic; }
29</style> 29</style>
30<pre><code><span class="macro">macro_rules!</span> println { 30<pre><code><span class="macro">macro_rules!</span> <span class="macro declaration">println</span> {
31 ($($arg:tt)*) =&gt; ({ 31 ($($arg:tt)*) =&gt; ({
32 $<span class="keyword">crate</span>::io::_print($<span class="keyword">crate</span>::format_args_nl!($($arg)*)); 32 $<span class="keyword">crate</span>::io::_print($<span class="keyword">crate</span>::format_args_nl!($($arg)*));
33 }) 33 })
34} 34}
35#[rustc_builtin_macro] 35#[rustc_builtin_macro]
36<span class="macro">macro_rules!</span> format_args_nl { 36<span class="macro">macro_rules!</span> <span class="macro declaration">format_args_nl</span> {
37 ($fmt:expr) =&gt; {{ <span class="comment">/* compiler built-in */</span> }}; 37 ($fmt:expr) =&gt; {{ <span class="comment">/* compiler built-in */</span> }};
38 ($fmt:expr, $($args:tt)*) =&gt; {{ <span class="comment">/* compiler built-in */</span> }}; 38 ($fmt:expr, $($args:tt)*) =&gt; {{ <span class="comment">/* compiler built-in */</span> }};
39} 39}
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html
index 4b12fe823..4c27aade4 100644
--- a/crates/ra_ide/src/snapshots/highlighting.html
+++ b/crates/ra_ide/src/snapshots/highlighting.html
@@ -33,11 +33,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
33 <span class="keyword">pub</span> <span class="field declaration">y</span>: <span class="builtin_type">i32</span>, 33 <span class="keyword">pub</span> <span class="field declaration">y</span>: <span class="builtin_type">i32</span>,
34} 34}
35 35
36<span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable">STATIC_MUT</span>: <span class="builtin_type">i32</span> = <span class="numeric_literal">0</span>;
37
36<span class="keyword">fn</span> <span class="function declaration">foo</span>&lt;<span class="lifetime declaration">'a</span>, <span class="type_param declaration">T</span>&gt;() -&gt; <span class="type_param">T</span> { 38<span class="keyword">fn</span> <span class="function declaration">foo</span>&lt;<span class="lifetime declaration">'a</span>, <span class="type_param declaration">T</span>&gt;() -&gt; <span class="type_param">T</span> {
37 <span class="function">foo</span>::&lt;<span class="lifetime">'a</span>, <span class="builtin_type">i32</span>&gt;() 39 <span class="function">foo</span>::&lt;<span class="lifetime">'a</span>, <span class="builtin_type">i32</span>&gt;()
38} 40}
39 41
40<span class="macro">macro_rules!</span> def_fn { 42<span class="macro">macro_rules!</span> <span class="macro declaration">def_fn</span> {
41 ($($tt:tt)*) =&gt; {$($tt)*} 43 ($($tt:tt)*) =&gt; {$($tt)*}
42} 44}
43 45
@@ -56,7 +58,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
56 <span class="keyword">let</span> <span class="variable declaration">x</span> = <span class="numeric_literal">92</span>; 58 <span class="keyword">let</span> <span class="variable declaration">x</span> = <span class="numeric_literal">92</span>;
57 <span class="variable mutable">vec</span>.<span class="unresolved_reference">push</span>(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> }); 59 <span class="variable mutable">vec</span>.<span class="unresolved_reference">push</span>(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> });
58 } 60 }
59 <span class="keyword unsafe">unsafe</span> { <span class="variable mutable">vec</span>.<span class="unresolved_reference">set_len</span>(<span class="numeric_literal">0</span>); } 61 <span class="keyword unsafe">unsafe</span> {
62 <span class="variable mutable">vec</span>.<span class="unresolved_reference">set_len</span>(<span class="numeric_literal">0</span>);
63 <span class="static mutable">STATIC_MUT</span> = <span class="numeric_literal">1</span>;
64 }
60 65
61 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>; 66 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>;
62 <span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>; 67 <span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>;
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 6658c7bb2..d53a39f57 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -167,6 +167,19 @@ pub(crate) fn highlight(
167 binding_hash: None, 167 binding_hash: None,
168 }); 168 });
169 } 169 }
170 if let Some(name) = mc.is_macro_rules() {
171 if let Some((highlight, binding_hash)) = highlight_element(
172 &sema,
173 &mut bindings_shadow_count,
174 name.syntax().clone().into(),
175 ) {
176 stack.add(HighlightedRange {
177 range: name.syntax().text_range(),
178 highlight,
179 binding_hash,
180 });
181 }
182 }
170 continue; 183 continue;
171 } 184 }
172 WalkEvent::Leave(Some(mc)) => { 185 WalkEvent::Leave(Some(mc)) => {
@@ -431,10 +444,16 @@ fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight {
431 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, 444 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union,
432 hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant, 445 hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant,
433 hir::ModuleDef::Const(_) => HighlightTag::Constant, 446 hir::ModuleDef::Const(_) => HighlightTag::Constant,
434 hir::ModuleDef::Static(_) => HighlightTag::Static,
435 hir::ModuleDef::Trait(_) => HighlightTag::Trait, 447 hir::ModuleDef::Trait(_) => HighlightTag::Trait,
436 hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias, 448 hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias,
437 hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, 449 hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType,
450 hir::ModuleDef::Static(s) => {
451 let mut h = Highlight::new(HighlightTag::Static);
452 if s.is_mut(db) {
453 h |= HighlightModifier::Mutable;
454 }
455 return h;
456 }
438 }, 457 },
439 Definition::SelfType(_) => HighlightTag::SelfType, 458 Definition::SelfType(_) => HighlightTag::SelfType,
440 Definition::TypeParam(_) => HighlightTag::TypeParam, 459 Definition::TypeParam(_) => HighlightTag::TypeParam,
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index d2926ba78..13894869c 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -17,6 +17,8 @@ struct Foo {
17 pub y: i32, 17 pub y: i32,
18} 18}
19 19
20static mut STATIC_MUT: i32 = 0;
21
20fn foo<'a, T>() -> T { 22fn foo<'a, T>() -> T {
21 foo::<'a, i32>() 23 foo::<'a, i32>()
22} 24}
@@ -40,7 +42,10 @@ fn main() {
40 let x = 92; 42 let x = 92;
41 vec.push(Foo { x, y: 1 }); 43 vec.push(Foo { x, y: 1 });
42 } 44 }
43 unsafe { vec.set_len(0); } 45 unsafe {
46 vec.set_len(0);
47 STATIC_MUT = 1;
48 }
44 49
45 let mut x = 42; 50 let mut x = 42;
46 let y = &mut x; 51 let y = &mut x;
diff --git a/crates/ra_toolchain/src/lib.rs b/crates/ra_toolchain/src/lib.rs
index 3c307a0ea..3d2865e09 100644
--- a/crates/ra_toolchain/src/lib.rs
+++ b/crates/ra_toolchain/src/lib.rs
@@ -53,10 +53,9 @@ fn lookup_in_path(exec: &str) -> bool {
53 let paths = env::var_os("PATH").unwrap_or_default(); 53 let paths = env::var_os("PATH").unwrap_or_default();
54 let mut candidates = env::split_paths(&paths).flat_map(|path| { 54 let mut candidates = env::split_paths(&paths).flat_map(|path| {
55 let candidate = path.join(&exec); 55 let candidate = path.join(&exec);
56 let with_exe = if env::consts::EXE_EXTENSION == "" { 56 let with_exe = match env::consts::EXE_EXTENSION {
57 None 57 "" => None,
58 } else { 58 it => Some(candidate.with_extension(it)),
59 Some(candidate.with_extension(env::consts::EXE_EXTENSION))
60 }; 59 };
61 iter::once(candidate).chain(with_exe) 60 iter::once(candidate).chain(with_exe)
62 }); 61 });
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index fa72a9cc6..3f12dd718 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -174,7 +174,6 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
174 }; 174 };
175 175
176 loop_state.roots_total = world_state.vfs.read().n_roots(); 176 loop_state.roots_total = world_state.vfs.read().n_roots();
177 loop_state.roots_scanned = 0;
178 177
179 let pool = ThreadPool::default(); 178 let pool = ThreadPool::default();
180 let (task_sender, task_receiver) = unbounded::<Task>(); 179 let (task_sender, task_receiver) = unbounded::<Task>();
@@ -401,10 +400,12 @@ fn loop_turn(
401 } 400 }
402 401
403 let max_in_flight_libs = pool.max_count().saturating_sub(2).max(1); 402 let max_in_flight_libs = pool.max_count().saturating_sub(2).max(1);
404 while loop_state.in_flight_libraries < max_in_flight_libs 403 while loop_state.in_flight_libraries < max_in_flight_libs {
405 && !loop_state.pending_libraries.is_empty() 404 let (root, files) = match loop_state.pending_libraries.pop() {
406 { 405 Some(it) => it,
407 let (root, files) = loop_state.pending_libraries.pop().unwrap(); 406 None => break,
407 };
408
408 loop_state.in_flight_libraries += 1; 409 loop_state.in_flight_libraries += 1;
409 let sender = libdata_sender.clone(); 410 let sender = libdata_sender.clone();
410 pool.execute(move || { 411 pool.execute(move || {
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs
index 16020648d..6333c15b2 100644
--- a/crates/rust-analyzer/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -137,15 +137,6 @@ impl WorldState {
137 opts 137 opts
138 }; 138 };
139 139
140 // Create crate graph from all the workspaces
141 let mut crate_graph = CrateGraph::default();
142 let mut load = |path: &std::path::Path| {
143 // Some path from metadata will be non canonicalized, e.g. /foo/../bar/lib.rs
144 let path = path.canonicalize().ok()?;
145 let vfs_file = vfs.load(&path);
146 vfs_file.map(|f| FileId(f.0))
147 };
148
149 let proc_macro_client = match &config.proc_macro_srv { 140 let proc_macro_client = match &config.proc_macro_srv {
150 None => ProcMacroClient::dummy(), 141 None => ProcMacroClient::dummy(),
151 Some((path, args)) => match ProcMacroClient::extern_process(path.into(), args) { 142 Some((path, args)) => match ProcMacroClient::extern_process(path.into(), args) {
@@ -161,19 +152,22 @@ impl WorldState {
161 }, 152 },
162 }; 153 };
163 154
164 workspaces 155 // Create crate graph from all the workspaces
165 .iter() 156 let mut crate_graph = CrateGraph::default();
166 .map(|ws| { 157 let mut load = |path: &Path| {
167 ws.to_crate_graph( 158 // Some path from metadata will be non canonicalized, e.g. /foo/../bar/lib.rs
168 &default_cfg_options, 159 let path = path.canonicalize().ok()?;
169 &extern_source_roots, 160 let vfs_file = vfs.load(&path);
170 &proc_macro_client, 161 vfs_file.map(|f| FileId(f.0))
171 &mut load, 162 };
172 ) 163 for ws in workspaces.iter() {
173 }) 164 crate_graph.extend(ws.to_crate_graph(
174 .for_each(|graph| { 165 &default_cfg_options,
175 crate_graph.extend(graph); 166 &extern_source_roots,
176 }); 167 &proc_macro_client,
168 &mut load,
169 ));
170 }
177 change.set_crate_graph(crate_graph); 171 change.set_crate_graph(crate_graph);
178 172
179 let flycheck = config.check.as_ref().and_then(|c| create_flycheck(&workspaces, c)); 173 let flycheck = config.check.as_ref().and_then(|c| create_flycheck(&workspaces, c));