forked from OSchip/llvm-project
clang-format: Add special comments to disable formatting.
With this patch: int ThisWillBeFormatted; // clang-format off int ThisWontBeFormatted; // clang-format on int Formatted; This is for regions where a significantly nicer code layout can be found knowing the content of the code. This fixes llvm.org/PR20463. llvm-svn: 214966
This commit is contained in:
parent
99917946da
commit
4718944399
|
@ -1648,6 +1648,8 @@ private:
|
|||
SmallVector<FormatToken *, 16> Tokens;
|
||||
SmallVector<IdentifierInfo *, 8> ForEachMacros;
|
||||
|
||||
bool FormattingDisabled = false;
|
||||
|
||||
void readRawToken(FormatToken &Tok) {
|
||||
Lex.LexFromRawLexer(Tok.Tok);
|
||||
Tok.TokenText = StringRef(SourceMgr.getCharacterData(Tok.Tok.getLocation()),
|
||||
|
@ -1663,6 +1665,11 @@ private:
|
|||
Tok.Tok.setKind(tok::char_constant);
|
||||
}
|
||||
}
|
||||
if (Tok.is(tok::comment) && Tok.TokenText == "// clang-format on")
|
||||
FormattingDisabled = false;
|
||||
Tok.Finalized = FormattingDisabled;
|
||||
if (Tok.is(tok::comment) && Tok.TokenText == "// clang-format off")
|
||||
FormattingDisabled = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -9133,5 +9133,18 @@ TEST_F(FormatTest, HandleConflictMarkers) {
|
|||
"int i;\n"));
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, DisableRegions) {
|
||||
EXPECT_EQ("int i;\n"
|
||||
"// clang-format off\n"
|
||||
" int j;\n"
|
||||
"// clang-format on\n"
|
||||
"int k;",
|
||||
format(" int i;\n"
|
||||
" // clang-format off\n"
|
||||
" int j;\n"
|
||||
" // clang-format on\n"
|
||||
" int k;"));
|
||||
}
|
||||
|
||||
} // end namespace tooling
|
||||
} // end namespace clang
|
||||
|
|
Loading…
Reference in New Issue