Code review feedback.

This commit is contained in:
James Leitch 2021-04-21 15:09:37 -07:00
parent 9fcad82980
commit 72718bc2d7
5 changed files with 14 additions and 12 deletions

View file

@ -99,9 +99,9 @@ config_data! {
diagnostics_enableExperimental: bool = "true",
/// List of rust-analyzer diagnostics to disable.
diagnostics_disabled: FxHashSet<String> = "[]",
/// 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<String, String> = "{}",
diagnostics_remapPrefix: FxHashMap<String, String> = "{}",
/// 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(),
}

View file

@ -12,7 +12,7 @@ pub(crate) type CheckFixes = Arc<FxHashMap<FileId, Vec<Fix>>>;
#[derive(Debug, Default, Clone)]
pub struct DiagnosticsMapConfig {
pub remap_path_prefixes: FxHashMap<String, String>,
pub remap_prefix: FxHashMap<String, String>,
pub warnings_as_info: Vec<String>,
pub warnings_as_hint: Vec<String>,
}

View file

@ -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),
}
}