Skip to content

Commit 14094e4

Browse files
committed
Move FeatureFlags
1 parent bf582e7 commit 14094e4

File tree

8 files changed

+24
-42
lines changed

8 files changed

+24
-42
lines changed

crates/ra_ide/src/lib.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ pub use ra_db::{
8484
};
8585
pub use ra_ide_db::{
8686
change::{AnalysisChange, LibraryData},
87-
feature_flags::FeatureFlags,
8887
line_index::{LineCol, LineIndex},
8988
line_index_utils::translate_offset_with_edit,
9089
search::SearchScope,
@@ -131,24 +130,20 @@ pub struct AnalysisHost {
131130

132131
impl Default for AnalysisHost {
133132
fn default() -> AnalysisHost {
134-
AnalysisHost::new(None, FeatureFlags::default())
133+
AnalysisHost::new(None)
135134
}
136135
}
137136

138137
impl AnalysisHost {
139-
pub fn new(lru_capcity: Option<usize>, feature_flags: FeatureFlags) -> AnalysisHost {
140-
AnalysisHost { db: RootDatabase::new(lru_capcity, feature_flags) }
138+
pub fn new(lru_capacity: Option<usize>) -> AnalysisHost {
139+
AnalysisHost { db: RootDatabase::new(lru_capacity) }
141140
}
142141
/// Returns a snapshot of the current state, which you can query for
143142
/// semantic information.
144143
pub fn analysis(&self) -> Analysis {
145144
Analysis { db: self.db.snapshot() }
146145
}
147146

148-
pub fn feature_flags(&self) -> &FeatureFlags {
149-
&self.db.feature_flags
150-
}
151-
152147
/// Applies changes to the current state of the world. If there are
153148
/// outstanding snapshots, they will be canceled.
154149
pub fn apply_change(&mut self, change: AnalysisChange) {
@@ -224,11 +219,6 @@ impl Analysis {
224219
(host.analysis(), file_id)
225220
}
226221

227-
/// Features for Analysis.
228-
pub fn feature_flags(&self) -> &FeatureFlags {
229-
&self.db.feature_flags
230-
}
231-
232222
/// Debug info about the current state of the analysis.
233223
pub fn status(&self) -> Cancelable<String> {
234224
self.with_db(|db| status::status(&*db))

crates/ra_ide_db/src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
pub mod marks;
66
pub mod line_index;
77
pub mod line_index_utils;
8-
pub mod feature_flags;
98
pub mod symbol_index;
109
pub mod change;
1110
pub mod defs;
@@ -22,7 +21,7 @@ use ra_db::{
2221
};
2322
use rustc_hash::FxHashMap;
2423

25-
use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase};
24+
use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase};
2625

2726
#[salsa::database(
2827
ra_db::SourceDatabaseStorage,
@@ -37,7 +36,6 @@ use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::Sy
3736
#[derive(Debug)]
3837
pub struct RootDatabase {
3938
runtime: salsa::Runtime<RootDatabase>,
40-
pub feature_flags: Arc<FeatureFlags>,
4139
pub(crate) debug_data: Arc<DebugData>,
4240
pub last_gc: crate::wasm_shims::Instant,
4341
pub last_gc_check: crate::wasm_shims::Instant,
@@ -82,17 +80,16 @@ impl salsa::Database for RootDatabase {
8280

8381
impl Default for RootDatabase {
8482
fn default() -> RootDatabase {
85-
RootDatabase::new(None, FeatureFlags::default())
83+
RootDatabase::new(None)
8684
}
8785
}
8886

8987
impl RootDatabase {
90-
pub fn new(lru_capacity: Option<usize>, feature_flags: FeatureFlags) -> RootDatabase {
88+
pub fn new(lru_capacity: Option<usize>) -> RootDatabase {
9189
let mut db = RootDatabase {
9290
runtime: salsa::Runtime::default(),
9391
last_gc: crate::wasm_shims::Instant::now(),
9492
last_gc_check: crate::wasm_shims::Instant::now(),
95-
feature_flags: Arc::new(feature_flags),
9693
debug_data: Default::default(),
9794
};
9895
db.set_crate_graph_with_durability(Default::default(), Durability::HIGH);
@@ -112,7 +109,6 @@ impl salsa::ParallelDatabase for RootDatabase {
112109
runtime: self.runtime.snapshot(self),
113110
last_gc: self.last_gc,
114111
last_gc_check: self.last_gc_check,
115-
feature_flags: Arc::clone(&self.feature_flags),
116112
debug_data: Arc::clone(&self.debug_data),
117113
})
118114
}

crates/rust-analyzer/src/cli/load_cargo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::Path;
66
use anyhow::Result;
77
use crossbeam_channel::{unbounded, Receiver};
88
use ra_db::{CrateGraph, FileId, SourceRootId};
9-
use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags};
9+
use ra_ide::{AnalysisChange, AnalysisHost};
1010
use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace};
1111
use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch};
1212
use rustc_hash::{FxHashMap, FxHashSet};
@@ -82,7 +82,7 @@ pub(crate) fn load(
8282
receiver: Receiver<VfsTask>,
8383
) -> AnalysisHost {
8484
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);
8686
let mut analysis_change = AnalysisChange::new();
8787
analysis_change.set_crate_graph(crate_graph);
8888

crates/rust-analyzer/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mod config;
3737
mod world;
3838
mod diagnostics;
3939
mod semantic_tokens;
40+
mod feature_flags;
4041

4142
use serde::de::DeserializeOwned;
4243

crates/rust-analyzer/src/main_loop.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crossbeam_channel::{select, unbounded, RecvError, Sender};
1818
use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
1919
use lsp_types::{ClientCapabilities, NumberOrString};
2020
use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckTask};
21-
use ra_ide::{Canceled, FeatureFlags, FileId, LibraryData, SourceRootId};
21+
use ra_ide::{Canceled, FileId, LibraryData, SourceRootId};
2222
use ra_prof::profile;
2323
use ra_vfs::{VfsFile, VfsTask, Watch};
2424
use relative_path::RelativePathBuf;
@@ -28,6 +28,7 @@ use threadpool::ThreadPool;
2828

2929
use crate::{
3030
diagnostics::DiagnosticTask,
31+
feature_flags::FeatureFlags,
3132
main_loop::{
3233
pending_requests::{PendingRequest, PendingRequests},
3334
subscriptions::Subscriptions,
@@ -423,7 +424,7 @@ fn loop_turn(
423424
{
424425
loop_state.workspace_loaded = true;
425426
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") {
427428
let msg = format!("workspace loaded, {} rust packages", n_packages);
428429
show_message(req::MessageType::Info, msg, &connection.sender);
429430
}
@@ -839,7 +840,7 @@ fn update_file_notifications_on_threadpool(
839840
subscriptions: Vec<FileId>,
840841
) {
841842
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");
843844
pool.execute(move || {
844845
for file_id in subscriptions {
845846
if publish_diagnostics {

crates/rust-analyzer/src/main_loop/handlers.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,10 @@ pub fn handle_completion(
425425
}
426426

427427
let options = CompletionOptions {
428-
enable_postfix_completions: world.feature_flags().get("completion.enable-postfix"),
429-
add_call_parenthesis: world
430-
.feature_flags()
431-
.get("completion.insertion.add-call-parenthesis"),
428+
enable_postfix_completions: world.feature_flags.get("completion.enable-postfix"),
429+
add_call_parenthesis: world.feature_flags.get("completion.insertion.add-call-parenthesis"),
432430
add_call_argument_snippets: world
433-
.feature_flags()
431+
.feature_flags
434432
.get("completion.insertion.add-argument-snippets"),
435433
};
436434

@@ -471,7 +469,7 @@ pub fn handle_signature_help(
471469
let _p = profile("handle_signature_help");
472470
let position = params.try_conv_with(&world)?;
473471
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");
475473
let mut active_parameter = call_info.active_parameter.map(|it| it as i64);
476474
if concise && call_info.signature.has_self_param {
477475
active_parameter = active_parameter.map(|it| it.saturating_sub(1));

crates/rust-analyzer/src/world.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ use lsp_types::Url;
1313
use parking_lot::RwLock;
1414
use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher};
1515
use ra_ide::{
16-
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FeatureFlags, FileId, LibraryData,
17-
SourceRootId,
16+
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId,
1817
};
1918
use ra_project_model::{get_rustc_cfg_options, ProjectWorkspace};
2019
use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch};
2120
use relative_path::RelativePathBuf;
2221

2322
use crate::{
2423
diagnostics::{CheckFixes, DiagnosticCollection},
24+
feature_flags::FeatureFlags,
2525
main_loop::pending_requests::{CompletedRequest, LatestRequests},
2626
vfs_glob::{Glob, RustPackageFilterBuilder},
2727
LspError, Result,
@@ -45,6 +45,7 @@ pub struct Options {
4545
#[derive(Debug)]
4646
pub struct WorldState {
4747
pub options: Options,
48+
pub feature_flags: Arc<FeatureFlags>,
4849
//FIXME: this belongs to `LoopState` rather than to `WorldState`
4950
pub roots_to_scan: usize,
5051
pub roots: Vec<PathBuf>,
@@ -60,6 +61,7 @@ pub struct WorldState {
6061
/// An immutable snapshot of the world's state at a point in time.
6162
pub struct WorldSnapshot {
6263
pub options: Options,
64+
pub feature_flags: Arc<FeatureFlags>,
6365
pub workspaces: Arc<Vec<ProjectWorkspace>>,
6466
pub analysis: Analysis,
6567
pub latest_requests: Arc<RwLock<LatestRequests>>,
@@ -146,10 +148,11 @@ impl WorldState {
146148
CheckWatcher::dummy()
147149
});
148150

149-
let mut analysis_host = AnalysisHost::new(lru_capacity, feature_flags);
151+
let mut analysis_host = AnalysisHost::new(lru_capacity);
150152
analysis_host.apply_change(change);
151153
WorldState {
152154
options,
155+
feature_flags: Arc::new(feature_flags),
153156
roots_to_scan,
154157
roots: folder_roots,
155158
workspaces: Arc::new(workspaces),
@@ -216,6 +219,7 @@ impl WorldState {
216219
pub fn snapshot(&self) -> WorldSnapshot {
217220
WorldSnapshot {
218221
options: self.options.clone(),
222+
feature_flags: Arc::clone(&self.feature_flags),
219223
workspaces: Arc::clone(&self.workspaces),
220224
analysis: self.analysis_host.analysis(),
221225
vfs: Arc::clone(&self.vfs),
@@ -235,10 +239,6 @@ impl WorldState {
235239
pub fn complete_request(&mut self, request: CompletedRequest) {
236240
self.latest_requests.write().record(request)
237241
}
238-
239-
pub fn feature_flags(&self) -> &FeatureFlags {
240-
self.analysis_host.feature_flags()
241-
}
242242
}
243243

244244
impl WorldSnapshot {
@@ -306,8 +306,4 @@ impl WorldSnapshot {
306306
let path = self.vfs.read().file2path(VfsFile(file_id.0));
307307
self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path))
308308
}
309-
310-
pub fn feature_flags(&self) -> &FeatureFlags {
311-
self.analysis.feature_flags()
312-
}
313309
}

0 commit comments

Comments
 (0)