Reduce feature flags

This commit is contained in:
Aleksey Kladov 2020-04-01 17:00:37 +02:00
parent facdf56cf6
commit 797cd34c7c
4 changed files with 48 additions and 52 deletions

View file

@ -9,24 +9,35 @@
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use crate::feature_flags::FeatureFlags;
use lsp_types::TextDocumentClientCapabilities; use lsp_types::TextDocumentClientCapabilities;
use ra_flycheck::FlycheckConfig; use ra_flycheck::FlycheckConfig;
use ra_ide::InlayHintsConfig; use ra_ide::{CompletionConfig, InlayHintsConfig};
use ra_project_model::CargoFeatures; use ra_project_model::CargoFeatures;
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Config { pub struct Config {
pub publish_decorations: bool, pub publish_decorations: bool,
pub publish_diagnostics: bool,
pub notifications: NotificationsConfig,
pub supports_location_link: bool, pub supports_location_link: bool,
pub line_folding_only: bool, pub line_folding_only: bool,
pub inlay_hints: InlayHintsConfig, pub inlay_hints: InlayHintsConfig,
pub completion: CompletionConfig,
pub call_info_full: bool,
pub rustfmt: RustfmtConfig, pub rustfmt: RustfmtConfig,
pub check: Option<FlycheckConfig>, pub check: Option<FlycheckConfig>,
pub vscode_lldb: bool, pub vscode_lldb: bool,
pub proc_macro_srv: Option<String>, pub proc_macro_srv: Option<String>,
} }
#[derive(Debug, Clone)]
pub struct NotificationsConfig {
pub workspace_loaded: bool,
pub cargo_toml_not_found: bool,
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum RustfmtConfig { pub enum RustfmtConfig {
Rustfmt { Rustfmt {
@ -49,8 +60,14 @@ pub(crate) fn get_config(
config: &ServerConfig, config: &ServerConfig,
text_document_caps: Option<&TextDocumentClientCapabilities>, text_document_caps: Option<&TextDocumentClientCapabilities>,
) -> Config { ) -> Config {
let feature_flags = get_feature_flags(config);
Config { Config {
publish_decorations: config.publish_decorations, publish_decorations: config.publish_decorations,
publish_diagnostics: feature_flags.get("lsp.diagnostics"),
notifications: NotificationsConfig {
workspace_loaded: feature_flags.get("notifications.workspace-loaded"),
cargo_toml_not_found: feature_flags.get("notifications.cargo-toml-not-found"),
},
supports_location_link: text_document_caps supports_location_link: text_document_caps
.and_then(|it| it.definition) .and_then(|it| it.definition)
.and_then(|it| it.link_support) .and_then(|it| it.link_support)
@ -65,6 +82,13 @@ pub(crate) fn get_config(
chaining_hints: config.inlay_hints_chaining, chaining_hints: config.inlay_hints_chaining,
max_length: config.inlay_hints_max_length, max_length: config.inlay_hints_max_length,
}, },
completion: CompletionConfig {
enable_postfix_completions: feature_flags.get("completion.enable-postfix"),
add_call_parenthesis: feature_flags.get("completion.insertion.add-call-parenthesis"),
add_call_argument_snippets: feature_flags
.get("completion.insertion.add-argument-snippets"),
},
call_info_full: feature_flags.get("call-info.full"),
check: if config.cargo_watch_enable { check: if config.cargo_watch_enable {
Some(FlycheckConfig::CargoCommand { Some(FlycheckConfig::CargoCommand {
command: config.cargo_watch_command.clone(), command: config.cargo_watch_command.clone(),
@ -80,6 +104,17 @@ pub(crate) fn get_config(
} }
} }
fn get_feature_flags(config: &ServerConfig) -> FeatureFlags {
let mut ff = FeatureFlags::default();
for (flag, &value) in &config.feature_flags {
if ff.set(flag.as_str(), value).is_err() {
log::error!("unknown feature flag: {:?}", flag);
}
}
log::info!("feature_flags: {:#?}", ff);
ff
}
/// Client provided initialization options /// Client provided initialization options
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)] #[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]

View file

@ -33,7 +33,6 @@ use threadpool::ThreadPool;
use crate::{ use crate::{
config::get_config, config::get_config,
diagnostics::DiagnosticTask, diagnostics::DiagnosticTask,
feature_flags::FeatureFlags,
main_loop::{ main_loop::{
pending_requests::{PendingRequest, PendingRequests}, pending_requests::{PendingRequest, PendingRequests},
subscriptions::Subscriptions, subscriptions::Subscriptions,
@ -66,22 +65,6 @@ impl fmt::Display for LspError {
impl Error for LspError {} impl Error for LspError {}
fn get_feature_flags(config: &ServerConfig, connection: &Connection) -> FeatureFlags {
let mut ff = FeatureFlags::default();
for (flag, &value) in &config.feature_flags {
if ff.set(flag.as_str(), value).is_err() {
log::error!("unknown feature flag: {:?}", flag);
show_message(
req::MessageType::Error,
format!("unknown feature flag: {:?}", flag),
&connection.sender,
);
}
}
log::info!("feature_flags: {:#?}", ff);
ff
}
pub fn main_loop( pub fn main_loop(
ws_roots: Vec<PathBuf>, ws_roots: Vec<PathBuf>,
client_caps: ClientCapabilities, client_caps: ClientCapabilities,
@ -112,8 +95,8 @@ pub fn main_loop(
let text_document_caps = client_caps.text_document.as_ref(); let text_document_caps = client_caps.text_document.as_ref();
let mut loop_state = LoopState::default(); let mut loop_state = LoopState::default();
let mut world_state = { let mut world_state = {
let feature_flags = get_feature_flags(&config, &connection); // TODO: refactor
let new_config = get_config(&config, text_document_caps);
// FIXME: support dynamic workspace loading. // FIXME: support dynamic workspace loading.
let workspaces = { let workspaces = {
let mut loaded_workspaces = Vec::new(); let mut loaded_workspaces = Vec::new();
@ -131,7 +114,7 @@ pub fn main_loop(
if let Some(ra_project_model::CargoTomlNotFoundError { .. }) = if let Some(ra_project_model::CargoTomlNotFoundError { .. }) =
e.downcast_ref() e.downcast_ref()
{ {
if !feature_flags.get("notifications.cargo-toml-not-found") { if !new_config.notifications.cargo_toml_not_found {
continue; continue;
} }
} }
@ -180,8 +163,7 @@ pub fn main_loop(
config.lru_capacity, config.lru_capacity,
&globs, &globs,
Watch(!config.use_client_watching), Watch(!config.use_client_watching),
get_config(&config, text_document_caps), new_config,
feature_flags,
) )
}; };
@ -406,7 +388,6 @@ fn loop_turn(
world_state.update_configuration( world_state.update_configuration(
new_config.lru_capacity, new_config.lru_capacity,
get_config(&new_config, text_document_caps), get_config(&new_config, text_document_caps),
get_feature_flags(&new_config, connection),
); );
} }
(None, Some(Err(e))) => { (None, Some(Err(e))) => {
@ -441,8 +422,8 @@ fn loop_turn(
}); });
} }
let show_progress = !loop_state.workspace_loaded let show_progress =
&& world_state.feature_flags.get("notifications.workspace-loaded"); !loop_state.workspace_loaded && world_state.config.notifications.workspace_loaded;
if !loop_state.workspace_loaded if !loop_state.workspace_loaded
&& loop_state.roots_scanned == loop_state.roots_total && loop_state.roots_scanned == loop_state.roots_total
@ -930,7 +911,7 @@ fn update_file_notifications_on_threadpool(
subscriptions: Vec<FileId>, subscriptions: Vec<FileId>,
) { ) {
log::trace!("updating notifications for {:?}", subscriptions); log::trace!("updating notifications for {:?}", subscriptions);
let publish_diagnostics = world.feature_flags.get("lsp.diagnostics"); let publish_diagnostics = world.config.publish_diagnostics;
pool.execute(move || { pool.execute(move || {
for file_id in subscriptions { for file_id in subscriptions {
if publish_diagnostics { if publish_diagnostics {

View file

@ -19,8 +19,8 @@ use lsp_types::{
TextEdit, WorkspaceEdit, TextEdit, WorkspaceEdit,
}; };
use ra_ide::{ use ra_ide::{
Assist, AssistId, CompletionConfig, FileId, FilePosition, FileRange, Query, RangeInfo, Assist, AssistId, FileId, FilePosition, FileRange, Query, RangeInfo, Runnable, RunnableKind,
Runnable, RunnableKind, SearchScope, SearchScope,
}; };
use ra_prof::profile; use ra_prof::profile;
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
@ -426,15 +426,7 @@ pub fn handle_completion(
return Ok(None); return Ok(None);
} }
let config = CompletionConfig { let items = match world.analysis().completions(position, &world.config.completion)? {
enable_postfix_completions: world.feature_flags.get("completion.enable-postfix"),
add_call_parenthesis: world.feature_flags.get("completion.insertion.add-call-parenthesis"),
add_call_argument_snippets: world
.feature_flags
.get("completion.insertion.add-argument-snippets"),
};
let items = match world.analysis().completions(position, &config)? {
None => return Ok(None), None => return Ok(None),
Some(items) => items, Some(items) => items,
}; };
@ -471,7 +463,7 @@ pub fn handle_signature_help(
let _p = profile("handle_signature_help"); let _p = profile("handle_signature_help");
let position = params.try_conv_with(&world)?; let position = params.try_conv_with(&world)?;
if let Some(call_info) = world.analysis().call_info(position)? { if let Some(call_info) = world.analysis().call_info(position)? {
let concise = !world.feature_flags.get("call-info.full"); let concise = !world.config.call_info_full;
let mut active_parameter = call_info.active_parameter.map(|it| it as i64); let mut active_parameter = call_info.active_parameter.map(|it| it as i64);
if concise && call_info.signature.has_self_param { if concise && call_info.signature.has_self_param {
active_parameter = active_parameter.map(|it| it.saturating_sub(1)); active_parameter = active_parameter.map(|it| it.saturating_sub(1));

View file

@ -23,7 +23,6 @@ use stdx::format_to;
use crate::{ use crate::{
config::Config, config::Config,
diagnostics::{CheckFixes, DiagnosticCollection}, diagnostics::{CheckFixes, DiagnosticCollection},
feature_flags::FeatureFlags,
main_loop::pending_requests::{CompletedRequest, LatestRequests}, main_loop::pending_requests::{CompletedRequest, LatestRequests},
vfs_glob::{Glob, RustPackageFilterBuilder}, vfs_glob::{Glob, RustPackageFilterBuilder},
LspError, Result, LspError, Result,
@ -59,7 +58,6 @@ fn create_flycheck(workspaces: &[ProjectWorkspace], config: &Config) -> Option<F
#[derive(Debug)] #[derive(Debug)]
pub struct WorldState { pub struct WorldState {
pub config: Config, pub config: Config,
pub feature_flags: Arc<FeatureFlags>,
pub roots: Vec<PathBuf>, pub roots: Vec<PathBuf>,
pub workspaces: Arc<Vec<ProjectWorkspace>>, pub workspaces: Arc<Vec<ProjectWorkspace>>,
pub analysis_host: AnalysisHost, pub analysis_host: AnalysisHost,
@ -73,7 +71,6 @@ pub struct WorldState {
/// An immutable snapshot of the world's state at a point in time. /// An immutable snapshot of the world's state at a point in time.
pub struct WorldSnapshot { pub struct WorldSnapshot {
pub config: Config, pub config: Config,
pub feature_flags: Arc<FeatureFlags>,
pub workspaces: Arc<Vec<ProjectWorkspace>>, pub workspaces: Arc<Vec<ProjectWorkspace>>,
pub analysis: Analysis, pub analysis: Analysis,
pub latest_requests: Arc<RwLock<LatestRequests>>, pub latest_requests: Arc<RwLock<LatestRequests>>,
@ -89,7 +86,6 @@ impl WorldState {
exclude_globs: &[Glob], exclude_globs: &[Glob],
watch: Watch, watch: Watch,
config: Config, config: Config,
feature_flags: FeatureFlags,
) -> WorldState { ) -> WorldState {
let mut change = AnalysisChange::new(); let mut change = AnalysisChange::new();
@ -197,7 +193,6 @@ impl WorldState {
analysis_host.apply_change(change); analysis_host.apply_change(change);
WorldState { WorldState {
config: config, config: config,
feature_flags: Arc::new(feature_flags),
roots: folder_roots, roots: folder_roots,
workspaces: Arc::new(workspaces), workspaces: Arc::new(workspaces),
analysis_host, analysis_host,
@ -209,13 +204,7 @@ impl WorldState {
} }
} }
pub fn update_configuration( pub fn update_configuration(&mut self, lru_capacity: Option<usize>, config: Config) {
&mut self,
lru_capacity: Option<usize>,
config: Config,
feature_flags: FeatureFlags,
) {
self.feature_flags = Arc::new(feature_flags);
self.analysis_host.update_lru_capacity(lru_capacity); self.analysis_host.update_lru_capacity(lru_capacity);
self.flycheck = create_flycheck(&self.workspaces, &config); self.flycheck = create_flycheck(&self.workspaces, &config);
self.config = config; self.config = config;
@ -275,7 +264,6 @@ impl WorldState {
pub fn snapshot(&self) -> WorldSnapshot { pub fn snapshot(&self) -> WorldSnapshot {
WorldSnapshot { WorldSnapshot {
config: self.config.clone(), config: self.config.clone(),
feature_flags: Arc::clone(&self.feature_flags),
workspaces: Arc::clone(&self.workspaces), workspaces: Arc::clone(&self.workspaces),
analysis: self.analysis_host.analysis(), analysis: self.analysis_host.analysis(),
vfs: Arc::clone(&self.vfs), vfs: Arc::clone(&self.vfs),