Move all config to config

This commit is contained in:
Aleksey Kladov 2020-04-01 17:22:56 +02:00
parent 797cd34c7c
commit 1e012eb991
3 changed files with 17 additions and 7 deletions

View file

@ -43,6 +43,7 @@ impl ops::Index<Target> for CargoWorkspace {
} }
} }
// TODO: rename to CargoConfig, kill `rename_all`, kill serde dep?
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)] #[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
pub struct CargoFeatures { pub struct CargoFeatures {

View file

@ -30,6 +30,11 @@ pub struct Config {
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>,
pub lru_capacity: Option<usize>,
pub use_client_watching: bool,
pub exclude_globs: Vec<String>,
pub cargo: CargoFeatures,
pub with_sysroot: bool,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -101,6 +106,11 @@ pub(crate) fn get_config(
rustfmt: RustfmtConfig::Rustfmt { extra_args: config.rustfmt_args.clone() }, rustfmt: RustfmtConfig::Rustfmt { extra_args: config.rustfmt_args.clone() },
vscode_lldb: config.vscode_lldb, vscode_lldb: config.vscode_lldb,
proc_macro_srv: None, // FIXME: get this from config proc_macro_srv: None, // FIXME: get this from config
lru_capacity: config.lru_capacity,
use_client_watching: config.use_client_watching,
exclude_globs: config.exclude_globs.clone(),
cargo: config.cargo_features.clone(),
with_sysroot: config.with_sysroot,
} }
} }

View file

@ -71,7 +71,9 @@ pub fn main_loop(
config: ServerConfig, config: ServerConfig,
connection: Connection, connection: Connection,
) -> Result<()> { ) -> Result<()> {
log::info!("server_config: {:#?}", config); let text_document_caps = client_caps.text_document.as_ref();
let config = get_config(&config, text_document_caps);
log::info!("initial config: {:#?}", config);
// Windows scheduler implements priority boosts: if thread waits for an // Windows scheduler implements priority boosts: if thread waits for an
// event (like a condvar), and event fires, priority of the thread is // event (like a condvar), and event fires, priority of the thread is
@ -92,11 +94,8 @@ pub fn main_loop(
SetThreadPriority(thread, thread_priority_above_normal); SetThreadPriority(thread, thread_priority_above_normal);
} }
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 = {
// 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();
@ -104,7 +103,7 @@ pub fn main_loop(
let workspace = ra_project_model::ProjectWorkspace::discover_with_sysroot( let workspace = ra_project_model::ProjectWorkspace::discover_with_sysroot(
ws_root.as_path(), ws_root.as_path(),
config.with_sysroot, config.with_sysroot,
&config.cargo_features, &config.cargo,
); );
match workspace { match workspace {
Ok(workspace) => loaded_workspaces.push(workspace), Ok(workspace) => loaded_workspaces.push(workspace),
@ -114,7 +113,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 !new_config.notifications.cargo_toml_not_found { if !config.notifications.cargo_toml_not_found {
continue; continue;
} }
} }
@ -163,7 +162,7 @@ pub fn main_loop(
config.lru_capacity, config.lru_capacity,
&globs, &globs,
Watch(!config.use_client_watching), Watch(!config.use_client_watching),
new_config, config,
) )
}; };