mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 07:16:05 +02:00
Reuse parsed modules (#9125)
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user