-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: use
LocatedDiagnostic
instead of maps of Diagnostic
- Loading branch information
1 parent
e3fe1b6
commit d658782
Showing
4 changed files
with
129 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
use std::collections::HashMap; | ||
use abs_path::AbsPath; | ||
use witcherscript_diagnostics::*; | ||
use crate::model::collections::SymbolTable; | ||
|
||
|
||
/// Key in the `diagnostics` map is a local path of the source file in the source tree | ||
pub fn merge_symbol_tables( | ||
target_symtab: &mut SymbolTable, | ||
source_symtab: SymbolTable, | ||
diagnostics: &mut HashMap<AbsPath, Vec<Diagnostic>> | ||
diagnostics: &mut Vec<LocatedDiagnostic> | ||
) { | ||
for (local_source_path, errors) in target_symtab.merge(source_symtab) { | ||
let abs_source_path = target_symtab.script_root().join(local_source_path).unwrap(); | ||
|
||
let errors_as_diags = errors.into_iter() | ||
.map(|err| Diagnostic { | ||
range: err.incoming_location.label_range, | ||
kind: DiagnosticKind::SymbolNameTaken { | ||
name: err.occupied_path.components().last().unwrap().name.to_string(), | ||
precursor_range: err.occupied_location.as_ref().map(|loc| loc.label_range), | ||
precursor_file_path: err.occupied_location.as_ref().map(|loc| target_symtab.script_root().join(&loc.local_source_path).unwrap()) | ||
}.into() | ||
}); | ||
|
||
diagnostics | ||
.entry(abs_source_path) | ||
.or_default() | ||
.extend(errors_as_diags); | ||
} | ||
diagnostics.extend( | ||
target_symtab | ||
.merge(source_symtab) | ||
.into_iter() | ||
.map(|err| { | ||
LocatedDiagnostic { | ||
path: err.incoming_location.abs_source_path.clone(), | ||
diagnostic: Diagnostic { | ||
range: err.incoming_location.label_range, | ||
kind: DiagnosticKind::SymbolNameTaken { | ||
name: err.occupied_path.components().last().unwrap().name.to_string(), | ||
precursor_range: err.occupied_location.as_ref().map(|loc| loc.label_range), | ||
precursor_file_path: err.occupied_location.as_ref().map(|loc| loc.abs_source_path.clone()) | ||
} | ||
} | ||
} | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.