From 1aece03d161dc167e72473a1b56ad35f20cc22cf Mon Sep 17 00:00:00 2001 From: Ali Bektas Date: Fri, 26 Jul 2024 03:04:29 +0200 Subject: [PATCH] Globals too are asking for sourcerootid --- crates/rust-analyzer/src/config.rs | 177 +++++++++++++++-------------- crates/rust-analyzer/src/reload.rs | 2 +- 2 files changed, 93 insertions(+), 86 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 6724b6a7ad..36419d4a97 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -1001,7 +1001,7 @@ impl Config { config.source_root_parent_map = source_root_map; } - if config.check_command().is_empty() { + if config.check_command(None).is_empty() { config.validation_errors.0.push(Arc::new(ConfigErrorInner::Json { config_key: "/check/command".to_owned(), error: serde_json::Error::custom("expected a non-empty string"), @@ -1453,11 +1453,11 @@ impl Config { pub fn diagnostics(&self, source_root: Option) -> DiagnosticsConfig { DiagnosticsConfig { - enabled: *self.diagnostics_enable(), + enabled: *self.diagnostics_enable(source_root), proc_attr_macros_enabled: self.expand_proc_attr_macros(), proc_macros_enabled: *self.procMacro_enable(), - disable_experimental: !self.diagnostics_experimental_enable(), - disabled: self.diagnostics_disabled().clone(), + disable_experimental: !self.diagnostics_experimental_enable(source_root), + disabled: self.diagnostics_disabled(source_root).clone(), expr_fill_default: match self.assist_expressionFillDefault(source_root) { ExprFillDefaultDef::Todo => ExprFillDefaultMode::Todo, ExprFillDefaultDef::Default => ExprFillDefaultMode::Default, @@ -1467,7 +1467,7 @@ impl Config { prefer_no_std: self.imports_preferNoStd(source_root).to_owned(), prefer_prelude: self.imports_preferPrelude(source_root).to_owned(), prefer_absolute: self.imports_prefixExternPrelude(source_root).to_owned(), - style_lints: self.diagnostics_styleLints_enable().to_owned(), + style_lints: self.diagnostics_styleLints_enable(source_root).to_owned(), term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64, term_search_borrowck: self.assist_termSearch_borrowcheck(source_root).to_owned(), } @@ -1660,11 +1660,11 @@ impl Config { } pub fn has_linked_projects(&self) -> bool { - !self.linkedProjects().is_empty() + !self.linkedProjects(None).is_empty() } pub fn linked_manifests(&self) -> impl Iterator + '_ { - self.linkedProjects().iter().filter_map(|it| match it { + self.linkedProjects(None).iter().filter_map(|it| match it { ManifestOrProjectJson::Manifest(p) => Some(&**p), // despite having a buildfile, using this variant as a manifest // will fail. @@ -1674,20 +1674,20 @@ impl Config { } pub fn has_linked_project_jsons(&self) -> bool { - self.linkedProjects() + self.linkedProjects(None) .iter() .any(|it| matches!(it, ManifestOrProjectJson::ProjectJson { .. })) } pub fn discover_workspace_config(&self) -> Option<&DiscoverWorkspaceConfig> { - self.workspace_discoverConfig().as_ref() + self.workspace_discoverConfig(None).as_ref() } pub fn linked_or_discovered_projects(&self) -> Vec { - match self.linkedProjects().as_slice() { + match self.linkedProjects(None).as_slice() { [] => { let exclude_dirs: Vec<_> = - self.files_excludeDirs().iter().map(|p| self.root_path.join(p)).collect(); + self.files_excludeDirs(None).iter().map(|p| self.root_path.join(p)).collect(); self.discovered_projects .iter() .filter(|project| { @@ -1722,48 +1722,48 @@ impl Config { } pub fn prefill_caches(&self) -> bool { - self.cachePriming_enable().to_owned() + self.cachePriming_enable(None).to_owned() } pub fn publish_diagnostics(&self) -> bool { - self.diagnostics_enable().to_owned() + self.diagnostics_enable(None).to_owned() } pub fn diagnostics_map(&self) -> DiagnosticsMapConfig { DiagnosticsMapConfig { - remap_prefix: self.diagnostics_remapPrefix().clone(), - warnings_as_info: self.diagnostics_warningsAsInfo().clone(), - warnings_as_hint: self.diagnostics_warningsAsHint().clone(), - check_ignore: self.check_ignore().clone(), + remap_prefix: self.diagnostics_remapPrefix(None).clone(), + warnings_as_info: self.diagnostics_warningsAsInfo(None).clone(), + warnings_as_hint: self.diagnostics_warningsAsHint(None).clone(), + check_ignore: self.check_ignore(None).clone(), } } pub fn extra_args(&self) -> &Vec { - self.cargo_extraArgs() + self.cargo_extraArgs(None) } pub fn extra_env(&self) -> &FxHashMap { - self.cargo_extraEnv() + self.cargo_extraEnv(None) } pub fn check_extra_args(&self) -> Vec { let mut extra_args = self.extra_args().clone(); - extra_args.extend_from_slice(self.check_extraArgs()); + extra_args.extend_from_slice(self.check_extraArgs(None)); extra_args } pub fn check_extra_env(&self) -> FxHashMap { - let mut extra_env = self.cargo_extraEnv().clone(); - extra_env.extend(self.check_extraEnv().clone()); + let mut extra_env = self.cargo_extraEnv(None).clone(); + extra_env.extend(self.check_extraEnv(None).clone()); extra_env } pub fn lru_parse_query_capacity(&self) -> Option { - self.lru_capacity().to_owned() + self.lru_capacity(None).to_owned() } pub fn lru_query_capacities_config(&self) -> Option<&FxHashMap, u16>> { - self.lru_query_capacities().is_empty().not().then(|| self.lru_query_capacities()) + self.lru_query_capacities(None).is_empty().not().then(|| self.lru_query_capacities(None)) } pub fn proc_macro_srv(&self) -> Option { @@ -1772,7 +1772,7 @@ impl Config { } pub fn ignored_proc_macros(&self) -> &FxHashMap, Box<[Box]>> { - self.procMacro_ignored() + self.procMacro_ignored(None) } pub fn expand_proc_macros(&self) -> bool { @@ -1787,7 +1787,11 @@ impl Config { } _ => FilesWatcher::Server, }, - exclude: self.files_excludeDirs().iter().map(|it| self.root_path.join(it)).collect(), + exclude: self + .files_excludeDirs(None) + .iter() + .map(|it| self.root_path.join(it)) + .collect(), } } @@ -1798,22 +1802,22 @@ impl Config { } pub fn cargo_autoreload_config(&self) -> bool { - self.cargo_autoreload().to_owned() + self.cargo_autoreload(None).to_owned() } pub fn run_build_scripts(&self) -> bool { - self.cargo_buildScripts_enable().to_owned() || self.procMacro_enable().to_owned() + self.cargo_buildScripts_enable(None).to_owned() || self.procMacro_enable().to_owned() } pub fn cargo(&self) -> CargoConfig { - let rustc_source = self.rustc_source().as_ref().map(|rustc_src| { + let rustc_source = self.rustc_source(None).as_ref().map(|rustc_src| { if rustc_src == "discover" { RustLibSource::Discover } else { RustLibSource::Path(self.root_path.join(rustc_src)) } }); - let sysroot = self.cargo_sysroot().as_ref().map(|sysroot| { + let sysroot = self.cargo_sysroot(None).as_ref().map(|sysroot| { if sysroot == "discover" { RustLibSource::Discover } else { @@ -1821,26 +1825,26 @@ impl Config { } }); let sysroot_src = - self.cargo_sysrootSrc().as_ref().map(|sysroot| self.root_path.join(sysroot)); - let sysroot_query_metadata = self.cargo_sysrootQueryMetadata(); + self.cargo_sysrootSrc(None).as_ref().map(|sysroot| self.root_path.join(sysroot)); + let sysroot_query_metadata = self.cargo_sysrootQueryMetadata(None); CargoConfig { - all_targets: *self.cargo_allTargets(), - features: match &self.cargo_features() { + all_targets: *self.cargo_allTargets(None), + features: match &self.cargo_features(None) { CargoFeaturesDef::All => CargoFeatures::All, CargoFeaturesDef::Selected(features) => CargoFeatures::Selected { features: features.clone(), - no_default_features: self.cargo_noDefaultFeatures().to_owned(), + no_default_features: self.cargo_noDefaultFeatures(None).to_owned(), }, }, - target: self.cargo_target().clone(), + target: self.cargo_target(None).clone(), sysroot, sysroot_query_metadata: *sysroot_query_metadata, sysroot_src, rustc_source, cfg_overrides: project_model::CfgOverrides { global: CfgDiff::new( - self.cargo_cfgs() + self.cargo_cfgs(None) .iter() .map(|(key, val)| match val { Some(val) => CfgAtom::KeyValue { @@ -1855,49 +1859,49 @@ impl Config { .unwrap(), selective: Default::default(), }, - wrap_rustc_in_build_scripts: *self.cargo_buildScripts_useRustcWrapper(), - invocation_strategy: match self.cargo_buildScripts_invocationStrategy() { + wrap_rustc_in_build_scripts: *self.cargo_buildScripts_useRustcWrapper(None), + invocation_strategy: match self.cargo_buildScripts_invocationStrategy(None) { InvocationStrategy::Once => project_model::InvocationStrategy::Once, InvocationStrategy::PerWorkspace => project_model::InvocationStrategy::PerWorkspace, }, - invocation_location: match self.cargo_buildScripts_invocationLocation() { + invocation_location: match self.cargo_buildScripts_invocationLocation(None) { InvocationLocation::Root => { project_model::InvocationLocation::Root(self.root_path.clone()) } InvocationLocation::Workspace => project_model::InvocationLocation::Workspace, }, - run_build_script_command: self.cargo_buildScripts_overrideCommand().clone(), - extra_args: self.cargo_extraArgs().clone(), - extra_env: self.cargo_extraEnv().clone(), + run_build_script_command: self.cargo_buildScripts_overrideCommand(None).clone(), + extra_args: self.cargo_extraArgs(None).clone(), + extra_env: self.cargo_extraEnv(None).clone(), target_dir: self.target_dir_from_config(), } } pub fn rustfmt(&self) -> RustfmtConfig { - match &self.rustfmt_overrideCommand() { + match &self.rustfmt_overrideCommand(None) { Some(args) if !args.is_empty() => { let mut args = args.clone(); let command = args.remove(0); RustfmtConfig::CustomCommand { command, args } } Some(_) | None => RustfmtConfig::Rustfmt { - extra_args: self.rustfmt_extraArgs().clone(), - enable_range_formatting: *self.rustfmt_rangeFormatting_enable(), + extra_args: self.rustfmt_extraArgs(None).clone(), + enable_range_formatting: *self.rustfmt_rangeFormatting_enable(None), }, } } pub fn flycheck_workspace(&self) -> bool { - *self.check_workspace() + *self.check_workspace(None) } pub fn cargo_test_options(&self) -> CargoOptions { CargoOptions { - target_triples: self.cargo_target().clone().into_iter().collect(), + target_triples: self.cargo_target(None).clone().into_iter().collect(), all_targets: false, - no_default_features: *self.cargo_noDefaultFeatures(), - all_features: matches!(self.cargo_features(), CargoFeaturesDef::All), - features: match self.cargo_features().clone() { + no_default_features: *self.cargo_noDefaultFeatures(None), + all_features: matches!(self.cargo_features(None), CargoFeaturesDef::All), + features: match self.cargo_features(None).clone() { CargoFeaturesDef::All => vec![], CargoFeaturesDef::Selected(it) => it, }, @@ -1908,7 +1912,7 @@ impl Config { } pub fn flycheck(&self) -> FlycheckConfig { - match &self.check_overrideCommand() { + match &self.check_overrideCommand(None) { Some(args) if !args.is_empty() => { let mut args = args.clone(); let command = args.remove(0); @@ -1916,13 +1920,13 @@ impl Config { command, args, extra_env: self.check_extra_env(), - invocation_strategy: match self.check_invocationStrategy() { + invocation_strategy: match self.check_invocationStrategy(None) { InvocationStrategy::Once => flycheck::InvocationStrategy::Once, InvocationStrategy::PerWorkspace => { flycheck::InvocationStrategy::PerWorkspace } }, - invocation_location: match self.check_invocationLocation() { + invocation_location: match self.check_invocationLocation(None) { InvocationLocation::Root => { flycheck::InvocationLocation::Root(self.root_path.clone()) } @@ -1931,28 +1935,30 @@ impl Config { } } Some(_) | None => FlycheckConfig::CargoCommand { - command: self.check_command().clone(), + command: self.check_command(None).clone(), options: CargoOptions { target_triples: self - .check_targets() + .check_targets(None) .clone() .and_then(|targets| match &targets.0[..] { [] => None, targets => Some(targets.into()), }) - .unwrap_or_else(|| self.cargo_target().clone().into_iter().collect()), - all_targets: self.check_allTargets().unwrap_or(*self.cargo_allTargets()), + .unwrap_or_else(|| self.cargo_target(None).clone().into_iter().collect()), + all_targets: self + .check_allTargets(None) + .unwrap_or(*self.cargo_allTargets(None)), no_default_features: self - .check_noDefaultFeatures() - .unwrap_or(*self.cargo_noDefaultFeatures()), + .check_noDefaultFeatures(None) + .unwrap_or(*self.cargo_noDefaultFeatures(None)), all_features: matches!( - self.check_features().as_ref().unwrap_or(self.cargo_features()), + self.check_features(None).as_ref().unwrap_or(self.cargo_features(None)), CargoFeaturesDef::All ), features: match self - .check_features() + .check_features(None) .clone() - .unwrap_or_else(|| self.cargo_features().clone()) + .unwrap_or_else(|| self.cargo_features(None).clone()) { CargoFeaturesDef::All => vec![], CargoFeaturesDef::Selected(it) => it, @@ -1967,7 +1973,7 @@ impl Config { } fn target_dir_from_config(&self) -> Option { - self.cargo_targetDir().as_ref().and_then(|target_dir| match target_dir { + self.cargo_targetDir(None).as_ref().and_then(|target_dir| match target_dir { TargetDirectory::UseSubdirectory(true) => { Some(Utf8PathBuf::from("target/rust-analyzer")) } @@ -1978,18 +1984,18 @@ impl Config { } pub fn check_on_save(&self) -> bool { - *self.checkOnSave() + *self.checkOnSave(None) } pub fn script_rebuild_on_save(&self) -> bool { - *self.cargo_buildScripts_rebuildOnSave() + *self.cargo_buildScripts_rebuildOnSave(None) } pub fn runnables(&self) -> RunnablesConfig { RunnablesConfig { - override_cargo: self.runnables_command().clone(), - cargo_extra_args: self.runnables_extraArgs().clone(), - extra_test_binary_args: self.runnables_extraTestBinaryArgs().clone(), + override_cargo: self.runnables_command(None).clone(), + cargo_extra_args: self.runnables_extraArgs(None).clone(), + extra_test_binary_args: self.runnables_extraTestBinaryArgs(None).clone(), } } @@ -2060,7 +2066,7 @@ impl Config { } pub fn prime_caches_num_threads(&self) -> usize { - match self.cachePriming_numThreads() { + match self.cachePriming_numThreads(None) { NumThreads::Concrete(0) | NumThreads::Physical => num_cpus::get_physical(), &NumThreads::Concrete(n) => n, NumThreads::Logical => num_cpus::get(), @@ -2544,11 +2550,12 @@ macro_rules! _impl_for_config_data { } } - if let Some((root_path_ratoml, _)) = self.root_ratoml.as_ref() { - if let Some(v) = root_path_ratoml.local.$field.as_ref() { - return &v; - } - } + // TODO + // if let Some((root_path_ratoml, _)) = self.root_ratoml.as_ref() { + // if let Some(v) = root_path_ratoml.local.$field.as_ref() { + // return &v; + // } + // } if let Some(v) = self.client_config.0.local.$field.as_ref() { return &v; @@ -2574,13 +2581,13 @@ macro_rules! _impl_for_config_data { $( $($doc)* #[allow(non_snake_case)] - $vis fn $field(&self) -> &$ty { - - if let Some((root_path_ratoml, _)) = self.root_ratoml.as_ref() { - if let Some(v) = root_path_ratoml.global.$field.as_ref() { - return &v; - } - } + $vis fn $field(&self, source_root : Option) -> &$ty { + // TODO + // if let Some((root_path_ratoml, _)) = self.root_ratoml.as_ref() { + // if let Some(v) = root_path_ratoml.global.$field.as_ref() { + // return &v; + // } + // } if let Some(v) = self.client_config.0.global.$field.as_ref() { return &v; @@ -3522,7 +3529,7 @@ mod tests { })); (config, _, _) = config.apply_change(change); - assert_eq!(config.cargo_targetDir(), &None); + assert_eq!(config.cargo_targetDir(None), &None); assert!( matches!(config.flycheck(), FlycheckConfig::CargoCommand { options, .. } if options.target_dir.is_none()) ); @@ -3545,7 +3552,7 @@ mod tests { (config, _, _) = config.apply_change(change); - assert_eq!(config.cargo_targetDir(), &Some(TargetDirectory::UseSubdirectory(true))); + assert_eq!(config.cargo_targetDir(None), &Some(TargetDirectory::UseSubdirectory(true))); assert!( matches!(config.flycheck(), FlycheckConfig::CargoCommand { options, .. } if options.target_dir == Some(Utf8PathBuf::from("target/rust-analyzer"))) ); @@ -3569,7 +3576,7 @@ mod tests { (config, _, _) = config.apply_change(change); assert_eq!( - config.cargo_targetDir(), + config.cargo_targetDir(None), &Some(TargetDirectory::Directory(Utf8PathBuf::from("other_folder"))) ); assert!( diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index b2d360c62d..2d358afab3 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -110,7 +110,7 @@ impl GlobalState { }; let mut message = String::new(); - if !self.config.cargo_autoreload() + if !self.config.cargo_autoreload(None) && self.is_quiescent() && self.fetch_workspaces_queue.op_requested() && self.config.discover_workspace_config().is_none()