clang-format: Only output IncompleteFormat if -cursor is given.

This is only for editor integrations.

llvm-svn: 236867
This commit is contained in:
Daniel Jasper 2015-05-08 15:36:30 +00:00
parent ec1fc97e5d
commit e44e5665d4
2 changed files with 8 additions and 8 deletions

View File

@ -1,7 +1,7 @@
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t2.cpp // RUN: grep -Ev "// *[A-Z-]+:" %s > %t2.cpp
// RUN: clang-format -style=LLVM %t2.cpp > %t.cpp // RUN: clang-format -style=LLVM %t2.cpp > %t.cpp
// RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s // RUN: FileCheck -strict-whitespace -cursor=0 -input-file=%t.cpp %s
// CHECK: {{^\{ "IncompleteFormat": true }} // CHECK: {{"IncompleteFormat": true}}
// CHECK: {{^int\ \i;$}} // CHECK: {{^int\ \i;$}}
int i; int i;
// CHECK: {{^f \( g \(;$}} // CHECK: {{^f \( g \(;$}}

View File

@ -226,7 +226,8 @@ static bool format(StringRef FileName) {
FormatStyle FormatStyle = getStyle( FormatStyle FormatStyle = getStyle(
Style, (FileName == "-") ? AssumeFilename : FileName, FallbackStyle); Style, (FileName == "-") ? AssumeFilename : FileName, FallbackStyle);
bool IncompleteFormat = false; bool IncompleteFormat = false;
tooling::Replacements Replaces = reformat(FormatStyle, Sources, ID, Ranges, &IncompleteFormat); tooling::Replacements Replaces =
reformat(FormatStyle, Sources, ID, Ranges, &IncompleteFormat);
if (OutputXML) { if (OutputXML) {
llvm::outs() << "<?xml version='1.0'?>\n<replacements " llvm::outs() << "<?xml version='1.0'?>\n<replacements "
"xml:space='preserve' incomplete_format='" "xml:space='preserve' incomplete_format='"
@ -255,12 +256,11 @@ static bool format(StringRef FileName) {
else if (Rewrite.overwriteChangedFiles()) else if (Rewrite.overwriteChangedFiles())
return true; return true;
} else { } else {
outs() << "{";
if (Cursor.getNumOccurrences() != 0) if (Cursor.getNumOccurrences() != 0)
outs() << " \"Cursor\": " outs() << "{ \"Cursor\": "
<< tooling::shiftedCodePosition(Replaces, Cursor) << ","; << tooling::shiftedCodePosition(Replaces, Cursor)
outs() << " \"IncompleteFormat\": " << ", \"IncompleteFormat\": "
<< (IncompleteFormat ? "true" : "false") << " }\n"; << (IncompleteFormat ? "true" : "false") << " }\n";
Rewrite.getEditBuffer(ID).write(outs()); Rewrite.getEditBuffer(ID).write(outs());
} }
} }