Skip to content

Commit 72718bc

Browse files
committed
Code review feedback.
1 parent 9fcad82 commit 72718bc

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ config_data! {
9999
diagnostics_enableExperimental: bool = "true",
100100
/// List of rust-analyzer diagnostics to disable.
101101
diagnostics_disabled: FxHashSet<String> = "[]",
102-
/// Map of path prefixes to be substituted when parsing diagnostic file paths.
102+
/// Map of prefixes to be substituted when parsing diagnostic file paths.
103103
/// This should be the reverse mapping of what is passed to `rustc` as `--remap-path-prefix`.
104-
diagnostics_remapPathPrefixes: FxHashMap<String, String> = "{}",
104+
diagnostics_remapPrefix: FxHashMap<String, String> = "{}",
105105
/// List of warnings that should be displayed with info severity.
106106
///
107107
/// The warnings will be indicated by a blue squiggly underline in code
@@ -477,7 +477,7 @@ impl Config {
477477
}
478478
pub fn diagnostics_map(&self) -> DiagnosticsMapConfig {
479479
DiagnosticsMapConfig {
480-
remap_path_prefixes: self.data.diagnostics_remapPathPrefixes.clone(),
480+
remap_prefix: self.data.diagnostics_remapPrefix.clone(),
481481
warnings_as_info: self.data.diagnostics_warningsAsInfo.clone(),
482482
warnings_as_hint: self.data.diagnostics_warningsAsHint.clone(),
483483
}

crates/rust-analyzer/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(crate) type CheckFixes = Arc<FxHashMap<FileId, Vec<Fix>>>;
1212

1313
#[derive(Debug, Default, Clone)]
1414
pub struct DiagnosticsMapConfig {
15-
pub remap_path_prefixes: FxHashMap<String, String>,
15+
pub remap_prefix: FxHashMap<String, String>,
1616
pub warnings_as_info: Vec<String>,
1717
pub warnings_as_hint: Vec<String>,
1818
}

crates/rust-analyzer/src/diagnostics/to_proto.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ fn diagnostic_related_information(
9999
/// Resolves paths applying any matching path prefix remappings, and then
100100
/// joining the path to the workspace root.
101101
fn resolve_path(config: &DiagnosticsMapConfig, workspace_root: &Path, file_name: &str) -> PathBuf {
102-
match config.remap_path_prefixes.iter().find(|(from, _)| file_name.starts_with(*from)) {
103-
Some((from, to)) => {
104-
workspace_root.join(format!("{}{}", to, file_name.strip_prefix(from).unwrap()))
105-
}
102+
match config
103+
.remap_prefix
104+
.iter()
105+
.find_map(|(from, to)| file_name.strip_prefix(from).map(|file_name| (to, file_name)))
106+
{
107+
Some((to, file_name)) => workspace_root.join(format!("{}{}", to, file_name)),
106108
None => workspace_root.join(file_name),
107109
}
108110
}

docs/user/generated_config.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ have more false positives than usual.
147147
--
148148
List of rust-analyzer diagnostics to disable.
149149
--
150-
[[rust-analyzer.diagnostics.remapPathPrefixes]]rust-analyzer.diagnostics.remapPathPrefixes (default: `{}`)::
150+
[[rust-analyzer.diagnostics.remapPrefix]]rust-analyzer.diagnostics.remapPrefix (default: `{}`)::
151151
+
152152
--
153-
Map of path prefixes to be substituted when parsing diagnostic file paths.
153+
Map of prefixes to be substituted when parsing diagnostic file paths.
154154
This should be the reverse mapping of what is passed to `rustc` as `--remap-path-prefix`.
155155
--
156156
[[rust-analyzer.diagnostics.warningsAsHint]]rust-analyzer.diagnostics.warningsAsHint (default: `[]`)::

editors/code/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@
565565
},
566566
"uniqueItems": true
567567
},
568-
"rust-analyzer.diagnostics.remapPathPrefixes": {
569-
"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`.",
568+
"rust-analyzer.diagnostics.remapPrefix": {
569+
"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`.",
570570
"default": {},
571571
"type": "object"
572572
},

0 commit comments

Comments
 (0)