Make LSP parser aware of variables in sub-blocks

Fixes #43164 and Fixes godotengine/godot-vscode-plugin#207
This commit is contained in:
Francois Belair 2021-03-24 16:27:57 -04:00
parent ed1f5c29be
commit 7f8fe58825
1 changed files with 32 additions and 16 deletions

View File

@ -346,7 +346,22 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN
r_symbol.detail += " -> " + p_func->return_type.to_string();
}
for (const Map<StringName, LocalVarNode *>::Element *E = p_func->body->variables.front(); E; E = E->next()) {
List<GDScriptParser::BlockNode *> function_blocks;
List<GDScriptParser::BlockNode *> block_stack;
block_stack.push_back(p_func->body);
while (!block_stack.empty()) {
GDScriptParser::BlockNode *block = block_stack[0];
block_stack.pop_front();
function_blocks.push_back(block);
for (const List<GDScriptParser::BlockNode *>::Element *E = block->sub_blocks.front(); E; E = E->next()) {
block_stack.push_back(E->get());
}
}
for (const List<GDScriptParser::BlockNode *>::Element *B = function_blocks.front(); B; B = B->next()) {
for (const Map<StringName, LocalVarNode *>::Element *E = B->get()->variables.front(); E; E = E->next()) {
lsp::DocumentSymbol symbol;
const GDScriptParser::LocalVarNode *var = E->value();
symbol.name = E->key();
@ -364,6 +379,7 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN
symbol.documentation = parse_documentation(line);
r_symbol.children.push_back(symbol);
}
}
}
String ExtendGDScriptParser::parse_documentation(int p_line, bool p_docs_down) {