diff options
Diffstat (limited to 'crates/ra_ide_db/src')
-rw-r--r-- | crates/ra_ide_db/src/change.rs | 13 | ||||
-rw-r--r-- | crates/ra_ide_db/src/feature_flags.rs | 71 | ||||
-rw-r--r-- | crates/ra_ide_db/src/lib.rs | 19 | ||||
-rw-r--r-- | crates/ra_ide_db/src/search.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide_db/src/symbol_index.rs | 4 |
5 files changed, 39 insertions, 96 deletions
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs index 7e9310005..628cf6416 100644 --- a/crates/ra_ide_db/src/change.rs +++ b/crates/ra_ide_db/src/change.rs | |||
@@ -5,7 +5,7 @@ use std::{fmt, sync::Arc, time}; | |||
5 | 5 | ||
6 | use ra_db::{ | 6 | use ra_db::{ |
7 | salsa::{Database, Durability, SweepStrategy}, | 7 | salsa::{Database, Durability, SweepStrategy}, |
8 | CrateGraph, CrateId, FileId, RelativePathBuf, SourceDatabase, SourceDatabaseExt, SourceRoot, | 8 | CrateGraph, FileId, RelativePathBuf, SourceDatabase, SourceDatabaseExt, SourceRoot, |
9 | SourceRootId, | 9 | SourceRootId, |
10 | }; | 10 | }; |
11 | use ra_prof::{memory_usage, profile, Bytes}; | 11 | use ra_prof::{memory_usage, profile, Bytes}; |
@@ -88,10 +88,6 @@ impl AnalysisChange { | |||
88 | self.crate_graph = Some(graph); | 88 | self.crate_graph = Some(graph); |
89 | } | 89 | } |
90 | 90 | ||
91 | pub fn set_debug_crate_name(&mut self, crate_id: CrateId, name: String) { | ||
92 | self.debug_data.crate_names.insert(crate_id, name); | ||
93 | } | ||
94 | |||
95 | pub fn set_debug_root_path(&mut self, source_root_id: SourceRootId, path: String) { | 91 | pub fn set_debug_root_path(&mut self, source_root_id: SourceRootId, path: String) { |
96 | self.debug_data.root_paths.insert(source_root_id, path); | 92 | self.debug_data.root_paths.insert(source_root_id, path); |
97 | } | 93 | } |
@@ -279,7 +275,7 @@ impl RootDatabase { | |||
279 | self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); | 275 | self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); |
280 | 276 | ||
281 | self.query(hir::db::ExprScopesQuery).sweep(sweep); | 277 | self.query(hir::db::ExprScopesQuery).sweep(sweep); |
282 | self.query(hir::db::DoInferQuery).sweep(sweep); | 278 | self.query(hir::db::InferQueryQuery).sweep(sweep); |
283 | self.query(hir::db::BodyQuery).sweep(sweep); | 279 | self.query(hir::db::BodyQuery).sweep(sweep); |
284 | } | 280 | } |
285 | 281 | ||
@@ -318,7 +314,7 @@ impl RootDatabase { | |||
318 | 314 | ||
319 | // DefDatabase | 315 | // DefDatabase |
320 | hir::db::RawItemsQuery | 316 | hir::db::RawItemsQuery |
321 | hir::db::ComputeCrateDefMapQuery | 317 | hir::db::CrateDefMapQueryQuery |
322 | hir::db::StructDataQuery | 318 | hir::db::StructDataQuery |
323 | hir::db::UnionDataQuery | 319 | hir::db::UnionDataQuery |
324 | hir::db::EnumDataQuery | 320 | hir::db::EnumDataQuery |
@@ -350,7 +346,7 @@ impl RootDatabase { | |||
350 | hir::db::InternImplQuery | 346 | hir::db::InternImplQuery |
351 | 347 | ||
352 | // HirDatabase | 348 | // HirDatabase |
353 | hir::db::DoInferQuery | 349 | hir::db::InferQueryQuery |
354 | hir::db::TyQuery | 350 | hir::db::TyQuery |
355 | hir::db::ValueTyQuery | 351 | hir::db::ValueTyQuery |
356 | hir::db::ImplSelfTyQuery | 352 | hir::db::ImplSelfTyQuery |
@@ -362,7 +358,6 @@ impl RootDatabase { | |||
362 | hir::db::GenericDefaultsQuery | 358 | hir::db::GenericDefaultsQuery |
363 | hir::db::ImplsInCrateQuery | 359 | hir::db::ImplsInCrateQuery |
364 | hir::db::ImplsForTraitQuery | 360 | hir::db::ImplsForTraitQuery |
365 | hir::db::TraitSolverQuery | ||
366 | hir::db::InternTypeCtorQuery | 361 | hir::db::InternTypeCtorQuery |
367 | hir::db::InternChalkImplQuery | 362 | hir::db::InternChalkImplQuery |
368 | hir::db::InternAssocTyValueQuery | 363 | hir::db::InternAssocTyValueQuery |
diff --git a/crates/ra_ide_db/src/feature_flags.rs b/crates/ra_ide_db/src/feature_flags.rs deleted file mode 100644 index 76655f572..000000000 --- a/crates/ra_ide_db/src/feature_flags.rs +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | //! See docs for `FeatureFlags`. | ||
2 | |||
3 | use rustc_hash::FxHashMap; | ||
4 | |||
5 | /// Feature flags hold fine-grained toggles for all *user-visible* features of | ||
6 | /// rust-analyzer. | ||
7 | /// | ||
8 | /// The exists such that users are able to disable any annoying feature (and, | ||
9 | /// with many users and many features, some features are bound to be annoying | ||
10 | /// for some users) | ||
11 | /// | ||
12 | /// Note that we purposefully use run-time checked strings, and not something | ||
13 | /// checked at compile time, to keep things simple and flexible. | ||
14 | /// | ||
15 | /// Also note that, at the moment, `FeatureFlags` also store features for | ||
16 | /// `rust-analyzer`. This should be benign layering violation. | ||
17 | #[derive(Debug)] | ||
18 | pub struct FeatureFlags { | ||
19 | flags: FxHashMap<String, bool>, | ||
20 | } | ||
21 | |||
22 | impl FeatureFlags { | ||
23 | fn new(flags: &[(&str, bool)]) -> FeatureFlags { | ||
24 | let flags = flags | ||
25 | .iter() | ||
26 | .map(|&(name, value)| { | ||
27 | check_flag_name(name); | ||
28 | (name.to_string(), value) | ||
29 | }) | ||
30 | .collect(); | ||
31 | FeatureFlags { flags } | ||
32 | } | ||
33 | |||
34 | pub fn set(&mut self, flag: &str, value: bool) -> Result<(), ()> { | ||
35 | match self.flags.get_mut(flag) { | ||
36 | None => Err(()), | ||
37 | Some(slot) => { | ||
38 | *slot = value; | ||
39 | Ok(()) | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | pub fn get(&self, flag: &str) -> bool { | ||
45 | match self.flags.get(flag) { | ||
46 | None => panic!("unknown flag: {:?}", flag), | ||
47 | Some(value) => *value, | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | |||
52 | impl Default for FeatureFlags { | ||
53 | fn default() -> FeatureFlags { | ||
54 | FeatureFlags::new(&[ | ||
55 | ("lsp.diagnostics", true), | ||
56 | ("completion.insertion.add-call-parenthesis", true), | ||
57 | ("completion.enable-postfix", true), | ||
58 | ("notifications.workspace-loaded", true), | ||
59 | ("notifications.cargo-toml-not-found", true), | ||
60 | ]) | ||
61 | } | ||
62 | } | ||
63 | |||
64 | fn check_flag_name(flag: &str) { | ||
65 | for c in flag.bytes() { | ||
66 | match c { | ||
67 | b'a'..=b'z' | b'-' | b'.' => (), | ||
68 | _ => panic!("flag name does not match conventions: {:?}", flag), | ||
69 | } | ||
70 | } | ||
71 | } | ||
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index 79f48c9e3..fc1b19def 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -5,7 +5,6 @@ | |||
5 | pub mod marks; | 5 | pub mod marks; |
6 | pub mod line_index; | 6 | pub mod line_index; |
7 | pub mod line_index_utils; | 7 | pub mod line_index_utils; |
8 | pub mod feature_flags; | ||
9 | pub mod symbol_index; | 8 | pub mod symbol_index; |
10 | pub mod change; | 9 | pub mod change; |
11 | pub mod defs; | 10 | pub mod defs; |
@@ -22,7 +21,7 @@ use ra_db::{ | |||
22 | }; | 21 | }; |
23 | use rustc_hash::FxHashMap; | 22 | use rustc_hash::FxHashMap; |
24 | 23 | ||
25 | use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase}; | 24 | use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase}; |
26 | 25 | ||
27 | #[salsa::database( | 26 | #[salsa::database( |
28 | ra_db::SourceDatabaseStorage, | 27 | ra_db::SourceDatabaseStorage, |
@@ -37,7 +36,6 @@ use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::Sy | |||
37 | #[derive(Debug)] | 36 | #[derive(Debug)] |
38 | pub struct RootDatabase { | 37 | pub struct RootDatabase { |
39 | runtime: salsa::Runtime<RootDatabase>, | 38 | runtime: salsa::Runtime<RootDatabase>, |
40 | pub feature_flags: Arc<FeatureFlags>, | ||
41 | pub(crate) debug_data: Arc<DebugData>, | 39 | pub(crate) debug_data: Arc<DebugData>, |
42 | pub last_gc: crate::wasm_shims::Instant, | 40 | pub last_gc: crate::wasm_shims::Instant, |
43 | pub last_gc_check: crate::wasm_shims::Instant, | 41 | pub last_gc_check: crate::wasm_shims::Instant, |
@@ -57,6 +55,13 @@ impl FileLoader for RootDatabase { | |||
57 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 55 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { |
58 | FileLoaderDelegate(self).relevant_crates(file_id) | 56 | FileLoaderDelegate(self).relevant_crates(file_id) |
59 | } | 57 | } |
58 | fn resolve_extern_path( | ||
59 | &self, | ||
60 | extern_id: ra_db::ExternSourceId, | ||
61 | relative_path: &RelativePath, | ||
62 | ) -> Option<FileId> { | ||
63 | FileLoaderDelegate(self).resolve_extern_path(extern_id, relative_path) | ||
64 | } | ||
60 | } | 65 | } |
61 | 66 | ||
62 | impl salsa::Database for RootDatabase { | 67 | impl salsa::Database for RootDatabase { |
@@ -82,17 +87,16 @@ impl salsa::Database for RootDatabase { | |||
82 | 87 | ||
83 | impl Default for RootDatabase { | 88 | impl Default for RootDatabase { |
84 | fn default() -> RootDatabase { | 89 | fn default() -> RootDatabase { |
85 | RootDatabase::new(None, FeatureFlags::default()) | 90 | RootDatabase::new(None) |
86 | } | 91 | } |
87 | } | 92 | } |
88 | 93 | ||
89 | impl RootDatabase { | 94 | impl RootDatabase { |
90 | pub fn new(lru_capacity: Option<usize>, feature_flags: FeatureFlags) -> RootDatabase { | 95 | pub fn new(lru_capacity: Option<usize>) -> RootDatabase { |
91 | let mut db = RootDatabase { | 96 | let mut db = RootDatabase { |
92 | runtime: salsa::Runtime::default(), | 97 | runtime: salsa::Runtime::default(), |
93 | last_gc: crate::wasm_shims::Instant::now(), | 98 | last_gc: crate::wasm_shims::Instant::now(), |
94 | last_gc_check: crate::wasm_shims::Instant::now(), | 99 | last_gc_check: crate::wasm_shims::Instant::now(), |
95 | feature_flags: Arc::new(feature_flags), | ||
96 | debug_data: Default::default(), | 100 | debug_data: Default::default(), |
97 | }; | 101 | }; |
98 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); | 102 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); |
@@ -112,7 +116,6 @@ impl salsa::ParallelDatabase for RootDatabase { | |||
112 | runtime: self.runtime.snapshot(self), | 116 | runtime: self.runtime.snapshot(self), |
113 | last_gc: self.last_gc, | 117 | last_gc: self.last_gc, |
114 | last_gc_check: self.last_gc_check, | 118 | last_gc_check: self.last_gc_check, |
115 | feature_flags: Arc::clone(&self.feature_flags), | ||
116 | debug_data: Arc::clone(&self.debug_data), | 119 | debug_data: Arc::clone(&self.debug_data), |
117 | }) | 120 | }) |
118 | } | 121 | } |
@@ -131,12 +134,10 @@ fn line_index(db: &impl LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> { | |||
131 | #[derive(Debug, Default, Clone)] | 134 | #[derive(Debug, Default, Clone)] |
132 | pub(crate) struct DebugData { | 135 | pub(crate) struct DebugData { |
133 | pub(crate) root_paths: FxHashMap<SourceRootId, String>, | 136 | pub(crate) root_paths: FxHashMap<SourceRootId, String>, |
134 | pub(crate) crate_names: FxHashMap<CrateId, String>, | ||
135 | } | 137 | } |
136 | 138 | ||
137 | impl DebugData { | 139 | impl DebugData { |
138 | pub(crate) fn merge(&mut self, other: DebugData) { | 140 | pub(crate) fn merge(&mut self, other: DebugData) { |
139 | self.root_paths.extend(other.root_paths.into_iter()); | 141 | self.root_paths.extend(other.root_paths.into_iter()); |
140 | self.crate_names.extend(other.crate_names.into_iter()); | ||
141 | } | 142 | } |
142 | } | 143 | } |
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs index 6f198df04..cf78d3e41 100644 --- a/crates/ra_ide_db/src/search.rs +++ b/crates/ra_ide_db/src/search.rs | |||
@@ -17,7 +17,7 @@ use rustc_hash::FxHashMap; | |||
17 | use test_utils::tested_by; | 17 | use test_utils::tested_by; |
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | defs::{classify_name_ref, Definition}, | 20 | defs::{classify_name_ref, Definition, NameRefClass}, |
21 | RootDatabase, | 21 | RootDatabase, |
22 | }; | 22 | }; |
23 | 23 | ||
@@ -30,6 +30,8 @@ pub struct Reference { | |||
30 | 30 | ||
31 | #[derive(Debug, Clone, PartialEq)] | 31 | #[derive(Debug, Clone, PartialEq)] |
32 | pub enum ReferenceKind { | 32 | pub enum ReferenceKind { |
33 | StructFieldShorthandForField, | ||
34 | StructFieldShorthandForLocal, | ||
33 | StructLiteral, | 35 | StructLiteral, |
34 | Other, | 36 | Other, |
35 | } | 37 | } |
@@ -237,9 +239,8 @@ impl Definition { | |||
237 | // FIXME: reuse sb | 239 | // FIXME: reuse sb |
238 | // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098 | 240 | // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098 |
239 | 241 | ||
240 | if let Some(d) = classify_name_ref(&sema, &name_ref) { | 242 | match classify_name_ref(&sema, &name_ref) { |
241 | let d = d.definition(); | 243 | Some(NameRefClass::Definition(def)) if &def == self => { |
242 | if &d == self { | ||
243 | let kind = if is_record_lit_name_ref(&name_ref) | 244 | let kind = if is_record_lit_name_ref(&name_ref) |
244 | || is_call_expr_name_ref(&name_ref) | 245 | || is_call_expr_name_ref(&name_ref) |
245 | { | 246 | { |
@@ -252,9 +253,26 @@ impl Definition { | |||
252 | refs.push(Reference { | 253 | refs.push(Reference { |
253 | file_range, | 254 | file_range, |
254 | kind, | 255 | kind, |
255 | access: reference_access(&d, &name_ref), | 256 | access: reference_access(&def, &name_ref), |
256 | }); | 257 | }); |
257 | } | 258 | } |
259 | Some(NameRefClass::FieldShorthand { local, field }) => { | ||
260 | match self { | ||
261 | Definition::StructField(_) if &field == self => refs.push(Reference { | ||
262 | file_range: sema.original_range(name_ref.syntax()), | ||
263 | kind: ReferenceKind::StructFieldShorthandForField, | ||
264 | access: reference_access(&field, &name_ref), | ||
265 | }), | ||
266 | Definition::Local(l) if &local == l => refs.push(Reference { | ||
267 | file_range: sema.original_range(name_ref.syntax()), | ||
268 | kind: ReferenceKind::StructFieldShorthandForLocal, | ||
269 | access: reference_access(&Definition::Local(local), &name_ref), | ||
270 | }), | ||
271 | |||
272 | _ => {} // not a usage | ||
273 | }; | ||
274 | } | ||
275 | _ => {} // not a usage | ||
258 | } | 276 | } |
259 | } | 277 | } |
260 | } | 278 | } |
diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs index e6b3126b6..884359ee3 100644 --- a/crates/ra_ide_db/src/symbol_index.rs +++ b/crates/ra_ide_db/src/symbol_index.rs | |||
@@ -163,7 +163,7 @@ pub fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec<FileSymb | |||
163 | #[derive(Default)] | 163 | #[derive(Default)] |
164 | pub struct SymbolIndex { | 164 | pub struct SymbolIndex { |
165 | symbols: Vec<FileSymbol>, | 165 | symbols: Vec<FileSymbol>, |
166 | map: fst::Map, | 166 | map: fst::Map<Vec<u8>>, |
167 | } | 167 | } |
168 | 168 | ||
169 | impl fmt::Debug for SymbolIndex { | 169 | impl fmt::Debug for SymbolIndex { |
@@ -221,7 +221,7 @@ impl SymbolIndex { | |||
221 | builder.insert(key, value).unwrap(); | 221 | builder.insert(key, value).unwrap(); |
222 | } | 222 | } |
223 | 223 | ||
224 | let map = fst::Map::from_bytes(builder.into_inner().unwrap()).unwrap(); | 224 | let map = fst::Map::new(builder.into_inner().unwrap()).unwrap(); |
225 | SymbolIndex { symbols, map } | 225 | SymbolIndex { symbols, map } |
226 | } | 226 | } |
227 | 227 | ||