Properly handle commands defined inside of other commands (#2837)

* Fix function inner scopes

* tweak error
This commit is contained in:
Jonathan Turner
2021-01-01 19:23:54 +13:00
committed by GitHub
parent 328b09fe04
commit 43c10b0625
3 changed files with 74 additions and 6 deletions

View File

@ -2142,6 +2142,8 @@ fn parse_definition(call: &LiteCommand, scope: &dyn ParserScope) -> Option<Parse
// We have a literal block
let string: String = chars.collect();
scope.enter_scope();
let (tokens, err) = lex(&string, call.parts[3].span.start() + 1);
if err.is_some() {
return err;
@ -2152,6 +2154,7 @@ fn parse_definition(call: &LiteCommand, scope: &dyn ParserScope) -> Option<Parse
};
let (mut block, err) = classify_block(&lite_block, scope);
scope.exit_scope();
block.params = signature;
block.params.name = name;
@ -2285,6 +2288,14 @@ pub fn classify_block(
}
}
let definitions = scope.get_definitions();
for definition in definitions.into_iter() {
let name = definition.params.name.clone();
if !output.definitions.contains_key(&name) {
output.definitions.insert(name, definition.clone());
}
}
(output, error)
}