mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 08:23:29 +00:00
Merge pull request #26547 from vnen/gdscript-dependency-parse
Add a parse mode for GDScript which doesn't load dependencies
This commit is contained in:
commit
a9fe834a8e
6 changed files with 158 additions and 79 deletions
|
@ -473,29 +473,31 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
|
|||
}
|
||||
|
||||
Ref<Resource> res;
|
||||
if (!validating) {
|
||||
dependencies.push_back(path);
|
||||
if (!dependencies_only) {
|
||||
if (!validating) {
|
||||
|
||||
//this can be too slow for just validating code
|
||||
if (for_completion && ScriptCodeCompletionCache::get_singleton() && FileAccess::exists(path)) {
|
||||
res = ScriptCodeCompletionCache::get_singleton()->get_cached_resource(path);
|
||||
} else if (!for_completion || FileAccess::exists(path)) {
|
||||
res = ResourceLoader::load(path);
|
||||
//this can be too slow for just validating code
|
||||
if (for_completion && ScriptCodeCompletionCache::get_singleton() && FileAccess::exists(path)) {
|
||||
res = ScriptCodeCompletionCache::get_singleton()->get_cached_resource(path);
|
||||
} else if (!for_completion || FileAccess::exists(path)) {
|
||||
res = ResourceLoader::load(path);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (!FileAccess::exists(path)) {
|
||||
_set_error("Can't preload resource at path: " + path);
|
||||
return NULL;
|
||||
} else if (ScriptCodeCompletionCache::get_singleton()) {
|
||||
res = ScriptCodeCompletionCache::get_singleton()->get_cached_resource(path);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
if (!FileAccess::exists(path)) {
|
||||
if (!res.is_valid()) {
|
||||
_set_error("Can't preload resource at path: " + path);
|
||||
return NULL;
|
||||
} else if (ScriptCodeCompletionCache::get_singleton()) {
|
||||
res = ScriptCodeCompletionCache::get_singleton()->get_cached_resource(path);
|
||||
}
|
||||
}
|
||||
|
||||
if (!res.is_valid()) {
|
||||
_set_error("Can't preload resource at path: " + path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
|
||||
_set_error("Expected ')' after 'preload' path");
|
||||
return NULL;
|
||||
|
@ -812,17 +814,19 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
|
|||
bfn = true;
|
||||
}
|
||||
|
||||
// Check parents for the constant
|
||||
if (!bfn && cln->extends_file != StringName()) {
|
||||
Ref<GDScript> parent = ResourceLoader::load(cln->extends_file);
|
||||
if (parent.is_valid() && parent->is_valid()) {
|
||||
Map<StringName, Variant> parent_constants;
|
||||
parent->get_constants(&parent_constants);
|
||||
if (parent_constants.has(identifier)) {
|
||||
ConstantNode *constant = alloc_node<ConstantNode>();
|
||||
constant->value = parent_constants[identifier];
|
||||
expr = constant;
|
||||
bfn = true;
|
||||
if (!dependencies_only) {
|
||||
// Check parents for the constant
|
||||
if (!bfn && cln->extends_file != StringName()) {
|
||||
Ref<GDScript> parent = ResourceLoader::load(cln->extends_file);
|
||||
if (parent.is_valid() && parent->is_valid()) {
|
||||
Map<StringName, Variant> parent_constants;
|
||||
parent->get_constants(&parent_constants);
|
||||
if (parent_constants.has(identifier)) {
|
||||
ConstantNode *constant = alloc_node<ConstantNode>();
|
||||
constant->value = parent_constants[identifier];
|
||||
expr = constant;
|
||||
bfn = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3378,6 +3382,13 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) {
|
|||
p_class->extends_file = constant;
|
||||
tokenizer->advance();
|
||||
|
||||
// Add parent script as a dependency
|
||||
String parent = constant;
|
||||
if (parent.is_rel_path()) {
|
||||
parent = base_path.plus_file(parent).simplify_path();
|
||||
}
|
||||
dependencies.push_back(parent);
|
||||
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_PERIOD) {
|
||||
return;
|
||||
} else
|
||||
|
@ -8152,6 +8163,10 @@ Error GDScriptParser::_parse(const String &p_base_path) {
|
|||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
if (dependencies_only) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
_determine_inheritance(main_class);
|
||||
|
||||
if (error_set) {
|
||||
|
@ -8230,7 +8245,7 @@ Error GDScriptParser::parse_bytecode(const Vector<uint8_t> &p_bytecode, const St
|
|||
return ret;
|
||||
}
|
||||
|
||||
Error GDScriptParser::parse(const String &p_code, const String &p_base_path, bool p_just_validate, const String &p_self_path, bool p_for_completion, Set<int> *r_safe_lines) {
|
||||
Error GDScriptParser::parse(const String &p_code, const String &p_base_path, bool p_just_validate, const String &p_self_path, bool p_for_completion, Set<int> *r_safe_lines, bool p_dependencies_only) {
|
||||
|
||||
clear();
|
||||
|
||||
|
@ -8240,6 +8255,7 @@ Error GDScriptParser::parse(const String &p_code, const String &p_base_path, boo
|
|||
|
||||
validating = p_just_validate;
|
||||
for_completion = p_for_completion;
|
||||
dependencies_only = p_dependencies_only;
|
||||
#ifdef DEBUG_ENABLED
|
||||
safe_lines = r_safe_lines;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
@ -8296,6 +8312,8 @@ void GDScriptParser::clear() {
|
|||
parenthesis = 0;
|
||||
current_export.type = Variant::NIL;
|
||||
check_types = true;
|
||||
dependencies_only = false;
|
||||
dependencies.clear();
|
||||
error = "";
|
||||
#ifdef DEBUG_ENABLED
|
||||
safe_lines = NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue