summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/editor_resource_preview.cpp10
-rw-r--r--modules/gdscript/gd_editor.cpp14
-rw-r--r--modules/gdscript/gd_parser.cpp2
-rw-r--r--modules/gdscript/gd_parser.h3
4 files changed, 27 insertions, 2 deletions
diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp
index dcfe68b286..99ce843880 100644
--- a/editor/editor_resource_preview.cpp
+++ b/editor/editor_resource_preview.cpp
@@ -180,11 +180,13 @@ void EditorResourcePreview::_thread() {
if (cache.has(item.path)) {
//already has it because someone loaded it, just let it know it's ready
+ String path = item.path;
if (item.resource.is_valid()) {
- item.path += ":" + itos(cache[item.path].last_hash); //keep last hash (see description of what this is in condition below)
+ path += ":" + itos(cache[item.path].last_hash); //keep last hash (see description of what this is in condition below)
}
- _preview_ready(item.path, cache[item.path].preview, item.id, item.function, item.userdata);
+ print_line("cached: " + item.path);
+ _preview_ready(path, cache[item.path].preview, item.id, item.function, item.userdata);
preview_mutex->unlock();
} else {
@@ -199,12 +201,16 @@ void EditorResourcePreview::_thread() {
if (item.resource.is_valid()) {
+ print_line("generated: " + item.path);
+
texture = _generate_preview(item, String());
//adding hash to the end of path (should be ID:<objid>:<hash>) because of 5 argument limit to call_deferred
_preview_ready(item.path + ":" + itos(item.resource->hash_edited_version()), texture, item.id, item.function, item.userdata);
} else {
+ print_line("from file: " + item.path);
+
String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp");
String cache_base = ProjectSettings::get_singleton()->globalize_path(item.path).md5_text();
cache_base = temp_path.plus_file("resthumb-" + cache_base);
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index de9903fd70..d06da08551 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.cpp
@@ -929,6 +929,20 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser:
static bool _guess_identifier_type_in_block(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type) {
+ if (context.block->if_condition && context.block->if_condition->type == GDParser::Node::TYPE_OPERATOR && static_cast<const GDParser::OperatorNode *>(context.block->if_condition)->op == GDParser::OperatorNode::OP_IS) {
+ //is used, check if identifier is in there! this helps resolve in blocks that are (if (identifier is value)): which are very common..
+ //super dirty hack, but very useful
+ //credit: Zylann
+ //TODO: this could be hacked to detect ANDed conditions too..
+ const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(context.block->if_condition);
+ if (op->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER && static_cast<const GDParser::IdentifierNode *>(op->arguments[0])->name == p_identifier) {
+ //bingo
+ if (_guess_expression_type(context, op->arguments[1], op->line, r_type)) {
+ return true;
+ }
+ }
+ }
+
GDCompletionIdentifier gdi = _get_native_class(context);
if (gdi.obj_type != StringName()) {
bool valid;
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index 820304184e..48da2135fa 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.cpp
@@ -2470,6 +2470,8 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) {
cf_if->body = alloc_node<BlockNode>();
cf_if->body->parent_block = p_block;
+ cf_if->body->if_condition = condition; //helps code completion
+
p_block->sub_blocks.push_back(cf_if->body);
if (!_enter_indent_block(cf_if->body)) {
diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h
index 8ad494cd39..177552d279 100644
--- a/modules/gdscript/gd_parser.h
+++ b/modules/gdscript/gd_parser.h
@@ -146,10 +146,13 @@ public:
Vector<StringName> variables;
Vector<int> variable_lines;
+ Node *if_condition; //tiny hack to improve code completion on if () blocks
+
//the following is useful for code completion
List<BlockNode *> sub_blocks;
int end_line;
BlockNode() {
+ if_condition = NULL;
type = TYPE_BLOCK;
end_line = -1;
parent_block = NULL;