]> granicus.if.org Git - clang/commitdiff
clang-format: Only output IncompleteFormat if -cursor is given.
authorDaniel Jasper <djasper@google.com>
Fri, 8 May 2015 15:36:30 +0000 (15:36 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 8 May 2015 15:36:30 +0000 (15:36 +0000)
This is only for editor integrations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236867 91177308-0d34-0410-b5e6-96231b3b80d8

test/Format/incomplete.cpp
tools/clang-format/ClangFormat.cpp

index ade38b66a393c2a89c53cabf422771ace3faf9df..b66d5f816ea875c61c8236d7efafac353c29450a 100644 (file)
@@ -1,7 +1,7 @@
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t2.cpp
 // RUN: clang-format -style=LLVM %t2.cpp > %t.cpp
-// RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s
-// CHECK: {{^\{ "IncompleteFormat": true }}
+// RUN: FileCheck -strict-whitespace -cursor=0 -input-file=%t.cpp %s
+// CHECK: {{"IncompleteFormat": true}}
 // CHECK: {{^int\ \i;$}}
  int    i;
 // CHECK: {{^f  \( g  \(;$}}
index ae2180c8370d72141079aa6a7c0322204ee4e32c..5037e901f3b41c42c59d181d7db866d3e8bfba77 100644 (file)
@@ -226,7 +226,8 @@ static bool format(StringRef FileName) {
   FormatStyle FormatStyle = getStyle(
       Style, (FileName == "-") ? AssumeFilename : FileName, FallbackStyle);
   bool IncompleteFormat = false;
-  tooling::Replacements Replaces = reformat(FormatStyle, Sources, ID, Ranges, &IncompleteFormat);
+  tooling::Replacements Replaces =
+      reformat(FormatStyle, Sources, ID, Ranges, &IncompleteFormat);
   if (OutputXML) {
     llvm::outs() << "<?xml version='1.0'?>\n<replacements "
                     "xml:space='preserve' incomplete_format='"
@@ -255,12 +256,11 @@ static bool format(StringRef FileName) {
       else if (Rewrite.overwriteChangedFiles())
         return true;
     } else {
-      outs() << "{";
       if (Cursor.getNumOccurrences() != 0)
-        outs() << " \"Cursor\": "
-               << tooling::shiftedCodePosition(Replaces, Cursor) << ",";
-      outs() << " \"IncompleteFormat\": "
-             << (IncompleteFormat ? "true" : "false") << " }\n";
+        outs() << "{ \"Cursor\": "
+               << tooling::shiftedCodePosition(Replaces, Cursor)
+               << ", \"IncompleteFormat\": "
+               << (IncompleteFormat ? "true" : "false") << " }\n";
       Rewrite.getEditBuffer(ID).write(outs());
     }
   }