Reuse parsed modules (#9125)

This commit is contained in:
Jakub Žádník
2023-05-07 14:41:40 +03:00
committed by GitHub
parent 0ea973b78b
commit 250071939b
3 changed files with 50 additions and 15 deletions

View File

@ -1727,6 +1727,10 @@ fn parse_module_file(
let file_id = working_set.add_file(path.to_string_lossy().to_string(), &contents);
let new_span = working_set.get_span_for_file(file_id);
if let Some(module_id) = working_set.find_module_by_span(new_span) {
return Some(module_id);
}
// Change the currently parsed directory
let prev_currently_parsed_cwd = if let Some(parent) = path.parent() {
let prev = working_set.currently_parsed_cwd.clone();
@ -1834,13 +1838,25 @@ pub fn parse_module_file_or_dir(
path_span,
name_override.or(Some(module_name)),
) {
let module = working_set.get_module_mut(module_id);
let mut module = working_set.get_module(module_id).clone();
for (submodule_name, submodule_id) in submodules {
module.add_submodule(submodule_name, submodule_id);
}
Some(module_id)
let module_name = String::from_utf8_lossy(&module.name).to_string();
let module_comments =
if let Some(comments) = working_set.get_module_comments(module_id) {
comments.to_vec()
} else {
vec![]
};
let new_module_id =
working_set.add_module(&module_name, module, module_comments);
Some(new_module_id)
} else {
None
}