diff options
Diffstat (limited to 'modules/gdscript')
-rw-r--r-- | modules/gdscript/gd_editor.cpp | 58 | ||||
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 7 | ||||
-rw-r--r-- | modules/gdscript/gd_parser.h | 1 | ||||
-rw-r--r-- | modules/gdscript/gd_script.cpp | 5 | ||||
-rw-r--r-- | modules/gdscript/gd_script.h | 2 |
5 files changed, 67 insertions, 6 deletions
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index ae5bb5694c..ba8df81c15 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -27,10 +27,15 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "editor/editor_settings.h" #include "gd_compiler.h" #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 { @@ -50,11 +55,12 @@ Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const Str "# var a = 2\n" + "# var b = \"textvar\"\n\n" + "func _ready():\n" + - "\t# Called every time the node is added to the scene.\n" + - "\t# Initialization here\n" + - "\tpass\n"; + "%TS%# Called every time the node is added to the scene.\n" + + "%TS%# Initialization here\n" + + "%TS%pass\n"; _template = _template.replace("%BASE%", p_base_class_name); + _template = _template.replace("%TS%", _get_indentation()); Ref<GDScript> script; script.instance(); @@ -1405,6 +1411,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?"); @@ -1753,6 +1770,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) @@ -2374,6 +2395,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()) { @@ -2391,8 +2417,29 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base #endif +String GDScriptLanguage::_get_indentation() const { +#ifdef TOOLS_ENABLED + if (SceneTree::get_singleton()->is_editor_hint()) { + bool use_space_indentation = EDITOR_DEF("text_editor/indent/type", "Tabs") == "Tabs" ? 0 : 1; + + if (use_space_indentation) { + int indent_size = EDITOR_DEF("text_editor/indent/size", 4); + + String space_indent = ""; + for (int i = 0; i < indent_size; i++) { + space_indent += " "; + } + return space_indent; + } + } +#endif + return "\t"; +} + void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { + String indent = _get_indentation(); + Vector<String> lines = p_code.split("\n"); List<int> indent_stack; @@ -2432,8 +2479,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t if (i >= p_from_line) { l = ""; - for (int j = 0; j < indent_stack.size(); j++) - l += "\t"; + for (int j = 0; j < indent_stack.size(); j++) { + l += indent; + } l += st; } else if (i > p_to_line) { 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, diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 2367f60740..173014b138 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -1697,8 +1697,8 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so #ifdef TOOLS_ENABLED while (E->get()->placeholders.size()) { - Object *obj = E->get()->placeholders.front()->get()->get_owner(); + //save instance info List<Pair<StringName, Variant> > state; if (obj->get_script_instance()) { @@ -1706,6 +1706,9 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so obj->get_script_instance()->get_property_state(state); map[obj->get_instance_ID()] = state; obj->set_script(RefPtr()); + } else { + // no instance found. Let's remove it so we don't loop forever + E->get()->placeholders.erase(E->get()->placeholders.front()->get()); } } #endif diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 93f8ee8721..00ae136790 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -384,12 +384,14 @@ public: virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const; virtual Script *create_script() const; virtual bool has_named_classes() const; + virtual bool can_inherit_from_file() { return true; } virtual int find_function(const String &p_function, const String &p_code) const; virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const; virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint); #ifdef TOOLS_ENABLED virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result); #endif + virtual String _get_indentation() const; virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const; virtual void add_global_constant(const StringName &p_variable, const Variant &p_value); |