Skip to content

Commit 797cd34

Browse files
committed
Reduce feature flags
1 parent facdf56 commit 797cd34

File tree

4 files changed

+48
-52
lines changed

4 files changed

+48
-52
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,35 @@
99
1010
use rustc_hash::FxHashMap;
1111

12+
use crate::feature_flags::FeatureFlags;
1213
use lsp_types::TextDocumentClientCapabilities;
1314
use ra_flycheck::FlycheckConfig;
14-
use ra_ide::InlayHintsConfig;
15+
use ra_ide::{CompletionConfig, InlayHintsConfig};
1516
use ra_project_model::CargoFeatures;
1617
use serde::{Deserialize, Deserializer};
1718

1819
#[derive(Debug, Clone)]
1920
pub struct Config {
2021
pub publish_decorations: bool,
22+
pub publish_diagnostics: bool,
23+
pub notifications: NotificationsConfig,
2124
pub supports_location_link: bool,
2225
pub line_folding_only: bool,
2326
pub inlay_hints: InlayHintsConfig,
27+
pub completion: CompletionConfig,
28+
pub call_info_full: bool,
2429
pub rustfmt: RustfmtConfig,
2530
pub check: Option<FlycheckConfig>,
2631
pub vscode_lldb: bool,
2732
pub proc_macro_srv: Option<String>,
2833
}
2934

