From 72718bc2d7113874536b8bcd486aa5bd7dacafe6 Mon Sep 17 00:00:00 2001 From: James Leitch Date: Wed, 21 Apr 2021 15:09:37 -0700 Subject: Code review feedback. --- crates/rust-analyzer/src/config.rs | 6 +++--- crates/rust-analyzer/src/diagnostics.rs | 2 +- crates/rust-analyzer/src/diagnostics/to_proto.rs | 10 ++++++---- docs/user/generated_config.adoc | 4 ++-- editors/code/package.json | 4 ++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 3be335550..1109d2daf 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -99,9 +99,9 @@ config_data! { diagnostics_enableExperimental: bool = "true", /// List of rust-analyzer diagnostics to disable. diagnostics_disabled: FxHashSet = "[]", - /// Map of path prefixes to be substituted when parsing diagnostic file paths. + /// Map of prefixes to be substituted when parsing diagnostic file paths. /// This should be the reverse mapping of what is passed to `rustc` as `--remap-path-prefix`. - diagnostics_remapPathPrefixes: FxHashMap = "{}", + diagnostics_remapPrefix: FxHashMap = "{}", /// List of warnings that should be displayed with info severity. /// /// The warnings will be indicated by a blue squiggly underline in code @@ -477,7 +477,7 @@ impl Config { } pub fn diagnostics_map(&self) -> DiagnosticsMapConfig { DiagnosticsMapConfig { - remap_path_prefixes: self.data.diagnostics_remapPathPrefixes.clone(), + remap_prefix: self.data.diagnostics_remapPrefix.clone(), warnings_as_info: self.data.diagnostics_warningsAsInfo.clone(), warnings_as_hint: self.data.diagnostics_warningsAsHint.clone(), } diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs index 776d21778..d4b9db362 100644 --- a/crates/rust-analyzer/src/diagnostics.rs +++ b/crates/rust-analyzer/src/diagnostics.rs @@ -12,7 +12,7 @@ pub(crate) type CheckFixes = Arc>>; #[derive(Debug, Default, Clone)] pub struct DiagnosticsMapConfig { - pub remap_path_prefixes: FxHashMap, + pub remap_prefix: FxHashMap, pub warnings_as_info: Vec, pub warnings_as_hint: Vec, } diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index 08303a781..82dd0da9a 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs @@ -99,10 +99,12 @@ fn diagnostic_related_information( /// Resolves paths applying any matching path prefix remappings, and then /// joining the path to the workspace root. fn resolve_path(config: &DiagnosticsMapConfig, workspace_root: &Path, file_name: &str) -> PathBuf { - match config.remap_path_prefixes.iter().find(|(from, _)| file_name.starts_with(*from)) { - Some((from, to)) => { - workspace_root.join(format!("{}{}", to, file_name.strip_prefix(from).unwrap())) - } + match config + .remap_prefix + .iter() + .find_map(|(from, to)| file_name.strip_prefix(from).map(|file_name| (to, file_name))) + { + Some((to, file_name)) => workspace_root.join(format!("{}{}", to, file_name)), None => workspace_root.join(file_name), } } diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index cb6fe5850..e28423e99 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -147,10 +147,10 @@ have more false positives than usual. -- List of rust-analyzer diagnostics to disable. -- -[[rust-analyzer.diagnostics.remapPathPrefixes]]rust-analyzer.diagnostics.remapPathPrefixes (default: `{}`):: +[[rust-analyzer.diagnostics.remapPrefix]]rust-analyzer.diagnostics.remapPrefix (default: `{}`):: + -- -Map of path prefixes to be substituted when parsing diagnostic file paths. +Map of prefixes to be substituted when parsing diagnostic file paths. This should be the reverse mapping of what is passed to `rustc` as `--remap-path-prefix`. -- [[rust-analyzer.diagnostics.warningsAsHint]]rust-analyzer.diagnostics.warningsAsHint (default: `[]`):: diff --git a/editors/code/package.json b/editors/code/package.json index dcb2e89d1..fa5632f90 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -565,8 +565,8 @@ }, "uniqueItems": true }, - "rust-analyzer.diagnostics.remapPathPrefixes": { - "markdownDescription": "Map of path prefixes to be substituted when parsing diagnostic file paths.\nThis should be the reverse mapping of what is passed to `rustc` as `--remap-path-prefix`.", + "rust-analyzer.diagnostics.remapPrefix": { + "markdownDescription": "Map of prefixes to be substituted when parsing diagnostic file paths.\nThis should be the reverse mapping of what is passed to `rustc` as `--remap-path-prefix`.", "default": {}, "type": "object" }, -- cgit v1.2.3