summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/language_server/gdscript_extend_parser.cpp
diff options
context:
space:
mode:
authorgeequlim <geequlim@gmail.com>2019-06-23 21:10:28 +0800
committergeequlim <geequlim@gmail.com>2019-08-11 13:30:15 +0800
commitfa6d6a329c93224b5454b17603284913da0472a3 (patch)
tree6247b59ba4313cb1af1b80efbf45fab2bff10dba /modules/gdscript/language_server/gdscript_extend_parser.cpp
parent37aafaaa9cc7d66c85fd9395e46b2386d899ba12 (diff)
downloadredot-engine-fa6d6a329c93224b5454b17603284913da0472a3.tar.gz
Add optional smart resolve sulotion
The smart resolvaion can guess most symbols but it might be slow so disabled by default users can turn on it in the editor setting
Diffstat (limited to 'modules/gdscript/language_server/gdscript_extend_parser.cpp')
-rw-r--r--modules/gdscript/language_server/gdscript_extend_parser.cpp43
1 files changed, 36 insertions, 7 deletions
diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp
index 9ec93a813e..16af7cb92f 100644
--- a/modules/gdscript/language_server/gdscript_extend_parser.cpp
+++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp
@@ -123,7 +123,9 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
if (m.data_type.kind != GDScriptParser::DataType::UNRESOLVED) {
symbol.detail += ": " + m.data_type.to_string();
}
- symbol.detail += " = " + String(m.default_value);
+ if (m.default_value.get_type() != Variant::NIL) {
+ symbol.detail += " = " + JSON::print(m.default_value);
+ }
symbol.documentation = parse_documentation(line);
symbol.uri = uri;
@@ -493,12 +495,39 @@ const lsp::DocumentSymbol *ExtendGDScriptParser::get_member_symbol(const String
return NULL;
}
-void ExtendGDScriptParser::dump_symbols(HashMap<String, lsp::DocumentedSymbolInformation> &r_symbols) {
- Vector<lsp::DocumentedSymbolInformation> list;
- class_symbol.symbol_tree_as_list(path, list, path, true);
- for (int i = 0; i < list.size(); i++) {
- const lsp::DocumentedSymbolInformation &symbol = list[i];
- r_symbols.set(symbol.name, symbol);
+void ExtendGDScriptParser::dump_member_symbols(Map<String, const lsp::DocumentSymbol *> &r_symbols) {
+
+ const GDScriptParser::Node *head = get_parse_tree();
+ if (const GDScriptParser::ClassNode *gdclass = dynamic_cast<const GDScriptParser::ClassNode *>(head)) {
+
+ for (const Map<StringName, GDScriptParser::ClassNode::Constant>::Element *E = gdclass->constant_expressions.front(); E; E = E->next()) {
+ get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(E->get().expression->line));
+ }
+
+ for (int i = 0; i < gdclass->subclasses.size(); i++) {
+ const ClassNode *m = gdclass->subclasses[i];
+ r_symbols.insert(JOIN_SYMBOLS(path, m->name), get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m->line)));
+ }
+
+ for (int i = 0; i < gdclass->variables.size(); i++) {
+ const GDScriptParser::ClassNode::Member &m = gdclass->variables[i];
+ r_symbols.insert(JOIN_SYMBOLS(path, m.identifier), get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.line)));
+ }
+
+ for (int i = 0; i < gdclass->functions.size(); i++) {
+ const GDScriptParser::FunctionNode *m = gdclass->functions[i];
+ r_symbols.insert(JOIN_SYMBOLS(path, m->name), get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m->line)));
+ }
+
+ for (int i = 0; i < gdclass->static_functions.size(); i++) {
+ const GDScriptParser::FunctionNode *m = gdclass->static_functions[i];
+ r_symbols.insert(JOIN_SYMBOLS(path, m->name), get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m->line)));
+ }
+
+ for (int i = 0; i < gdclass->_signals.size(); i++) {
+ const GDScriptParser::ClassNode::Signal &m = gdclass->_signals[i];
+ r_symbols.insert(JOIN_SYMBOLS(path, m.name), get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.line)));
+ }
}
}