mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-28 20:41:07 +00:00
[clangd] Better handling \n
in the synthesized diagnostic message.
The newline-eof fix was rendered as "insert '...'", this patch special-case it. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D117294
This commit is contained in:
parent
00b77d917c
commit
64c108c9e4
@ -631,7 +631,10 @@ void StoreDiags::EndSourceFile() {
|
||||
/// the result is not too large and does not contain newlines.
|
||||
static void writeCodeToFixMessage(llvm::raw_ostream &OS, llvm::StringRef Code) {
|
||||
constexpr unsigned MaxLen = 50;
|
||||
|
||||
if (Code == "\n") {
|
||||
OS << "\\n";
|
||||
return;
|
||||
}
|
||||
// Only show the first line if there are many.
|
||||
llvm::StringRef R = Code.split('\n').first;
|
||||
// Shorten the message if it's too long.
|
||||
|
@ -623,6 +623,15 @@ n]] = 10; // error-ok
|
||||
Fix(Source.range(), "ident", "change 'ide\\…' to 'ident'"))));
|
||||
}
|
||||
|
||||
TEST(DiagnosticTest, NewLineFixMessage) {
|
||||
Annotations Source("int a;[[]]");
|
||||
TestTU TU = TestTU::withCode(Source.code());
|
||||
TU.ExtraArgs = {"-Wnewline-eof"};
|
||||
EXPECT_THAT(
|
||||
*TU.build().getDiagnostics(),
|
||||
ElementsAre(WithFix((Fix(Source.range(), "\n", "insert '\\n'")))));
|
||||
}
|
||||
|
||||
TEST(DiagnosticTest, ClangTidySuppressionCommentTrumpsWarningAsError) {
|
||||
Annotations Main(R"cpp(
|
||||
int main() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user