summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2016-02-10 12:42:58 +0000
committerDaniel Jasper <djasper@google.com>2016-02-10 12:42:58 +0000
commit36e979af73c7e184e899fda40338927558ac1597 (patch)
tree621886ba4077fa732886f70369b20e7c30424eb1
parent5bfd4d00086e07d06e28f6a88ce1b07a3521ec3d (diff)
downloadbcm5719-llvm-36e979af73c7e184e899fda40338927558ac1597.tar.gz
bcm5719-llvm-36e979af73c7e184e899fda40338927558ac1597.zip
clang-format sort include use the source file name to determine the
"main include" that will be the 1st include (category 0). Because the clang-format visual studio extension does not pass the file name and use the standard input, sort include cannot find a "main include": Testing fix on llvm\tools\clang\lib\Format\Format.cpp: Original file: #include "clang/Format/Format.h" ... #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" Without fix, selecting the includes and running visual studio clang-format: ... #include "clang/Basic/SourceManager.h" #include "clang/Format/Format.h" #include "clang/Lex/Lexer.h" With fix, selecting the includes and running visual studio clang-format: #include "clang/Format/Format.h" ... #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" Test 2 with main header not at the start: Original file: ... #include "clang/Format/Format.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" Without fix, selecting the includes and running visual studio clang-format: ... #include "clang/Basic/SourceManager.h" #include "clang/Format/Format.h" #include "clang/Lex/Lexer.h" With fix, selecting the includes and running visual studio clang-format: #include "clang/Format/Format.h" ... #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" Patch by Jean-Philippe Dufraigne, thank you. Review: http://reviews.llvm.org/D16524 llvm-svn: 260378
-rw-r--r--clang/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs17
1 files changed, 15 insertions, 2 deletions
diff --git a/clang/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs b/clang/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
index df872b2e219..6af2fd177f0 100644
--- a/clang/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
+++ b/clang/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
@@ -202,9 +202,10 @@ namespace LLVM.ClangFormat
if (start >= text.Length && text.Length > 0)
start = text.Length - 1;
string path = GetDocumentParent(view);
+ string filePath = GetDocumentPath(view);
try
{
- var root = XElement.Parse(RunClangFormat(text, start, length, path));
+ var root = XElement.Parse(RunClangFormat(text, start, length, path, filePath));
var edit = view.TextBuffer.CreateEdit();
foreach (XElement replacement in root.Descendants("replacement"))
{
@@ -237,7 +238,7 @@ namespace LLVM.ClangFormat
///
/// Formats the text range starting at offset of the given length.
/// </summary>
- private string RunClangFormat(string text, int offset, int length, string path)
+ private string RunClangFormat(string text, int offset, int length, string path, string filePath)
{
string vsixPath = Path.GetDirectoryName(
typeof(ClangFormatPackage).Assembly.Location);
@@ -257,6 +258,8 @@ namespace LLVM.ClangFormat
if (GetSortIncludes())
process.StartInfo.Arguments += " -sort-includes ";
string assumeFilename = GetAssumeFilename();
+ if (string.IsNullOrEmpty(assumeFilename))
+ assumeFilename = filePath;
if (!string.IsNullOrEmpty(assumeFilename))
process.StartInfo.Arguments += " -assume-filename \"" + assumeFilename + "\"";
process.StartInfo.CreateNoWindow = true;
@@ -355,5 +358,15 @@ namespace LLVM.ClangFormat
}
return null;
}
+
+ private string GetDocumentPath(IWpfTextView view)
+ {
+ ITextDocument document;
+ if (view.TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out document))
+ {
+ return document.FilePath;
+ }
+ return null;
+ }
}
}
OpenPOWER on IntegriCloud