35+
#[derive(Debug, Clone)]
36+
pub struct NotificationsConfig {
37+
pub workspace_loaded: bool,
38+
pub cargo_toml_not_found: bool,
39+
}
40+
3041
#[derive(Debug, Clone)]
3142
pub enum RustfmtConfig {
3243
Rustfmt {
@@ -49,8 +60,14 @@ pub(crate) fn get_config(
4960
config: &ServerConfig,
5061
text_document_caps: Option<&TextDocumentClientCapabilities>,
5162
) -> Config {
63+
let feature_flags = get_feature_flags(config);
5264
Config {
5365
publish_decorations: config.publish_decorations,
66+
publish_diagnostics: feature_flags.get("lsp.diagnostics"),
67+
notifications: NotificationsConfig {
68+
workspace_loaded: feature_flags.get("notifications.workspace-loaded"),
69+
cargo_toml_not_found: feature_flags.get("notifications.cargo-toml-not-found"),
70+
},
5471
supports_location_link: text_document_caps
5572
.and_then(|it| it.definition)
5673
.and_then(|it| it.link_support)
@@ -65,6 +82,13 @@ pub(crate) fn get_config(
6582
chaining_hints: config.inlay_hints_chaining,
6683
max_length: config.inlay_hints_max_length,
6784
},
85+
completion: CompletionConfig {
86+
enable_postfix_completions: feature_flags.get("completion.enable-postfix"),
87+
add_call_parenthesis: feature_flags.get("completion.insertion.add-call-parenthesis"),
88+
add_call_argument_snippets: feature_flags
89+
.get("completion.insertion.add-argument-snippets"),
90+
},
91+
call_info_full: feature_flags.get("call-info.full"),
6892
check: if config.cargo_watch_enable {
6993
Some(FlycheckConfig::CargoCommand {
7094
command: config.cargo_watch_command.clone(),
@@ -80,6 +104,17 @@ pub(crate) fn get_config(
80104
}
81105
}
82106

107+
fn get_feature_flags(config: &ServerConfig) -> FeatureFlags {
108+
let mut ff = FeatureFlags::default();
109+
for (flag, &value) in &config.feature_flags {
110+
if ff.set(flag.as_str(), value).is_err() {
111+
log::error!("unknown feature flag: {:?}", flag);
112+
}
113+
}
114+
log::info!("feature_flags: {:#?}", ff);
115+
ff
116+
}
117+
83118
/// Client provided initialization options
84119
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
85120
#[serde(rename_all = "camelCase", default)]

crates/rust-analyzer/src/main_loop.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use threadpool::ThreadPool;
3333
use crate::{
3434
config::get_config,
3535
diagnostics::DiagnosticTask,
36-
feature_flags::FeatureFlags,
3736
main_loop::{
3837
pending_requests::{PendingRequest, PendingRequests},
3938
subscriptions::Subscriptions,
@@ -66,22 +65,6 @@ impl fmt::Display for LspError {
6665

6766
impl Error for LspError {}
6867

69-
fn get_feature_flags(config: &ServerConfig, connection: &Connection) -> FeatureFlags {
70-
let mut ff = FeatureFlags::default();
71-
for (flag, &value) in &config.feature_flags {
72-
if ff.set(flag.as_str(), value).is_err() {
73-
log::error!("unknown feature flag: {:?}", flag);
74-
show_message(
75-
req::MessageType::Error,
76-
format!("unknown feature flag: {:?}", flag),
77-
&connection.sender,
78-
);
79-
}
80-
}
81-
log::info!("feature_flags: {:#?}", ff);
82-
ff
83-
}
84-
8568
pub fn main_loop(
8669
ws_roots: Vec<PathBuf>,
8770
client_caps: ClientCapabilities,
@@ -112,8 +95,8 @@ pub fn main_loop(
11295
let text_document_caps = client_caps.text_document.as_ref();
11396
let mut loop_state = LoopState::default();
11497
let mut world_state = {
115-
let feature_flags = get_feature_flags(&config, &connection);
116-
98+
// TODO: refactor
99+
let new_config = get_config(&config, text_document_caps);
117100
// FIXME: support dynamic workspace loading.
118101
let workspaces = {
119102
let mut loaded_workspaces = Vec::new();
@@ -131,7 +114,7 @@ pub fn main_loop(
131114
if let Some(ra_project_model::CargoTomlNotFoundError { .. }) =
132115
e.downcast_ref()
133116
{
134-
if !feature_flags.get("notifications.cargo-toml-not-found") {
117+
if !new_config.notifications.cargo_toml_not_found {
135118
continue;
136119
}
137120
}
@@ -180,8 +163,7 @@ pub fn main_loop(
180163
config.lru_capacity,
181164
&globs,
182165
Watch(!config.use_client_watching),
183-
get_config(&config, text_document_caps),
184-
feature_flags,
166+
new_config,
185167
)
186168
};
187169

@@ -406,7 +388,6 @@ fn loop_turn(
406388
world_state.update_configuration(
407389
new_config.lru_capacity,
408390
get_config(&new_config, text_document_caps),
409-
get_feature_flags(&new_config, connection),
410391
);
411392
}
412393
(None, Some(Err(e))) => {
@@ -441,8 +422,8 @@ fn loop_turn(
441422
});
442423
}
443424

444-
let show_progress = !loop_state.workspace_loaded
445-
&& world_state.feature_flags.get("notifications.workspace-loaded");
425+
let show_progress =
426+
!loop_state.workspace_loaded && world_state.config.notifications.workspace_loaded;
446427

447428
if !loop_state.workspace_loaded
448429
&& loop_state.roots_scanned == loop_state.roots_total
@@ -930,7 +911,7 @@ fn update_file_notifications_on_threadpool(
930911
subscriptions: Vec<FileId>,
931912
) {
932913
log::trace!("updating notifications for {:?}", subscriptions);
933-
let publish_diagnostics = world.feature_flags.get("lsp.diagnostics");
914+
let publish_diagnostics = world.config.publish_diagnostics;
934915
pool.execute(move || {
935916
for file_id in subscriptions {
936917
if publish_diagnostics {

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use lsp_types::{
1919
TextEdit, WorkspaceEdit,
2020
};
2121
use ra_ide::{
22-
Assist, AssistId, CompletionConfig, FileId, FilePosition, FileRange, Query, RangeInfo,
23-
Runnable, RunnableKind, SearchScope,
22+
Assist, AssistId, FileId, FilePosition, FileRange, Query, RangeInfo, Runnable, RunnableKind,
23+
SearchScope,
2424
};
2525
use ra_prof::profile;
2626
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
@@ -426,15 +426,7 @@ pub fn handle_completion(
426426
return Ok(None);
427427
}
428428

429-
let config = CompletionConfig {
430-
enable_postfix_completions: world.feature_flags.get("completion.enable-postfix"),
431-
add_call_parenthesis: world.feature_flags.get("completion.insertion.add-call-parenthesis"),
432-
add_call_argument_snippets: world
433-
.feature_flags
434-
.get("completion.insertion.add-argument-snippets"),
435-
};
436-
437-
let items = match world.analysis().completions(position, &config)? {
429+
let items = match world.analysis().completions(position, &world.config.completion)? {
438430
None => return Ok(None),
439431
Some(items) => items,
440432
};
@@ -471,7 +463,7 @@ pub fn handle_signature_help(
471463
let _p = profile("handle_signature_help");
472464
let position = params.try_conv_with(&world)?;
473465
if let Some(call_info) = world.analysis().call_info(position)? {
474-
let concise = !world.feature_flags.get("call-info.full");
466+
let concise = !world.config.call_info_full;
475467
let mut active_parameter = call_info.active_parameter.map(|it| it as i64);
476468
if concise && call_info.signature.has_self_param {
477469
active_parameter = active_parameter.map(|it| it.saturating_sub(1));

crates/rust-analyzer/src/world.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use stdx::format_to;
2323
use crate::{
2424
config::Config,
2525
diagnostics::{CheckFixes, DiagnosticCollection},
26-
feature_flags::FeatureFlags,
2726
main_loop::pending_requests::{CompletedRequest, LatestRequests},
2827
vfs_glob::{Glob, RustPackageFilterBuilder},
2928
LspError, Result,
@@ -59,7 +58,6 @@ fn create_flycheck(workspaces: &[ProjectWorkspace], config: &Config) -> Option<F
5958
#[derive(Debug)]
6059
pub struct WorldState {
6160
pub config: Config,
62-
pub feature_flags: Arc<FeatureFlags>,
6361
pub roots: Vec<PathBuf>,
6462
pub workspaces: Arc<Vec<ProjectWorkspace>>,
6563
pub analysis_host: AnalysisHost,
@@ -73,7 +71,6 @@ pub struct WorldState {
7371
/// An immutable snapshot of the world's state at a point in time.
7472
pub struct WorldSnapshot {
7573
pub config: Config,
76-
pub feature_flags: Arc<FeatureFlags>,
7774
pub workspaces: Arc<Vec<ProjectWorkspace>>,
7875
pub analysis: Analysis,
7976
pub latest_requests: Arc<RwLock<LatestRequests>>,
@@ -89,7 +86,6 @@ impl WorldState {
8986
exclude_globs: &[Glob],
9087
watch: Watch,
9188
config: Config,
92-
feature_flags: FeatureFlags,
9389
) -> WorldState {
9490
let mut change = AnalysisChange::new();
9591

@@ -197,7 +193,6 @@ impl WorldState {
197193
analysis_host.apply_change(change);
198194
WorldState {
199195
config: config,
200-
feature_flags: Arc::new(feature_flags),
201196
roots: folder_roots,
202197
workspaces: Arc::new(workspaces),
203198
analysis_host,
@@ -209,13 +204,7 @@ impl WorldState {
209204
}
210205
}
211206

212-
pub fn update_configuration(
213-
&mut self,
214-
lru_capacity: Option<usize>,
215-
config: Config,
216-
feature_flags: FeatureFlags,
217-
) {
218-
self.feature_flags = Arc::new(feature_flags);
207+
pub fn update_configuration(&mut self, lru_capacity: Option<usize>, config: Config) {
219208
self.analysis_host.update_lru_capacity(lru_capacity);
220209
self.flycheck = create_flycheck(&self.workspaces, &config);
221210
self.config = config;
@@ -275,7 +264,6 @@ impl WorldState {
275264
pub fn snapshot(&self) -> WorldSnapshot {
276265
WorldSnapshot {
277266
config: self.config.clone(),
278-
feature_flags: Arc::clone(&self.feature_flags),
279267
workspaces: Arc::clone(&self.workspaces),
280268
analysis: self.analysis_host.analysis(),
281269
vfs: Arc::clone(&self.vfs),

0 commit comments

Comments
 (0)