r314033 - clang-format plugin: Add missing NL (new line) at EOF (end of file)

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 22 14:47:39 PDT 2017


Author: hans
Date: Fri Sep 22 14:47:39 2017
New Revision: 314033

URL: http://llvm.org/viewvc/llvm-project?rev=314033&view=rev
Log:
clang-format plugin: Add missing NL (new line) at EOF (end of file)

clang-format.exe removes trailing new lines at end of file.

However, if no NL is found at EOF one should be added.

Patch by Teodor MICU!

Differential Revision: https://reviews.llvm.org/D37732

Modified:
    cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs

Modified: cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs?rev=314033&r1=314032&r2=314033&view=diff
==============================================================================
--- cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs (original)
+++ cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs Fri Sep 22 14:47:39 2017
@@ -326,7 +326,13 @@ namespace LLVM.ClangFormat
 
             string filePath = Vsix.GetDocumentPath(view);
             var path = Path.GetDirectoryName(filePath);
+
             string text = view.TextBuffer.CurrentSnapshot.GetText();
+            if (!text.EndsWith(Environment.NewLine))
+            {
+                view.TextBuffer.Insert(view.TextBuffer.CurrentSnapshot.Length, Environment.NewLine);
+                text += Environment.NewLine;
+            }
 
             RunClangFormatAndApplyReplacements(text, 0, text.Length, path, filePath, options, view);
         }




More information about the cfe-commits mailing list