summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-04-24 11:37:57 +0200
committerGitHub <noreply@github.com>2017-04-24 11:37:57 +0200
commit9acfb0782c818373fcb4bf13425cb7239f36893b (patch)
tree0a9130c0dfa9864ca6771b845ed33ff89c92b3ed /modules/gdscript
parent68870af2142ebe4fba181256b2cb4f79c7d33548 (diff)
parent71978685f9173d87658437e4a7fd56c71a29ac5a (diff)
Merge pull request #8444 from magyar123/pr-complete-paths
Script editor now automatically completes file paths in GDScript
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gd_editor.cpp24
-rw-r--r--modules/gdscript/gd_parser.cpp7
-rw-r--r--modules/gdscript/gd_parser.h1
3 files changed, 32 insertions, 0 deletions
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index c2f14f5466..2a3015c185 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.cpp
@@ -32,6 +32,10 @@
#include "gd_script.h"
#include "global_config.h"
#include "os/file_access.h"
+#ifdef TOOLS_ENABLED
+#include "editor/editor_file_system.h"
+#include "editor/editor_settings.h"
+#endif
void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
@@ -1406,6 +1410,17 @@ static void _make_function_hint(const GDParser::FunctionNode *p_func, int p_argi
arghint += ")";
}
+void get_directory_contents(EditorFileSystemDirectory *p_dir, Set<String> &r_list) {
+
+ for (int i = 0; i < p_dir->get_subdir_count(); i++) {
+ get_directory_contents(p_dir->get_subdir(i), r_list);
+ }
+
+ for (int i = 0; i < p_dir->get_file_count(); i++) {
+ r_list.insert("\"" + p_dir->get_file_path(i) + "\"");
+ }
+}
+
static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, String &arghint) {
//print_line("find type arguments?");
@@ -1754,6 +1769,10 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N
const GDParser::BuiltInFunctionNode *fn = static_cast<const GDParser::BuiltInFunctionNode *>(op->arguments[0]);
MethodInfo mi = GDFunctions::get_info(fn->function);
+ if (mi.name == "load" && bool(EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths"))) {
+ get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), result);
+ }
+
arghint = _get_visual_datatype(mi.return_val, false) + " " + GDFunctions::get_func_name(fn->function) + String("(");
for (int i = 0; i < mi.arguments.size(); i++) {
if (i > 0)
@@ -2375,6 +2394,11 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base
}
} break;
+ case GDParser::COMPLETION_PRELOAD: {
+
+ if (EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths"))
+ get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), options);
+ } break;
}
for (Set<String>::Element *E = options.front(); E; E = E->next()) {
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index cd16fef6b3..b02d7f713b 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.cpp
@@ -387,6 +387,13 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool
_set_error("Expected '(' after 'preload'");
return NULL;
}
+ completion_cursor = StringName();
+ completion_type = COMPLETION_PRELOAD;
+ completion_class = current_class;
+ completion_function = current_function;
+ completion_line = tokenizer->get_token_line();
+ completion_block = current_block;
+ completion_found = true;
tokenizer->advance();
String path;
diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h
index 445ad7361c..4f3ca0dc5f 100644
--- a/modules/gdscript/gd_parser.h
+++ b/modules/gdscript/gd_parser.h
@@ -437,6 +437,7 @@ public:
COMPLETION_PARENT_FUNCTION,
COMPLETION_METHOD,
COMPLETION_CALL_ARGUMENTS,
+ COMPLETION_PRELOAD,
COMPLETION_INDEX,
COMPLETION_VIRTUAL_FUNC,
COMPLETION_YIELD,