aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/lib.rs16
-rw-r--r--crates/ra_ide_db/src/lib.rs10
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs4
-rw-r--r--crates/rust-analyzer/src/feature_flags.rs (renamed from crates/ra_ide_db/src/feature_flags.rs)0
-rw-r--r--crates/rust-analyzer/src/lib.rs1
-rw-r--r--crates/rust-analyzer/src/main_loop.rs7
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs10
-rw-r--r--crates/rust-analyzer/src/world.rs18
8 files changed, 24 insertions, 42 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index d888bb745..9f45003d3 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -84,7 +84,6 @@ pub use ra_db::{
84}; 84};
85pub use ra_ide_db::{ 85pub use ra_ide_db::{
86 change::{AnalysisChange, LibraryData}, 86 change::{AnalysisChange, LibraryData},
87 feature_flags::FeatureFlags,
88 line_index::{LineCol, LineIndex}, 87 line_index::{LineCol, LineIndex},
89 line_index_utils::translate_offset_with_edit, 88 line_index_utils::translate_offset_with_edit,
90 search::SearchScope, 89 search::SearchScope,
@@ -131,13 +130,13 @@ pub struct AnalysisHost {
131 130
132impl Default for AnalysisHost { 131impl Default for AnalysisHost {
133 fn default() -> AnalysisHost { 132 fn default() -> AnalysisHost {
134 AnalysisHost::new(None, FeatureFlags::default()) 133 AnalysisHost::new(None)
135 } 134 }
136} 135}
137 136
138impl AnalysisHost { 137impl AnalysisHost {
139 pub fn new(lru_capcity: Option<usize>, feature_flags: FeatureFlags) -> AnalysisHost { 138 pub fn new(lru_capacity: Option<usize>) -> AnalysisHost {
140 AnalysisHost { db: RootDatabase::new(lru_capcity, feature_flags) } 139 AnalysisHost { db: RootDatabase::new(lru_capacity) }
141 } 140 }
142 /// Returns a snapshot of the current state, which you can query for 141 /// Returns a snapshot of the current state, which you can query for
143 /// semantic information. 142 /// semantic information.
@@ -145,10 +144,6 @@ impl AnalysisHost {
145 Analysis { db: self.db.snapshot() } 144 Analysis { db: self.db.snapshot() }
146 } 145 }
147 146
148 pub fn feature_flags(&self) -> &FeatureFlags {
149 &self.db.feature_flags
150 }
151
152 /// Applies changes to the current state of the world. If there are 147 /// Applies changes to the current state of the world. If there are
153 /// outstanding snapshots, they will be canceled. 148 /// outstanding snapshots, they will be canceled.
154 pub fn apply_change(&mut self, change: AnalysisChange) { 149 pub fn apply_change(&mut self, change: AnalysisChange) {
@@ -224,11 +219,6 @@ impl Analysis {
224 (host.analysis(), file_id) 219 (host.analysis(), file_id)
225 } 220 }
226 221
227 /// Features for Analysis.
228 pub fn feature_flags(&self) -> &FeatureFlags {
229 &self.db.feature_flags
230 }
231
232 /// Debug info about the current state of the analysis. 222 /// Debug info about the current state of the analysis.
233 pub fn status(&self) -> Cancelable<String> { 223 pub fn status(&self) -> Cancelable<String> {
234 self.with_db(|db| status::status(&*db)) 224 self.with_db(|db| status::status(&*db))
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs
index a105c7556..6bcccc848 100644
--- a/crates/ra_ide_db/src/lib.rs
+++ b/crates/ra_ide_db/src/lib.rs
@@ -5,7 +5,6 @@
5pub mod marks; 5pub mod marks;
6pub mod line_index; 6pub mod line_index;
7pub mod line_index_utils; 7pub mod line_index_utils;
8pub mod feature_flags;
9pub mod symbol_index; 8pub mod symbol_index;
10pub mod change; 9pub mod change;
11pub mod defs; 10pub mod defs;
@@ -22,7 +21,7 @@ use ra_db::{
22}; 21};
23use rustc_hash::FxHashMap; 22use rustc_hash::FxHashMap;
24 23
25use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase}; 24use 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)]
38pub struct RootDatabase { 37pub 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,
@@ -82,17 +80,16 @@ impl salsa::Database for RootDatabase {
82 80
83impl Default for RootDatabase { 81impl Default for RootDatabase {
84 fn default() -> RootDatabase { 82 fn default() -> RootDatabase {
85 RootDatabase::new(None, FeatureFlags::default()) 83 RootDatabase::new(None)
86 } 84 }
87} 85}
88 86
89impl RootDatabase { 87impl RootDatabase {
90 pub fn new(lru_capacity: Option<usize>, feature_flags: FeatureFlags) -> RootDatabase { 88 pub fn new(lru_capacity: Option<usize>) -> RootDatabase {
91 let mut db = RootDatabase { 89 let mut db = RootDatabase {
92 runtime: salsa::Runtime::default(), 90 runtime: salsa::Runtime::default(),
93 last_gc: crate::wasm_shims::Instant::now(), 91 last_gc: crate::wasm_shims::Instant::now(),
94 last_gc_check: crate::wasm_shims::Instant::now(), 92 last_gc_check: crate::wasm_shims::Instant::now(),
95 feature_flags: Arc::new(feature_flags),
96 debug_data: Default::default(), 93 debug_data: Default::default(),
97 }; 94 };
98 db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); 95 db.set_crate_graph_with_durability(Default::default(), Durability::HIGH);
@@ -112,7 +109,6 @@ impl salsa::ParallelDatabase for RootDatabase {
112 runtime: self.runtime.snapshot(self), 109 runtime: self.runtime.snapshot(self),
113 last_gc: self.last_gc, 110 last_gc: self.last_gc,
114 last_gc_check: self.last_gc_check, 111 last_gc_check: self.last_gc_check,
115 feature_flags: Arc::clone(&self.feature_flags),
116 debug_data: Arc::clone(&self.debug_data), 112 debug_data: Arc::clone(&self.debug_data),
117 }) 113 })
118 } 114 }
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index 4be987860..5df29a383 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -6,7 +6,7 @@ use std::path::Path;
6use anyhow::Result; 6use anyhow::Result;
7use crossbeam_channel::{unbounded, Receiver}; 7use crossbeam_channel::{unbounded, Receiver};
8use ra_db::{CrateGraph, FileId, SourceRootId}; 8use ra_db::{CrateGraph, FileId, SourceRootId};
9use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags}; 9use ra_ide::{AnalysisChange, AnalysisHost};
10use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; 10use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace};
11use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; 11use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch};
12use rustc_hash::{FxHashMap, FxHashSet}; 12use rustc_hash::{FxHashMap, FxHashSet};
@@ -82,7 +82,7 @@ pub(crate) fn load(
82 receiver: Receiver<VfsTask>, 82 receiver: Receiver<VfsTask>,
83) -> AnalysisHost { 83) -> AnalysisHost {
84 let lru_cap = std::env::var("RA_LRU_CAP").ok().and_then(|it| it.parse::<usize>().ok()); 84 let lru_cap = std::env::var("RA_LRU_CAP").ok().and_then(|it| it.parse::<usize>().ok());
85 let mut host = AnalysisHost::new(lru_cap, FeatureFlags::default()); 85 let mut host = AnalysisHost::new(lru_cap);
86 let mut analysis_change = AnalysisChange::new(); 86 let mut analysis_change = AnalysisChange::new();
87 analysis_change.set_crate_graph(crate_graph); 87 analysis_change.set_crate_graph(crate_graph);
88 88
diff --git a/crates/ra_ide_db/src/feature_flags.rs b/crates/rust-analyzer/src/feature_flags.rs
index dbb3f50a0..dbb3f50a0 100644
--- a/crates/ra_ide_db/src/feature_flags.rs
+++ b/crates/rust-analyzer/src/feature_flags.rs
diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs
index a0f968823..e50e47b19 100644
--- a/crates/rust-analyzer/src/lib.rs
+++ b/crates/rust-analyzer/src/lib.rs
@@ -37,6 +37,7 @@ mod config;
37mod world; 37mod world;
38mod diagnostics; 38mod diagnostics;
39mod semantic_tokens; 39mod semantic_tokens;
40mod feature_flags;
40 41
41use serde::de::DeserializeOwned; 42use serde::de::DeserializeOwned;
42 43
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 221f464b6..f9de712a0 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -18,7 +18,7 @@ use crossbeam_channel::{select, unbounded, RecvError, Sender};
18use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; 18use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
19use lsp_types::{ClientCapabilities, NumberOrString}; 19use lsp_types::{ClientCapabilities, NumberOrString};
20use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckTask}; 20use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckTask};
21use ra_ide::{Canceled, FeatureFlags, FileId, LibraryData, SourceRootId}; 21use ra_ide::{Canceled, FileId, LibraryData, SourceRootId};
22use ra_prof::profile; 22use ra_prof::profile;
23use ra_vfs::{VfsFile, VfsTask, Watch}; 23use ra_vfs::{VfsFile, VfsTask, Watch};
24use relative_path::RelativePathBuf; 24use relative_path::RelativePathBuf;
@@ -28,6 +28,7 @@ use threadpool::ThreadPool;
28 28
29use crate::{ 29use crate::{
30 diagnostics::DiagnosticTask, 30 diagnostics::DiagnosticTask,
31 feature_flags::FeatureFlags,
31 main_loop::{ 32 main_loop::{
32 pending_requests::{PendingRequest, PendingRequests}, 33 pending_requests::{PendingRequest, PendingRequests},
33 subscriptions::Subscriptions, 34 subscriptions::Subscriptions,
@@ -423,7 +424,7 @@ fn loop_turn(
423 { 424 {
424 loop_state.workspace_loaded = true; 425 loop_state.workspace_loaded = true;
425 let n_packages: usize = world_state.workspaces.iter().map(|it| it.n_packages()).sum(); 426 let n_packages: usize = world_state.workspaces.iter().map(|it| it.n_packages()).sum();
426 if world_state.feature_flags().get("notifications.workspace-loaded") { 427 if world_state.feature_flags.get("notifications.workspace-loaded") {
427 let msg = format!("workspace loaded, {} rust packages", n_packages); 428 let msg = format!("workspace loaded, {} rust packages", n_packages);
428 show_message(req::MessageType::Info, msg, &connection.sender); 429 show_message(req::MessageType::Info, msg, &connection.sender);
429 } 430 }
@@ -839,7 +840,7 @@ fn update_file_notifications_on_threadpool(
839 subscriptions: Vec<FileId>, 840 subscriptions: Vec<FileId>,
840) { 841) {
841 log::trace!("updating notifications for {:?}", subscriptions); 842 log::trace!("updating notifications for {:?}", subscriptions);
842 let publish_diagnostics = world.feature_flags().get("lsp.diagnostics"); 843 let publish_diagnostics = world.feature_flags.get("lsp.diagnostics");
843 pool.execute(move || { 844 pool.execute(move || {
844 for file_id in subscriptions { 845 for file_id in subscriptions {
845 if publish_diagnostics { 846 if publish_diagnostics {
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index 155f677a6..fcb40432d 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -425,12 +425,10 @@ pub fn handle_completion(
425 } 425 }
426 426
427 let options = CompletionOptions { 427 let options = CompletionOptions {
428 enable_postfix_completions: world.feature_flags().get("completion.enable-postfix"), 428 enable_postfix_completions: world.feature_flags.get("completion.enable-postfix"),
429 add_call_parenthesis: world 429 add_call_parenthesis: world.feature_flags.get("completion.insertion.add-call-parenthesis"),
430 .feature_flags()
431 .get("completion.insertion.add-call-parenthesis"),
432 add_call_argument_snippets: world 430 add_call_argument_snippets: world
433 .feature_flags() 431 .feature_flags
434 .get("completion.insertion.add-argument-snippets"), 432 .get("completion.insertion.add-argument-snippets"),
435 }; 433 };
436 434
@@ -471,7 +469,7 @@ pub fn handle_signature_help(
471 let _p = profile("handle_signature_help"); 469 let _p = profile("handle_signature_help");
472 let position = params.try_conv_with(&world)?; 470 let position = params.try_conv_with(&world)?;
473 if let Some(call_info) = world.analysis().call_info(position)? { 471 if let Some(call_info) = world.analysis().call_info(position)? {
474 let concise = !world.analysis().feature_flags().get("call-info.full"); 472 let concise = !world.feature_flags.get("call-info.full");
475 let mut active_parameter = call_info.active_parameter.map(|it| it as i64); 473 let mut active_parameter = call_info.active_parameter.map(|it| it as i64);
476 if concise && call_info.signature.has_self_param { 474 if concise && call_info.signature.has_self_param {
477 active_parameter = active_parameter.map(|it| it.saturating_sub(1)); 475 active_parameter = active_parameter.map(|it| it.saturating_sub(1));
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs
index 6f394055a..1ddc3c1a5 100644
--- a/crates/rust-analyzer/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -13,8 +13,7 @@ use lsp_types::Url;
13use parking_lot::RwLock; 13use parking_lot::RwLock;
14use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher}; 14use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher};
15use ra_ide::{ 15use ra_ide::{
16 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FeatureFlags, FileId, LibraryData, 16 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId,
17 SourceRootId,
18}; 17};
19use ra_project_model::{get_rustc_cfg_options, ProjectWorkspace}; 18use ra_project_model::{get_rustc_cfg_options, ProjectWorkspace};
20use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch}; 19use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch};
@@ -22,6 +21,7 @@ use relative_path::RelativePathBuf;
22 21
23use crate::{ 22use crate::{
24 diagnostics::{CheckFixes, DiagnosticCollection}, 23 diagnostics::{CheckFixes, DiagnosticCollection},
24 feature_flags::FeatureFlags,
25 main_loop::pending_requests::{CompletedRequest, LatestRequests}, 25 main_loop::pending_requests::{CompletedRequest, LatestRequests},
26 vfs_glob::{Glob, RustPackageFilterBuilder}, 26 vfs_glob::{Glob, RustPackageFilterBuilder},
27 LspError, Result, 27 LspError, Result,
@@ -45,6 +45,7 @@ pub struct Options {
45#[derive(Debug)] 45#[derive(Debug)]
46pub struct WorldState { 46pub struct WorldState {
47 pub options: Options, 47 pub options: Options,
48 pub feature_flags: Arc<FeatureFlags>,
48 //FIXME: this belongs to `LoopState` rather than to `WorldState` 49 //FIXME: this belongs to `LoopState` rather than to `WorldState`
49 pub roots_to_scan: usize, 50 pub roots_to_scan: usize,
50 pub roots: Vec<PathBuf>, 51 pub roots: Vec<PathBuf>,
@@ -60,6 +61,7 @@ pub struct WorldState {
60/// An immutable snapshot of the world's state at a point in time. 61/// An immutable snapshot of the world's state at a point in time.
61pub struct WorldSnapshot { 62pub struct WorldSnapshot {
62 pub options: Options, 63 pub options: Options,
64 pub feature_flags: Arc<FeatureFlags>,
63 pub workspaces: Arc<Vec<ProjectWorkspace>>, 65 pub workspaces: Arc<Vec<ProjectWorkspace>>,
64 pub analysis: Analysis, 66 pub analysis: Analysis,
65 pub latest_requests: Arc<RwLock<LatestRequests>>, 67 pub latest_requests: Arc<RwLock<LatestRequests>>,
@@ -146,10 +148,11 @@ impl WorldState {
146 CheckWatcher::dummy() 148 CheckWatcher::dummy()
147 }); 149 });
148 150
149 let mut analysis_host = AnalysisHost::new(lru_capacity, feature_flags); 151 let mut analysis_host = AnalysisHost::new(lru_capacity);
150 analysis_host.apply_change(change); 152 analysis_host.apply_change(change);
151 WorldState { 153 WorldState {
152 options, 154 options,
155 feature_flags: Arc::new(feature_flags),
153 roots_to_scan, 156 roots_to_scan,
154 roots: folder_roots, 157 roots: folder_roots,
155 workspaces: Arc::new(workspaces), 158 workspaces: Arc::new(workspaces),
@@ -216,6 +219,7 @@ impl WorldState {
216 pub fn snapshot(&self) -> WorldSnapshot { 219 pub fn snapshot(&self) -> WorldSnapshot {
217 WorldSnapshot { 220 WorldSnapshot {
218 options: self.options.clone(), 221 options: self.options.clone(),
222 feature_flags: Arc::clone(&self.feature_flags),
219 workspaces: Arc::clone(&self.workspaces), 223 workspaces: Arc::clone(&self.workspaces),
220 analysis: self.analysis_host.analysis(), 224 analysis: self.analysis_host.analysis(),
221 vfs: Arc::clone(&self.vfs), 225 vfs: Arc::clone(&self.vfs),
@@ -235,10 +239,6 @@ impl WorldState {
235 pub fn complete_request(&mut self, request: CompletedRequest) { 239 pub fn complete_request(&mut self, request: CompletedRequest) {
236 self.latest_requests.write().record(request) 240 self.latest_requests.write().record(request)
237 } 241 }
238
239 pub fn feature_flags(&self) -> &FeatureFlags {
240 self.analysis_host.feature_flags()
241 }
242} 242}
243 243
244impl WorldSnapshot { 244impl WorldSnapshot {
@@ -306,8 +306,4 @@ impl WorldSnapshot {
306 let path = self.vfs.read().file2path(VfsFile(file_id.0)); 306 let path = self.vfs.read().file2path(VfsFile(file_id.0));
307 self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path)) 307 self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path))
308 } 308 }
309
310 pub fn feature_flags(&self) -> &FeatureFlags {
311 self.analysis.feature_flags()
312 }
313} 309}