Skip to content

Commit 96abb87

Browse files
committed
Enable disable-next to control nodes of finer granularity
1 parent c558796 commit 96abb87

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

CodeFormatCore/src/Format/Analyzer/FormatDocAnalyze.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ void FormatDocAnalyze::Analyze(FormatState &f, const LuaSyntaxTree &t) {
1111
for (auto syntaxNode: t.GetSyntaxNodes()) {
1212
switch (syntaxNode.GetTokenKind(t)) {
1313
case TK_SHORT_COMMENT: {
14-
if (syntaxNode.GetParent(t).GetSyntaxKind(t) == LuaSyntaxNodeKind::Block) {
15-
AnalyzeDocFormat(syntaxNode, f, t);
16-
break;
17-
}
14+
AnalyzeDocFormat(syntaxNode, f, t);
15+
break;
1816
}
1917
default: {
2018
break;
@@ -100,7 +98,7 @@ void FormatDocAnalyze::AnalyzeDocFormat(LuaSyntaxNode n, FormatState &f, const L
10098
break;
10199
} else if (action == "disable-next") {
102100
auto nextNode = n.GetNextSibling(t);
103-
while (!nextNode.IsNull(t) && !detail::multi_match::StatementMatch(nextNode.GetSyntaxKind(t))) {
101+
while (!nextNode.IsNull(t) && nextNode.GetTokenKind(t) == TK_SHORT_COMMENT) {
104102
nextNode.ToNext(t);
105103
}
106104
if (nextNode.IsNode(t)) {

Test/src/FormatResult_unitest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,27 @@ local t=123
870870
end
871871
872872
local t = 123
873+
)"));
874+
EXPECT_TRUE(TestHelper::TestFormatted(
875+
R"(
876+
local t = {
877+
---@format disable-next
878+
879+
aa = 123,
880+
---@format disable-next
881+
lcc = 123,
882+
gjopepgo = 123,
883+
}
884+
)",
885+
R"(
886+
local t = {
887+
---@format disable-next
888+
889+
aa = 123,
890+
---@format disable-next
891+
lcc = 123,
892+
gjopepgo = 123,
893+
}
873894
)"));
874895
}
875896

0 commit comments

Comments
 (0)