From: Hans Wennborg Date: Fri, 22 Sep 2017 21:47:39 +0000 (+0000) Subject: clang-format plugin: Add missing NL (new line) at EOF (end of file) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f87b529510cd26b9835cca8602a504985b773efb;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314033 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs b/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs index d16d6d5041..efb2147f2b 100644 --- a/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs +++ b/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs @@ -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); }