From 3485253a98f263bdd8ecf7e3cb5a56af6917b2b5 Mon Sep 17 00:00:00 2001 From: Math <175355178+maffeus@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:46:35 -0300 Subject: [PATCH 1/7] Insert newline for empty single-line documentation comments --- src/DocumentationParser.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DocumentationParser.cpp b/src/DocumentationParser.cpp index f5e0fe83..5eae919e 100644 --- a/src/DocumentationParser.cpp +++ b/src/DocumentationParser.cpp @@ -405,6 +405,10 @@ std::vector WorkspaceFolder::getComments(const Luau::ModuleName& mo { comments.emplace_back(commentText.substr(4)); } + else if (commentText == "---") + { + comments.emplace_back("\n"); + } } else if (comment.type == Luau::Lexeme::Type::BlockComment) { From 3e7fd2daf504e3bae1002531e29a5f3ec4af75b0 Mon Sep 17 00:00:00 2001 From: Math <175355178+maffeus@users.noreply.github.com> Date: Sat, 1 Feb 2025 11:16:46 -0300 Subject: [PATCH 2/7] Add `print_comments_multiline_equals_singleline` test to `Documentation.test.cpp` --- tests/Documentation.test.cpp | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/Documentation.test.cpp b/tests/Documentation.test.cpp index 6858edf0..4fc45982 100644 --- a/tests/Documentation.test.cpp +++ b/tests/Documentation.test.cpp @@ -483,4 +483,60 @@ TEST_CASE_FIXTURE(Fixture, "ignored_tags") "\n- `x` number -- Testing"); } +TEST_CASE_FIXTURE(Fixture, "print_comments_multiline_equals_singleline") +{ + auto result = check(R"( + --[=[ + Adds 5 to the input number + + ```lua + do + local x = 5 + end + ``` + + @param x number -- Testing + ]=] + function foo_ml(x: number) + return x + 5 + end + + --- Adds 5 to the input number + --- + --- ```lua + --- do + --- local x = 5 + --- end + --- ``` + --- + --- @param x number -- Testing + function foo_sl(a: number, b: number): number + if b == 0 then + error("division by 0") + end + return a / b + end + )"); + + REQUIRE_EQ(0, result.errors.size()); + + auto ty_ml = requireType("foo_ml"); + auto ftv_ml = Luau::get(ty); + REQUIRE(ftv_ml); + REQUIRE(ftv_ml->definition); + + auto ty_sl = requireType("foo_sl"); + auto ftv_sl = Luau::get(ty); + REQUIRE(ftv_sl); + REQUIRE(ftv_sl->definition); + + auto comments_ml = getComments(ftv_ml->definition->definitionLocation); + auto documentation_ml = printMoonwaveDocumentation(comments_ml); + + auto comments_sl = getComments(ftv_sl->definition->definitionLocation); + auto documentation_sl = printMoonwaveDocumentation(comments_sl); + + CHECK_EQ(documentation_ml, documentation_sl); +} + TEST_SUITE_END(); From c7e665c929cfdaafd87f6fe48199b9301566f866 Mon Sep 17 00:00:00 2001 From: Math <175355178+maffeus@users.noreply.github.com> Date: Sat, 1 Feb 2025 11:41:13 -0300 Subject: [PATCH 3/7] I forgot to change `foo_sl` --- tests/Documentation.test.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/Documentation.test.cpp b/tests/Documentation.test.cpp index 4fc45982..2e84580c 100644 --- a/tests/Documentation.test.cpp +++ b/tests/Documentation.test.cpp @@ -511,10 +511,7 @@ TEST_CASE_FIXTURE(Fixture, "print_comments_multiline_equals_singleline") --- --- @param x number -- Testing function foo_sl(a: number, b: number): number - if b == 0 then - error("division by 0") - end - return a / b + return x + 5 end )"); From cf243ca19f3df4c75672caf6456ef418960ba503 Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Sat, 8 Feb 2025 18:43:57 +0100 Subject: [PATCH 4/7] Fix compilation of test case --- tests/Documentation.test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Documentation.test.cpp b/tests/Documentation.test.cpp index 2e84580c..62daec1c 100644 --- a/tests/Documentation.test.cpp +++ b/tests/Documentation.test.cpp @@ -510,7 +510,7 @@ TEST_CASE_FIXTURE(Fixture, "print_comments_multiline_equals_singleline") --- ``` --- --- @param x number -- Testing - function foo_sl(a: number, b: number): number + function foo_sl(x: number) return x + 5 end )"); @@ -518,12 +518,12 @@ TEST_CASE_FIXTURE(Fixture, "print_comments_multiline_equals_singleline") REQUIRE_EQ(0, result.errors.size()); auto ty_ml = requireType("foo_ml"); - auto ftv_ml = Luau::get(ty); + auto ftv_ml = Luau::get(ty_ml); REQUIRE(ftv_ml); REQUIRE(ftv_ml->definition); auto ty_sl = requireType("foo_sl"); - auto ftv_sl = Luau::get(ty); + auto ftv_sl = Luau::get(ty_sl); REQUIRE(ftv_sl); REQUIRE(ftv_sl->definition); From f30ba48e98aecd975c0821b003f03688cf5a782d Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Sat, 8 Feb 2025 18:44:17 +0100 Subject: [PATCH 5/7] Add another test case --- tests/Documentation.test.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Documentation.test.cpp b/tests/Documentation.test.cpp index 62daec1c..fa055e60 100644 --- a/tests/Documentation.test.cpp +++ b/tests/Documentation.test.cpp @@ -483,6 +483,29 @@ TEST_CASE_FIXTURE(Fixture, "ignored_tags") "\n- `x` number -- Testing"); } +TEST_CASE_FIXTURE(Fixture, "singleline_comments_preserve_newlines") +{ + auto result = check(R"( + --- @class MyClass + --- + --- A sample class. + local MyClass = {} + )"); + + REQUIRE_EQ(0, result.errors.size()); + + auto ty = requireType("MyClass"); + auto ttv = Luau::get(ty); + REQUIRE(ttv); + + auto comments = getComments(ttv->definitionLocation); + REQUIRE_EQ(3, comments.size()); + + CHECK_EQ("@class MyClass", comments[0]); + CHECK_EQ("\n", comments[1]); + CHECK_EQ("A sample class.", comments[2]); +} + TEST_CASE_FIXTURE(Fixture, "print_comments_multiline_equals_singleline") { auto result = check(R"( From 9b247dbd4ff466ad622009ca92549480daa8974d Mon Sep 17 00:00:00 2001 From: Math <175355178+maffeus@users.noreply.github.com> Date: Sun, 9 Feb 2025 04:29:44 -0300 Subject: [PATCH 6/7] Add JohnnyMorganz/luau-lsp#917 to changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29f10191..77f8e6fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed + +- Single-line documentation comments (`---`) now correctly preserve newlines ([#917](https://github.com/JohnnyMorganz/luau-lsp/pull/917)). + ## [1.39.1] - 2025-02-08 ### Fixed From 48fc27cdd30f9a63ed3d92b5279b42a3a3d53cad Mon Sep 17 00:00:00 2001 From: Math <175355178+maffeus@users.noreply.github.com> Date: Sun, 9 Feb 2025 04:37:00 -0300 Subject: [PATCH 7/7] Remove `print_comments_multiline_equals_singleline` test --- tests/Documentation.test.cpp | 53 ------------------------------------ 1 file changed, 53 deletions(-) diff --git a/tests/Documentation.test.cpp b/tests/Documentation.test.cpp index fa055e60..a5258f42 100644 --- a/tests/Documentation.test.cpp +++ b/tests/Documentation.test.cpp @@ -506,57 +506,4 @@ TEST_CASE_FIXTURE(Fixture, "singleline_comments_preserve_newlines") CHECK_EQ("A sample class.", comments[2]); } -TEST_CASE_FIXTURE(Fixture, "print_comments_multiline_equals_singleline") -{ - auto result = check(R"( - --[=[ - Adds 5 to the input number - - ```lua - do - local x = 5 - end - ``` - - @param x number -- Testing - ]=] - function foo_ml(x: number) - return x + 5 - end - - --- Adds 5 to the input number - --- - --- ```lua - --- do - --- local x = 5 - --- end - --- ``` - --- - --- @param x number -- Testing - function foo_sl(x: number) - return x + 5 - end - )"); - - REQUIRE_EQ(0, result.errors.size()); - - auto ty_ml = requireType("foo_ml"); - auto ftv_ml = Luau::get(ty_ml); - REQUIRE(ftv_ml); - REQUIRE(ftv_ml->definition); - - auto ty_sl = requireType("foo_sl"); - auto ftv_sl = Luau::get(ty_sl); - REQUIRE(ftv_sl); - REQUIRE(ftv_sl->definition); - - auto comments_ml = getComments(ftv_ml->definition->definitionLocation); - auto documentation_ml = printMoonwaveDocumentation(comments_ml); - - auto comments_sl = getComments(ftv_sl->definition->definitionLocation); - auto documentation_sl = printMoonwaveDocumentation(comments_sl); - - CHECK_EQ(documentation_ml, documentation_sl); -} - TEST_SUITE_END();