Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert a newline for empty single-line documentation comments #917

Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/DocumentationParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ std::vector<std::string> 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)
{
Expand Down
23 changes: 23 additions & 0 deletions tests/Documentation.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,27 @@ 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<Luau::TableType>(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_SUITE_END();
Loading