Sfoglia il codice sorgente

Rewrite code completion

- Use data type struct from the parser.
- Avail from type hints when type can't be guessed.
- Consider inner classes and other scripts when looking for candidates.
George Marques 7 anni fa
parent
commit
3e87ad5187
2 ha cambiato i file con 1639 aggiunte e 1462 eliminazioni
  1. 1617 1445
      modules/gdscript/gdscript_editor.cpp
  2. 22 17
      modules/gdscript/gdscript_parser.cpp

File diff suppressed because it is too large
+ 1617 - 1445
modules/gdscript/gdscript_editor.cpp


+ 22 - 17
modules/gdscript/gdscript_parser.cpp

@@ -142,8 +142,9 @@ bool GDScriptParser::_parse_arguments(Node *p_parent, Vector<Node *> &p_args, bo
 			}
 
 			Node *arg = _parse_expression(p_parent, p_static);
-			if (!arg)
+			if (!arg) {
 				return false;
+			}
 
 			p_args.push_back(arg);
 
@@ -1000,7 +1001,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
 
 			expr = dict;
 
-		} else if (tokenizer->get_token() == GDScriptTokenizer::TK_PERIOD && (tokenizer->is_token_literal(1) || tokenizer->get_token(1) == GDScriptTokenizer::TK_CURSOR) && tokenizer->get_token(2) == GDScriptTokenizer::TK_PARENTHESIS_OPEN) {
+		} else if (tokenizer->get_token() == GDScriptTokenizer::TK_PERIOD && (tokenizer->is_token_literal(1) || tokenizer->get_token(1) == GDScriptTokenizer::TK_CURSOR)) {
 			// We check with is_token_literal, as this allows us to use match/sync/etc. as a name
 			// parent call
 
@@ -1012,17 +1013,23 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
 			op->arguments.push_back(self);
 			forbidden for now */
 			StringName identifier;
-			if (_get_completable_identifier(COMPLETION_PARENT_FUNCTION, identifier)) {
-				//indexing stuff
-			}
+			bool is_completion = _get_completable_identifier(COMPLETION_PARENT_FUNCTION, identifier) && for_completion;
 
 			IdentifierNode *id = alloc_node<IdentifierNode>();
 			id->name = identifier;
 			op->arguments.push_back(id);
 
-			tokenizer->advance(1);
-			if (!_parse_arguments(op, op->arguments, p_static))
-				return NULL;
+			if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) {
+				if (!is_completion) {
+					_set_error("Expected '(' for parent function call.");
+					return NULL;
+				}
+			} else {
+				tokenizer->advance();
+				if (!_parse_arguments(op, op->arguments, p_static)) {
+					return NULL;
+				}
+			}
 
 			expr = op;
 
@@ -4806,13 +4813,13 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class) {
 
 			if (path.is_rel_path()) {
 
-				String base = self_path;
+				String base = base_path;
 
 				if (base == "" || base.is_rel_path()) {
 					_set_error("Could not resolve relative path for parent class: " + path, p_class->line);
 					return;
 				}
-				path = base.get_base_dir().plus_file(path).simplify_path();
+				path = base.plus_file(path).simplify_path();
 			}
 			script = ResourceLoader::load(path);
 			if (script.is_null()) {
@@ -7540,7 +7547,7 @@ Error GDScriptParser::_parse(const String &p_base_path) {
 		_set_error("Parse Error: " + tokenizer->get_token_error());
 	}
 
-	if (error_set) {
+	if (error_set && !for_completion) {
 		return ERR_PARSE_ERROR;
 	}
 
@@ -7559,13 +7566,11 @@ Error GDScriptParser::_parse(const String &p_base_path) {
 	check_types = false;
 #endif
 
-	if (check_types) {
-		// Resolve all class-level stuff before getting into function blocks
-		_check_class_level_types(main_class);
+	// Resolve all class-level stuff before getting into function blocks
+	_check_class_level_types(main_class);
 
-		if (error_set) {
-			return ERR_PARSE_ERROR;
-		}
+	if (error_set) {
+		return ERR_PARSE_ERROR;
 	}
 
 	// Resolve the function blocks

Some files were not shown because too many files changed in this diff