Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix formatting of GDScript code examples in LSP documentation

cksrb63aff5cb3c6a28
diff --git a/modules/gdscript/language_server/godot_lsp.h b/modules/gdscript/language_server/godot_lsp.h
index 86a739774b5..8cc2b8caf23 100644
--- a/modules/gdscript/language_server/godot_lsp.h
+++ b/modules/gdscript/language_server/godot_lsp.h
@@ -1922,7 +1922,7 @@ static String marked_documentation(const String &p_bbcode, const HashSet<String>
in_codeblock_tag = false;
}
- if (!in_codeblock_tag) {
+ if (!in_codeblock_tag && !in_codeblocks_gdscript_tag) {
line = line.strip_edges();
line = line.replace("[br]", "\n\n");
diff --git a/modules/gdscript/tests/test_lsp.h b/modules/gdscript/tests/test_lsp.h
index f468b4f2ca3..21c5e494895 100644
--- a/modules/gdscript/tests/test_lsp.h
+++ b/modules/gdscript/tests/test_lsp.h
@@ -520,6 +520,9 @@ TEST_SUITE("[Modules][GDScript][LSP][Editor]") {
// NOTE: There is always a GDScript code listing in the built-in class reference.
CHECK_EQ(LSP::marked_documentation("[codeblocks]\n[gdscript]\nprint(hash(\"a\")) # Prints 177670\n[/gdscript]\n[csharp]\nGD.Print(GD.Hash(\"a\")); // Prints 177670\n[/csharp]\n[/codeblocks]", {}),
"```gdscript\nprint(hash(\"a\")) # Prints 177670\n```\n");
+ // Indentation and brackets inside the [gdscript] listing must be preserved.
+ CHECK_EQ(LSP::marked_documentation("[codeblocks]\n[gdscript]\nfunc test(arr):\n\tfor i in 3:\n\t\tprint(arr[i])\n[/gdscript]\n[csharp]\npublic void Test()\n{\n}\n[/csharp]\n[/codeblocks]", {}),
+ "```gdscript\nfunc test(arr):\n\tfor i in 3:\n\t\tprint(arr[i])\n```\n");
// lb and rb are used to insert literal square brackets in markdown.
CHECK_EQ(LSP::marked_documentation("[lb]literal brackets[rb]", {}), "\\[literal brackets\\]");