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.
This commit is contained in:
George Marques 2018-06-20 22:41:26 -03:00
parent 3445dca01d
commit 3e87ad5187
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D
2 changed files with 2302 additions and 2140 deletions

File diff suppressed because it is too large Load diff

View file

@ -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