summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/io/file_access_pack.cpp16
-rw-r--r--core/string_builder.cpp3
-rw-r--r--core/ustring.cpp6
-rw-r--r--core/ustring.h2
-rw-r--r--core/variant_call.cpp2
-rw-r--r--doc/classes/ProjectSettings.xml8
-rw-r--r--doc/classes/StreamPeer.xml8
-rw-r--r--doc/classes/String.xml14
-rw-r--r--doc/classes/TreeItem.xml9
-rw-r--r--editor/editor_fonts.cpp1
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp2
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp2
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp35
-rw-r--r--editor/plugins/spatial_editor_plugin.h2
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h1
-rw-r--r--main/main.cpp7
-rw-r--r--modules/gdscript/language_server/gdscript_extend_parser.cpp70
-rw-r--r--modules/gdscript/language_server/gdscript_extend_parser.h5
-rw-r--r--modules/gdscript/language_server/gdscript_language_protocol.cpp6
-rw-r--r--modules/gdscript/language_server/gdscript_text_document.cpp73
-rw-r--r--modules/gdscript/language_server/gdscript_text_document.h2
-rw-r--r--modules/gdscript/language_server/gdscript_workspace.cpp26
-rw-r--r--modules/gdscript/language_server/gdscript_workspace.h2
-rw-r--r--modules/gdscript/language_server/lsp.hpp144
-rw-r--r--scene/gui/tree.cpp45
-rw-r--r--scene/gui/tree.h4
26 files changed, 344 insertions, 151 deletions
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index 54ef753b7c..34d3eb5344 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -151,6 +151,7 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files)
magic = f->get_32();
if (magic != 0x43504447) {
+ f->close();
memdelete(f);
return false;
}
@@ -162,6 +163,7 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files)
magic = f->get_32();
if (magic != 0x43504447) {
+ f->close();
memdelete(f);
return false;
}
@@ -172,8 +174,16 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files)
uint32_t ver_minor = f->get_32();
f->get_32(); // ver_rev
- ERR_FAIL_COND_V_MSG(version != PACK_VERSION, false, "Pack version unsupported: " + itos(version) + ".");
- ERR_FAIL_COND_V_MSG(ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR), false, "Pack created with a newer version of the engine: " + itos(ver_major) + "." + itos(ver_minor) + ".");
+ if (version != PACK_VERSION) {
+ f->close();
+ memdelete(f);
+ ERR_FAIL_V_MSG(false, "Pack version unsupported: " + itos(version) + ".");
+ }
+ if (ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR)) {
+ f->close();
+ memdelete(f);
+ ERR_FAIL_V_MSG(false, "Pack created with a newer version of the engine: " + itos(ver_major) + "." + itos(ver_minor) + ".");
+ }
for (int i = 0; i < 16; i++) {
//reserved
@@ -200,6 +210,8 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files)
PackedData::get_singleton()->add_path(p_path, path, ofs, size, md5, this, p_replace_files);
};
+ f->close();
+ memdelete(f);
return true;
};
diff --git a/core/string_builder.cpp b/core/string_builder.cpp
index 35526e0d70..22eed70f8b 100644
--- a/core/string_builder.cpp
+++ b/core/string_builder.cpp
@@ -34,6 +34,9 @@
StringBuilder &StringBuilder::append(const String &p_string) {
+ if (p_string == String())
+ return *this;
+
strings.push_back(p_string);
appended_strings.push_back(-1);
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 07caa3a018..f029ae4200 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -3288,9 +3288,7 @@ String String::simplify_path() const {
static int _humanize_digits(int p_num) {
- if (p_num < 10)
- return 2;
- else if (p_num < 100)
+ if (p_num < 100)
return 2;
else if (p_num < 1024)
return 1;
@@ -3298,7 +3296,7 @@ static int _humanize_digits(int p_num) {
return 0;
}
-String String::humanize_size(size_t p_size) {
+String String::humanize_size(uint64_t p_size) {
uint64_t _div = 1;
Vector<String> prefixes;
diff --git a/core/ustring.h b/core/ustring.h
index 87a14bfad7..15e2c07d9f 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -322,7 +322,7 @@ public:
String path_to_file(const String &p_path) const;
String get_base_dir() const;
String get_file() const;
- static String humanize_size(size_t p_size);
+ static String humanize_size(uint64_t p_size);
String simplify_path() const;
String xml_escape(bool p_escape_quotes = false) const;
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 53f64fcde6..1b5ca9d3e5 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -284,6 +284,7 @@ struct _VariantCall {
VCALL_LOCALMEM0R(String, sha1_buffer);
VCALL_LOCALMEM0R(String, sha256_buffer);
VCALL_LOCALMEM0R(String, empty);
+ VCALL_LOCALMEM1R(String, humanize_size);
VCALL_LOCALMEM0R(String, is_abs_path);
VCALL_LOCALMEM0R(String, is_rel_path);
VCALL_LOCALMEM0R(String, get_base_dir);
@@ -1561,6 +1562,7 @@ void register_variant_methods() {
ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, sha1_buffer, varray());
ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, sha256_buffer, varray());
ADDFUNC0R(STRING, BOOL, String, empty, varray());
+ ADDFUNC1R(STRING, STRING, String, humanize_size, INT, "size", varray());
ADDFUNC0R(STRING, BOOL, String, is_abs_path, varray());
ADDFUNC0R(STRING, BOOL, String, is_rel_path, varray());
ADDFUNC0R(STRING, STRING, String, get_base_dir, varray());
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 7d009252c0..4d82de2ac5 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -403,19 +403,19 @@
Sets the window to full screen when it starts.
</member>
<member name="display/window/size/height" type="int" setter="" getter="" default="600">
- Sets the main window height. On desktop, this is the default window size. Stretch mode settings use this also as a reference when enabled.
+ Sets the game's main viewport height. On desktop platforms, this is the default window size. Stretch mode settings also use also as a reference when enabled.
</member>
<member name="display/window/size/resizable" type="bool" setter="" getter="" default="true">
Allows the window to be resizable by default.
</member>
<member name="display/window/size/test_height" type="int" setter="" getter="" default="0">
- If greater than zero, uses a different height for the window when running from the editor. The main use for this is to test with stretch modes.
+ If greater than zero, overrides the window height when running the game. Useful for testing stretch modes.
</member>
<member name="display/window/size/test_width" type="int" setter="" getter="" default="0">
- If greater than zero, uses a different width for the window when running from the editor. The main use for this is to test with stretch modes.
+ If greater than zero, overrides the window width when running the game. Useful for testing stretch modes.
</member>
<member name="display/window/size/width" type="int" setter="" getter="" default="1024">
- Sets the main window width. On desktop platforms, this is the default window size. Stretch mode settings use this also as a reference when enabled.
+ Sets the game's main viewport width. On desktop platforms, this is the default window size. Stretch mode settings also use this as a reference when enabled.
</member>
<member name="display/window/vsync/use_vsync" type="bool" setter="" getter="" default="true">
If [code]true[/code], enables vertical synchronization. This eliminates tearing that may appear in moving scenes, at the cost of higher input latency and stuttering at lower framerates. If [code]false[/code], vertical synchronization will be disabled, however, many platforms will enforce it regardless (such as mobile platforms and HTML5).
diff --git a/doc/classes/StreamPeer.xml b/doc/classes/StreamPeer.xml
index 678c587f8d..2a1919071a 100644
--- a/doc/classes/StreamPeer.xml
+++ b/doc/classes/StreamPeer.xml
@@ -211,6 +211,10 @@
</argument>
<description>
Puts a zero-terminated ASCII string into the stream prepended by a 32-bit unsigned integer representing its size.
+ Note: To put an ASCII string without prepending its size, you can use [method put_data]:
+ [codeblock]
+ put_data("Hello world".to_ascii())
+ [/codeblock]
</description>
</method>
<method name="put_u16">
@@ -256,6 +260,10 @@
</argument>
<description>
Puts a zero-terminated UTF-8 string into the stream prepended by a 32 bits unsigned integer representing its size.
+ Note: To put an UTF-8 string without prepending its size, you can use [method put_data]:
+ [codeblock]
+ put_data("Hello world".to_utf8())
+ [/codeblock]
</description>
</method>
<method name="put_var">
diff --git a/doc/classes/String.xml b/doc/classes/String.xml
index 03bc2095c0..cf152e716e 100644
--- a/doc/classes/String.xml
+++ b/doc/classes/String.xml
@@ -437,6 +437,20 @@
[/codeblock]
</description>
</method>
+ <method name="humanize_size">
+ <return type="String">
+ </return>
+ <argument index="0" name="size" type="int">
+ </argument>
+ <description>
+ Converts [code]size[/code] represented as number of bytes to human-readable format using internationalized set of data size units, namely: B, KiB, MiB, GiB, TiB, PiB, EiB. Note that the next smallest unit is picked automatically to hold at most 1024 units.
+ [codeblock]
+ var bytes = 133790307
+ var size = String.humanize_size(bytes)
+ print(size) # prints "127.5 MiB"
+ [/codeblock]
+ </description>
+ </method>
<method name="insert">
<return type="String">
</return>
diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml
index 1ab5c58a30..01d690589b 100644
--- a/doc/classes/TreeItem.xml
+++ b/doc/classes/TreeItem.xml
@@ -585,6 +585,15 @@
Sets the given column's tooltip text.
</description>
</method>
+ <method name="call_recursive" qualifiers="vararg">
+ <return type="Variant">
+ </return>
+ <argument index="0" name="method" type="String">
+ </argument>
+ <description>
+ Calls the [code]method[/code] on the actual TreeItem and its children recursively. Pass parameters as a comma separated list.
+ </description>
+ </method>
</methods>
<members>
<member name="collapsed" type="bool" setter="set_collapsed" getter="is_collapsed">
diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp
index 55cae35a4a..b6d27d84e0 100644
--- a/editor/editor_fonts.cpp
+++ b/editor/editor_fonts.cpp
@@ -232,6 +232,7 @@ void editor_register_fonts(Ref<Theme> p_theme) {
// Default font
MAKE_DEFAULT_FONT(df, default_font_size);
p_theme->set_default_theme_font(df);
+ p_theme->set_font("main", "EditorFonts", df);
// Bold font
MAKE_BOLD_FONT(df_bold, default_font_size);
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index 75a7099ec4..80353bab01 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -484,6 +484,8 @@ double AnimationPlayerEditor::_get_editor_step() const {
if (track_editor->is_snap_enabled()) {
const String current = player->get_assigned_animation();
const Ref<Animation> anim = player->get_animation(current);
+ ERR_FAIL_COND_V(!anim.is_valid(), 0.0);
+
// Use more precise snapping when holding Shift
return Input::get_singleton()->is_key_pressed(KEY_SHIFT) ? anim->get_step() * 0.25 : anim->get_step();
}
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index b1e8ce20d6..b7d36ce75a 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -5135,6 +5135,8 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
warning_child_of_container = memnew(Label);
warning_child_of_container->hide();
warning_child_of_container->set_text(TTR("Warning: Children of a container get their position and size determined only by their parent."));
+ warning_child_of_container->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("warning_color", "Editor"));
+ warning_child_of_container->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("main", "EditorFonts"));
add_control_to_info_overlay(warning_child_of_container);
h_scroll = memnew(HScrollBar);
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index 127cead57f..095350d0e1 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -2172,7 +2172,7 @@ void SpatialEditorViewport::_notification(int p_what) {
VisualInstance *vi = Object::cast_to<VisualInstance>(sp);
- se->aabb = vi ? vi->get_aabb() : AABB(Vector3(-0.2, -0.2, -0.2), Vector3(0.4, 0.4, 0.4));
+ se->aabb = vi ? vi->get_aabb() : _calculate_spatial_bounds(sp);
Transform t = sp->get_global_gizmo_transform();
t.translate(se->aabb.position);
@@ -3209,20 +3209,35 @@ Vector3 SpatialEditorViewport::_get_instance_position(const Point2 &p_pos) const
return point + offset;
}
-AABB SpatialEditorViewport::_calculate_spatial_bounds(const Spatial *p_parent, const AABB &p_bounds) {
- AABB bounds = p_bounds;
+AABB SpatialEditorViewport::_calculate_spatial_bounds(const Spatial *p_parent, bool p_exclude_toplevel_transform) {
+ AABB bounds;
+
+ const MeshInstance *mesh_instance = Object::cast_to<MeshInstance>(p_parent);
+ if (mesh_instance) {
+ bounds = mesh_instance->get_aabb();
+ }
+
for (int i = 0; i < p_parent->get_child_count(); i++) {
Spatial *child = Object::cast_to<Spatial>(p_parent->get_child(i));
if (child) {
- MeshInstance *mesh_instance = Object::cast_to<MeshInstance>(child);
- if (mesh_instance) {
- AABB mesh_instance_bounds = mesh_instance->get_aabb();
- mesh_instance_bounds.position += mesh_instance->get_global_gizmo_transform().origin - p_parent->get_global_gizmo_transform().origin;
- bounds.merge_with(mesh_instance_bounds);
+ AABB child_bounds = _calculate_spatial_bounds(child, false);
+
+ if (bounds.size == Vector3() && p_parent->get_class_name() == StringName("Spatial")) {
+ bounds = child_bounds;
+ } else {
+ bounds.merge_with(child_bounds);
}
- bounds = _calculate_spatial_bounds(child, bounds);
}
}
+
+ if (bounds.size == Vector3() && p_parent->get_class_name() != StringName("Spatial")) {
+ bounds = AABB(Vector3(-0.2, -0.2, -0.2), Vector3(0.4, 0.4, 0.4));
+ }
+
+ if (!p_exclude_toplevel_transform) {
+ bounds = p_parent->get_transform().xform(bounds);
+ }
+
return bounds;
}
@@ -3249,7 +3264,7 @@ void SpatialEditorViewport::_create_preview(const Vector<String> &files) const {
editor->get_scene_root()->add_child(preview_node);
}
}
- *preview_bounds = _calculate_spatial_bounds(preview_node, AABB());
+ *preview_bounds = _calculate_spatial_bounds(preview_node);
}
void SpatialEditorViewport::_remove_preview() {
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index 208495c2f5..fe91c33642 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -375,7 +375,7 @@ private:
Point2i _get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_ev_mouse_motion) const;
Vector3 _get_instance_position(const Point2 &p_pos) const;
- static AABB _calculate_spatial_bounds(const Spatial *p_parent, const AABB &p_bounds);
+ static AABB _calculate_spatial_bounds(const Spatial *p_parent, bool p_exclude_toplevel_transform = true);
void _create_preview(const Vector<String> &files) const;
void _remove_preview();
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index 700e7cfd7d..6f77641936 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -137,6 +137,7 @@ class VisualShaderEditor : public VBoxContainer {
category = p_category;
sub_category = p_sub_category;
description = p_description;
+ sub_func = 0;
sub_func_str = p_sub_func;
return_type = p_return_type;
mode = p_mode;
diff --git a/main/main.cpp b/main/main.cpp
index 6df02af3a5..42c90fc027 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -982,10 +982,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
video_mode.height = GLOBAL_GET("display/window/size/height");
if (globals->has_setting("display/window/size/test_width") && globals->has_setting("display/window/size/test_height")) {
+
int tw = globals->get("display/window/size/test_width");
- int th = globals->get("display/window/size/test_height");
- if (tw > 0 && th > 0) {
+ if (tw > 0) {
video_mode.width = tw;
+ }
+ int th = globals->get("display/window/size/test_height");
+ if (th > 0) {
video_mode.height = th;
}
}
diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp
index ae44137fef..03d731a5f0 100644
--- a/modules/gdscript/language_server/gdscript_extend_parser.cpp
+++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp
@@ -157,7 +157,7 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
r_symbol.selectionRange.start.line = r_symbol.range.start.line;
r_symbol.detail = "class " + r_symbol.name;
bool is_root_class = &r_symbol == &class_symbol;
- r_symbol.documentation = parse_documentation_as_markdown(is_root_class ? 0 : LINE_NUMBER_TO_INDEX(p_class->line), is_root_class);
+ r_symbol.documentation = parse_documentation(is_root_class ? 0 : LINE_NUMBER_TO_INDEX(p_class->line), is_root_class);
for (int i = 0; i < p_class->variables.size(); ++i) {
@@ -184,7 +184,7 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
symbol.detail += " = " + JSON::print(m.default_value);
}
- symbol.documentation = parse_documentation_as_markdown(line);
+ symbol.documentation = parse_documentation(line);
symbol.uri = uri;
symbol.script_path = path;
@@ -204,7 +204,7 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
symbol.range.end.line = symbol.range.start.line;
symbol.range.end.character = lines[line].length();
symbol.selectionRange.start.line = symbol.range.start.line;
- symbol.documentation = parse_documentation_as_markdown(line);
+ symbol.documentation = parse_documentation(line);
symbol.uri = uri;
symbol.script_path = path;
symbol.detail = "signal " + signal.name + "(";
@@ -233,7 +233,7 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
symbol.range.end.line = symbol.range.start.line;
symbol.range.end.character = lines[line].length();
symbol.selectionRange.start.line = symbol.range.start.line;
- symbol.documentation = parse_documentation_as_markdown(line);
+ symbol.documentation = parse_documentation(line);
symbol.uri = uri;
symbol.script_path = path;
@@ -301,7 +301,7 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN
r_symbol.range.end.line = MAX(p_func->body->end_line - 2, p_func->body->line);
r_symbol.range.end.character = lines[r_symbol.range.end.line].length();
r_symbol.selectionRange.start.line = r_symbol.range.start.line;
- r_symbol.documentation = parse_documentation_as_markdown(line);
+ r_symbol.documentation = parse_documentation(line);
r_symbol.uri = uri;
r_symbol.script_path = path;
@@ -359,65 +359,11 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN
if (var->datatype.kind != GDScriptParser::DataType::UNRESOLVED) {
symbol.detail += ": " + var->datatype.to_string();
}
- symbol.documentation = parse_documentation_as_markdown(line);
+ symbol.documentation = parse_documentation(line);
r_symbol.children.push_back(symbol);
}
}
-String ExtendGDScriptParser::marked_documentation(const String &p_bbcode) {
-
- String markdown = p_bbcode.strip_edges();
-
- Vector<String> lines = markdown.split("\n");
- bool in_code_block = false;
- int code_block_indent = -1;
-
- markdown = "";
- for (int i = 0; i < lines.size(); i++) {
- String line = lines[i];
- int block_start = line.find("[codeblock]");
- if (block_start != -1) {
- code_block_indent = block_start;
- in_code_block = true;
- line = "\n";
- } else if (in_code_block) {
- line = "\t" + line.substr(code_block_indent, line.length());
- }
-
- if (in_code_block && line.find("[/codeblock]") != -1) {
- line = "\n";
- in_code_block = false;
- }
-
- if (!in_code_block) {
- line = line.strip_edges();
- line = line.replace("[code]", "`");
- line = line.replace("[/code]", "`");
- line = line.replace("[i]", "*");
- line = line.replace("[/i]", "*");
- line = line.replace("[b]", "**");
- line = line.replace("[/b]", "**");
- line = line.replace("[u]", "__");
- line = line.replace("[/u]", "__");
- line = line.replace("[method ", "`");
- line = line.replace("[member ", "`");
- line = line.replace("[signal ", "`");
- line = line.replace("[enum ", "`");
- line = line.replace("[constant ", "`");
- line = line.replace("[", "`");
- line = line.replace("]", "`");
- }
-
- if (!in_code_block && i < lines.size() - 1) {
- line += "\n\n";
- } else if (i < lines.size() - 1) {
- line += "\n";
- }
- markdown += line;
- }
- return markdown;
-}
-
String ExtendGDScriptParser::parse_documentation(int p_line, bool p_docs_down) {
ERR_FAIL_INDEX_V(p_line, lines.size(), String());
@@ -576,10 +522,6 @@ const lsp::DocumentSymbol *ExtendGDScriptParser::search_symbol_defined_at_line(i
return ret;
}
-String ExtendGDScriptParser::parse_documentation_as_markdown(int p_line, bool p_docs_down) {
- return marked_documentation(parse_documentation(p_line, p_docs_down));
-}
-
const lsp::DocumentSymbol *ExtendGDScriptParser::get_symbol_defined_at_line(int p_line) const {
if (p_line <= 0) {
return &class_symbol;
diff --git a/modules/gdscript/language_server/gdscript_extend_parser.h b/modules/gdscript/language_server/gdscript_extend_parser.h
index 71db78c245..a6e0ca5534 100644
--- a/modules/gdscript/language_server/gdscript_extend_parser.h
+++ b/modules/gdscript/language_server/gdscript_extend_parser.h
@@ -75,11 +75,6 @@ class ExtendGDScriptParser : public GDScriptParser {
Array member_completions;
- String parse_documentation_as_markdown(int p_line, bool p_docs_down = false);
-
-public:
- static String marked_documentation(const String &p_bbcode);
-
public:
_FORCE_INLINE_ const String &get_path() const { return path; }
_FORCE_INLINE_ const Vector<String> &get_lines() const { return lines; }
diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp
index ce3de9bc3b..ae2aaf6aee 100644
--- a/modules/gdscript/language_server/gdscript_language_protocol.cpp
+++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp
@@ -153,7 +153,13 @@ Error GDScriptLanguageProtocol::start(int p_port) {
}
void GDScriptLanguageProtocol::stop() {
+ const int *ptr = clients.next(NULL);
+ while (ptr) {
+ clients.get(*ptr)->close();
+ ptr = clients.next(ptr);
+ }
server->stop();
+ clients.clear();
}
void GDScriptLanguageProtocol::notify_all_clients(const String &p_method, const Variant &p_params) {
diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp
index f51f3671dd..b83db718b8 100644
--- a/modules/gdscript/language_server/gdscript_text_document.cpp
+++ b/modules/gdscript/language_server/gdscript_text_document.cpp
@@ -39,6 +39,7 @@
void GDScriptTextDocument::_bind_methods() {
ClassDB::bind_method(D_METHOD("didOpen"), &GDScriptTextDocument::didOpen);
ClassDB::bind_method(D_METHOD("didChange"), &GDScriptTextDocument::didChange);
+ ClassDB::bind_method(D_METHOD("nativeSymbol"), &GDScriptTextDocument::nativeSymbol);
ClassDB::bind_method(D_METHOD("documentSymbol"), &GDScriptTextDocument::documentSymbol);
ClassDB::bind_method(D_METHOD("completion"), &GDScriptTextDocument::completion);
ClassDB::bind_method(D_METHOD("resolve"), &GDScriptTextDocument::resolve);
@@ -75,6 +76,11 @@ lsp::TextDocumentItem GDScriptTextDocument::load_document_item(const Variant &p_
return doc;
}
+void GDScriptTextDocument::notify_client_show_symbol(const lsp::DocumentSymbol *symbol) {
+ ERR_FAIL_NULL(symbol);
+ GDScriptLanguageProtocol::get_singleton()->notify_client("gdscript/show_native_symbol", symbol->to_json(true));
+}
+
void GDScriptTextDocument::initialize() {
if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
@@ -102,6 +108,21 @@ void GDScriptTextDocument::initialize() {
}
}
+Variant GDScriptTextDocument::nativeSymbol(const Dictionary &p_params) {
+
+ Variant ret;
+
+ lsp::NativeSymbolInspectParams params;
+ params.load(p_params);
+
+ if (const lsp::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_native_symbol(params)) {
+ ret = symbol->to_json(true);
+ notify_client_show_symbol(symbol);
+ }
+
+ return ret;
+}
+
Array GDScriptTextDocument::documentSymbol(const Dictionary &p_params) {
Dictionary params = p_params["textDocument"];
String uri = params["uri"];
@@ -335,31 +356,35 @@ Array GDScriptTextDocument::definition(const Dictionary &p_params) {
const String &path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(symbol->uri);
if (file_checker->file_exists(path)) {
arr.push_back(location.to_json());
- } else if (!symbol->native_class.empty() && GDScriptLanguageProtocol::get_singleton()->is_goto_native_symbols_enabled()) {
- String id;
- switch (symbol->kind) {
- case lsp::SymbolKind::Class:
- id = "class_name:" + symbol->name;
- break;
- case lsp::SymbolKind::Constant:
- id = "class_constant:" + symbol->native_class + ":" + symbol->name;
- break;
- case lsp::SymbolKind::Property:
- case lsp::SymbolKind::Variable:
- id = "class_property:" + symbol->native_class + ":" + symbol->name;
- break;
- case lsp::SymbolKind::Enum:
- id = "class_enum:" + symbol->native_class + ":" + symbol->name;
- break;
- case lsp::SymbolKind::Method:
- case lsp::SymbolKind::Function:
- id = "class_method:" + symbol->native_class + ":" + symbol->name;
- break;
- default:
- id = "class_global:" + symbol->native_class + ":" + symbol->name;
- break;
+ } else if (!symbol->native_class.empty()) {
+ if (GDScriptLanguageProtocol::get_singleton()->is_goto_native_symbols_enabled()) {
+ String id;
+ switch (symbol->kind) {
+ case lsp::SymbolKind::Class:
+ id = "class_name:" + symbol->name;
+ break;
+ case lsp::SymbolKind::Constant:
+ id = "class_constant:" + symbol->native_class + ":" + symbol->name;
+ break;
+ case lsp::SymbolKind::Property:
+ case lsp::SymbolKind::Variable:
+ id = "class_property:" + symbol->native_class + ":" + symbol->name;
+ break;
+ case lsp::SymbolKind::Enum:
+ id = "class_enum:" + symbol->native_class + ":" + symbol->name;
+ break;
+ case lsp::SymbolKind::Method:
+ case lsp::SymbolKind::Function:
+ id = "class_method:" + symbol->native_class + ":" + symbol->name;
+ break;
+ default:
+ id = "class_global:" + symbol->native_class + ":" + symbol->name;
+ break;
+ }
+ call_deferred("show_native_symbol_in_editor", id);
+ } else {
+ notify_client_show_symbol(symbol);
}
- call_deferred("show_native_symbol_in_editor", id);
}
} else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
diff --git a/modules/gdscript/language_server/gdscript_text_document.h b/modules/gdscript/language_server/gdscript_text_document.h
index 0b8103f175..235e2c3f6e 100644
--- a/modules/gdscript/language_server/gdscript_text_document.h
+++ b/modules/gdscript/language_server/gdscript_text_document.h
@@ -52,8 +52,10 @@ protected:
private:
lsp::TextDocumentItem load_document_item(const Variant &p_param);
+ void notify_client_show_symbol(const lsp::DocumentSymbol *symbol);
public:
+ Variant nativeSymbol(const Dictionary &p_params);
Array documentSymbol(const Dictionary &p_params);
Array completion(const Dictionary &p_params);
Dictionary resolve(const Dictionary &p_params);
diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp
index b42464aa8a..6baa7e4219 100644
--- a/modules/gdscript/language_server/gdscript_workspace.cpp
+++ b/modules/gdscript/language_server/gdscript_workspace.cpp
@@ -198,7 +198,7 @@ Error GDScriptWorkspace::initialize() {
if (!class_data.inherits.empty()) {
class_symbol.detail += " extends " + class_data.inherits;
}
- class_symbol.documentation = ExtendGDScriptParser::marked_documentation(class_data.brief_description) + "\n" + ExtendGDScriptParser::marked_documentation(class_data.description);
+ class_symbol.documentation = class_data.brief_description + "\n" + class_data.description;
for (int i = 0; i < class_data.constants.size(); i++) {
const DocData::ConstantDoc &const_data = class_data.constants[i];
@@ -211,7 +211,7 @@ Error GDScriptWorkspace::initialize() {
symbol.detail += ": " + const_data.enumeration;
}
symbol.detail += " = " + const_data.value;
- symbol.documentation = ExtendGDScriptParser::marked_documentation(const_data.description);
+ symbol.documentation = const_data.description;
class_symbol.children.push_back(symbol);
}
@@ -232,7 +232,7 @@ Error GDScriptWorkspace::initialize() {
} else {
symbol.detail += ": " + data.type;
}
- symbol.documentation = ExtendGDScriptParser::marked_documentation(data.description);
+ symbol.documentation = data.description;
class_symbol.children.push_back(symbol);
}
@@ -270,7 +270,7 @@ Error GDScriptWorkspace::initialize() {
}
symbol.detail = "func " + class_name + "." + data.name + "(" + params + ") -> " + data.return_type;
- symbol.documentation = ExtendGDScriptParser::marked_documentation(data.description);
+ symbol.documentation = data.description;
class_symbol.children.push_back(symbol);
}
@@ -475,6 +475,24 @@ void GDScriptWorkspace::resolve_related_symbols(const lsp::TextDocumentPositionP
}
}
+const lsp::DocumentSymbol *GDScriptWorkspace::resolve_native_symbol(const lsp::NativeSymbolInspectParams &p_params) {
+
+ if (Map<StringName, lsp::DocumentSymbol>::Element *E = native_symbols.find(p_params.native_class)) {
+ const lsp::DocumentSymbol &symbol = E->get();
+ if (p_params.symbol_name.empty() || p_params.symbol_name == symbol.name) {
+ return &symbol;
+ }
+
+ for (int i = 0; i < symbol.children.size(); ++i) {
+ if (symbol.children[i].name == p_params.symbol_name) {
+ return &(symbol.children[i]);
+ }
+ }
+ }
+
+ return NULL;
+}
+
void GDScriptWorkspace::resolve_document_links(const String &p_uri, List<lsp::DocumentLink> &r_list) {
if (const ExtendGDScriptParser *parser = get_parse_successed_script(get_file_path(p_uri))) {
const List<lsp::DocumentLink> &links = parser->get_document_links();
diff --git a/modules/gdscript/language_server/gdscript_workspace.h b/modules/gdscript/language_server/gdscript_workspace.h
index 23e89ea3f3..a416ae1075 100644
--- a/modules/gdscript/language_server/gdscript_workspace.h
+++ b/modules/gdscript/language_server/gdscript_workspace.h
@@ -80,7 +80,7 @@ public:
const lsp::DocumentSymbol *resolve_symbol(const lsp::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name = "", bool p_func_requred = false);
void resolve_related_symbols(const lsp::TextDocumentPositionParams &p_doc_pos, List<const lsp::DocumentSymbol *> &r_list);
-
+ const lsp::DocumentSymbol *resolve_native_symbol(const lsp::NativeSymbolInspectParams &p_params);
void resolve_document_links(const String &p_uri, List<lsp::DocumentLink> &r_list);
Dictionary generate_script_api(const String &p_path);
diff --git a/modules/gdscript/language_server/lsp.hpp b/modules/gdscript/language_server/lsp.hpp
index e60e28cc15..61a0980c41 100644
--- a/modules/gdscript/language_server/lsp.hpp
+++ b/modules/gdscript/language_server/lsp.hpp
@@ -37,6 +37,9 @@ namespace lsp {
typedef String DocumentUri;
+/** Format BBCode documentation from DocData to markdown */
+static String marked_documentation(const String &p_bbcode);
+
/**
* Text documents are identified using a URI. On the protocol level, URIs are passed as strings.
*/
@@ -282,6 +285,9 @@ struct Command {
}
};
+// Use namespace instead of enumeration to follow the LSP specifications
+// lsp::EnumName::EnumValue is OK but lsp::EnumValue is not
+
namespace TextDocumentSyncKind {
/**
* Documents should not be synced at all.
@@ -592,6 +598,7 @@ struct TextDocumentContentChangeEvent {
}
};
+// Use namespace instead of enumeration to follow the LSP specifications
namespace DiagnosticSeverity {
/**
* Reports an error.
@@ -692,6 +699,7 @@ struct Diagnostic {
}
};
+// Use namespace instead of enumeration to follow the LSP specifications
/**
* Describes the content type that a client supports in various
* result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
@@ -756,6 +764,9 @@ struct MarkupContent {
}
};
+// Use namespace instead of enumeration to follow the LSP specifications
+// lsp::EnumName::EnumValue is OK but lsp::EnumValue is not
+// And here C++ compilers are unhappy with our enumeration name like Color, File, Reference etc.
/**
* The kind of a completion entry.
*/
@@ -787,6 +798,7 @@ static const int Operator = 24;
static const int TypeParameter = 25;
}; // namespace CompletionItemKind
+// Use namespace instead of enumeration to follow the LSP specifications
/**
* Defines whether the insert text in a completion item should be interpreted as
* plain text or a snippet.
@@ -979,36 +991,39 @@ struct CompletionList {
Vector<CompletionItem> items;
};
+// Use namespace instead of enumeration to follow the LSP specifications
+// lsp::EnumName::EnumValue is OK but lsp::EnumValue is not
+// And here C++ compilers are unhappy with our enumeration name like String, Array, Object etc
/**
* A symbol kind.
*/
namespace SymbolKind {
-static const int File = 1;
-static const int Module = 2;
-static const int Namespace = 3;
-static const int Package = 4;
-static const int Class = 5;
-static const int Method = 6;
-static const int Property = 7;
-static const int Field = 8;
-static const int Constructor = 9;
-static const int Enum = 10;
-static const int Interface = 11;
-static const int Function = 12;
-static const int Variable = 13;
-static const int Constant = 14;
-static const int String = 15;
-static const int Number = 16;
-static const int Boolean = 17;
-static const int Array = 18;
-static const int Object = 19;
-static const int Key = 20;
-static const int Null = 21;
-static const int EnumMember = 22;
-static const int Struct = 23;
-static const int Event = 24;
-static const int Operator = 25;
-static const int TypeParameter = 26;
+static const int File = 0;
+static const int Module = 1;
+static const int Namespace = 2;
+static const int Package = 3;
+static const int Class = 4;
+static const int Method = 5;
+static const int Property = 6;
+static const int Field = 7;
+static const int Constructor = 8;
+static const int Enum = 9;
+static const int Interface = 10;
+static const int Function = 11;
+static const int Variable = 12;
+static const int Constant = 13;
+static const int String = 14;
+static const int Number = 15;
+static const int Boolean = 16;
+static const int Array = 17;
+static const int Object = 18;
+static const int Key = 19;
+static const int Null = 20;
+static const int EnumMember = 21;
+static const int Struct = 22;
+static const int Event = 23;
+static const int Operator = 24;
+static const int TypeParameter = 25;
}; // namespace SymbolKind
/**
@@ -1134,7 +1149,7 @@ struct DocumentSymbol {
*/
Vector<DocumentSymbol> children;
- _FORCE_INLINE_ Dictionary to_json() const {
+ Dictionary to_json(bool with_doc = false) const {
Dictionary dict;
dict["name"] = name;
dict["detail"] = detail;
@@ -1142,10 +1157,14 @@ struct DocumentSymbol {
dict["deprecated"] = deprecated;
dict["range"] = range.to_json();
dict["selectionRange"] = selectionRange.to_json();
+ if (with_doc) {
+ dict["documentation"] = documentation;
+ dict["native_class"] = native_class;
+ }
Array arr;
arr.resize(children.size());
for (int i = 0; i < children.size(); i++) {
- arr[i] = children[i].to_json();
+ arr[i] = children[i].to_json(with_doc);
}
dict["children"] = arr;
return dict;
@@ -1177,7 +1196,7 @@ struct DocumentSymbol {
markdown.value = "\t" + detail + "\n\n";
}
if (documentation.length()) {
- markdown.value += documentation + "\n\n";
+ markdown.value += marked_documentation(documentation) + "\n\n";
}
if (script_path.length()) {
markdown.value += "Defined in [" + script_path + "](" + uri + ")";
@@ -1229,6 +1248,17 @@ struct DocumentSymbol {
}
};
+struct NativeSymbolInspectParams {
+
+ String native_class;
+ String symbol_name;
+
+ void load(const Dictionary &p_params) {
+ native_class = p_params["native_class"];
+ symbol_name = p_params["symbol_name"];
+ }
+};
+
/**
* Enum of known range kinds
*/
@@ -1289,6 +1319,7 @@ struct FoldingRange {
}
};
+// Use namespace instead of enumeration to follow the LSP specifications
/**
* How a completion was triggered
*/
@@ -1536,6 +1567,61 @@ struct InitializeResult {
}
};
+/** Format BBCode documentation from DocData to markdown */
+static String marked_documentation(const String &p_bbcode) {
+
+ String markdown = p_bbcode.strip_edges();
+
+ Vector<String> lines = markdown.split("\n");
+ bool in_code_block = false;
+ int code_block_indent = -1;
+
+ markdown = "";
+ for (int i = 0; i < lines.size(); i++) {
+ String line = lines[i];
+ int block_start = line.find("[codeblock]");
+ if (block_start != -1) {
+ code_block_indent = block_start;
+ in_code_block = true;
+ line = "\n";
+ } else if (in_code_block) {
+ line = "\t" + line.substr(code_block_indent, line.length());
+ }
+
+ if (in_code_block && line.find("[/codeblock]") != -1) {
+ line = "\n";
+ in_code_block = false;
+ }
+
+ if (!in_code_block) {
+ line = line.strip_edges();
+ line = line.replace("[code]", "`");
+ line = line.replace("[/code]", "`");
+ line = line.replace("[i]", "*");
+ line = line.replace("[/i]", "*");
+ line = line.replace("[b]", "**");
+ line = line.replace("[/b]", "**");
+ line = line.replace("[u]", "__");
+ line = line.replace("[/u]", "__");
+ line = line.replace("[method ", "`");
+ line = line.replace("[member ", "`");
+ line = line.replace("[signal ", "`");
+ line = line.replace("[enum ", "`");
+ line = line.replace("[constant ", "`");
+ line = line.replace("[", "`");
+ line = line.replace("]", "`");
+ }
+
+ if (!in_code_block && i < lines.size() - 1) {
+ line += "\n\n";
+ } else if (i < lines.size() - 1) {
+ line += "\n";
+ }
+ markdown += line;
+ }
+ return markdown;
+}
+
} // namespace lsp
#endif
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 50b0b12029..1b52796dc7 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -729,6 +729,43 @@ bool TreeItem::is_folding_disabled() const {
return disable_folding;
}
+Variant TreeItem::_call_recursive_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+
+ if (p_argcount < 1) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = 0;
+ return Variant();
+ }
+
+ if (p_args[0]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
+ return Variant();
+ }
+
+ StringName method = *p_args[0];
+
+ call_recursive(method, &p_args[1], p_argcount - 1, r_error);
+ return Variant();
+}
+
+void recursive_call_aux(TreeItem *p_item, const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+ if (!p_item) {
+ return;
+ }
+ p_item->call(p_method, p_args, p_argcount, r_error);
+ TreeItem *c = p_item->get_children();
+ while (c) {
+ recursive_call_aux(c, p_method, p_args, p_argcount, r_error);
+ c = c->get_next();
+ }
+}
+
+void TreeItem::call_recursive(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+ recursive_call_aux(this, p_method, p_args, p_argcount, r_error);
+}
+
void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_cell_mode", "column", "mode"), &TreeItem::set_cell_mode);
@@ -820,6 +857,14 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_disable_folding", "disable"), &TreeItem::set_disable_folding);
ClassDB::bind_method(D_METHOD("is_folding_disabled"), &TreeItem::is_folding_disabled);
+ {
+ MethodInfo mi;
+ mi.name = "call_recursive";
+ mi.arguments.push_back(PropertyInfo(Variant::STRING, "method"));
+
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_recursive", &TreeItem::_call_recursive_bind, mi);
+ }
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collapsed"), "set_collapsed", "is_collapsed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_folding"), "set_disable_folding", "is_folding_disabled");
ADD_PROPERTY(PropertyInfo(Variant::INT, "custom_minimum_height", PROPERTY_HINT_RANGE, "0,1000,1"), "set_custom_minimum_height", "get_custom_minimum_height");
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 47befb0c15..361830173b 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -172,6 +172,8 @@ protected:
remove_child(Object::cast_to<TreeItem>(p_child));
}
+ Variant _call_recursive_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+
public:
/* cell mode */
void set_cell_mode(int p_column, TreeCellMode p_mode);
@@ -280,6 +282,8 @@ public:
void set_disable_folding(bool p_disable);
bool is_folding_disabled() const;
+ void call_recursive(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+
~TreeItem();
};