Index: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs =================================================================== --- tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs +++ tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs @@ -32,13 +32,16 @@ [CLSCompliant(false), ComVisible(true)] public class OptionPageGrid : DialogPage { - private string style = "File"; + private string assumeFilename = ""; + private string fallbackStyle = "LLVM"; + private bool sortIncludes = false; + private string style = "file"; [Category("LLVM/Clang")] [DisplayName("Style")] [Description("Coding style, currently supports:\n" + - " - Predefined styles ('LLVM', 'Google', 'Chromium', 'Mozilla').\n" + - " - 'File' to search for a YAML .clang-format or _clang-format\n" + + " - Predefined styles ('LLVM', 'Google', 'Chromium', 'Mozilla', 'WebKit').\n" + + " - 'file' to search for a YAML .clang-format or _clang-format\n" + " configuration file.\n" + " - A YAML configuration snippet.\n\n" + "'File':\n" + @@ -53,6 +56,38 @@ get { return style; } set { style = value; } } + + [Category("LLVM/Clang")] + [DisplayName("Assume Filename")] + [Description("When reading from stdin, clang-format assumes this " + + "filename to look for a style config file (with 'file' style) " + + "and to determine the language.")] + public string AssumeFilename + { + get { return assumeFilename; } + set { assumeFilename = value; } + } + + [Category("LLVM/Clang")] + [DisplayName("Fallback Style")] + [Description("The name of the predefined style used as a fallback in case clang-format " + + "is invoked with 'file' style, but can not find the configuration file.\n" + + "Use 'none' fallback style to skip formatting.")] + public string FallbackStyle + { + get { return fallbackStyle; } + set { fallbackStyle = value; } + } + + [Category("LLVM/Clang")] + [DisplayName("Sort includes")] + [Description("Sort touched include lines.\n\n" + + "See also: http://clang.llvm.org/docs/ClangFormat.html.")] + public bool SortIncludes + { + get { return sortIncludes; } + set { sortIncludes = value; } + } } [PackageRegistration(UseManagedResourcesOnly = true)] @@ -138,10 +173,17 @@ // Poor man's escaping - this will not work when quotes are already escaped // in the input (but we don't need more). string style = GetStyle().Replace("\"", "\\\""); + string fallbackStyle = GetFallbackStyle().Replace("\"", "\\\""); process.StartInfo.Arguments = " -offset " + offset + " -length " + length + " -output-replacements-xml " + - " -style \"" + style + "\""; + " -style \"" + style + "\"" + + " -fallback-style \"" + fallbackStyle + "\""; + if (GetSortIncludes()) + process.StartInfo.Arguments += " -sort-includes "; + string assumeFilename = GetAssumeFilename(); + if (!string.IsNullOrEmpty(assumeFilename)) + process.StartInfo.Arguments += " -assume-filename \"" + assumeFilename + "\""; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; @@ -211,6 +253,24 @@ return page.Style; } + private string GetAssumeFilename() + { + var page = (OptionPageGrid)GetDialogPage(typeof(OptionPageGrid)); + return page.AssumeFilename; + } + + private string GetFallbackStyle() + { + var page = (OptionPageGrid)GetDialogPage(typeof(OptionPageGrid)); + return page.FallbackStyle; + } + + private bool GetSortIncludes() + { + var page = (OptionPageGrid)GetDialogPage(typeof(OptionPageGrid)); + return page.SortIncludes; + } + private string GetDocumentParent(IWpfTextView view) { ITextDocument document; Index: tools/clang-format-vs/ClangFormat/Properties/AssemblyInfo.cs =================================================================== --- tools/clang-format-vs/ClangFormat/Properties/AssemblyInfo.cs +++ tools/clang-format-vs/ClangFormat/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] Index: tools/clang-format/ClangFormat.cpp =================================================================== --- tools/clang-format/ClangFormat.cpp +++ tools/clang-format/ClangFormat.cpp @@ -201,7 +201,7 @@ static void outputReplacementXML(StringRef Text) { size_t From = 0; size_t Index; - while ((Index = Text.find_first_of("\n\r", From)) != StringRef::npos) { + while ((Index = Text.find_first_of("\n\r<&", From)) != StringRef::npos) { llvm::outs() << Text.substr(From, Index - From); switch (Text[Index]) { case '\n': @@ -210,6 +210,12 @@ case '\r': llvm::outs() << " "; break; + case '<': + llvm::outs() << "<"; + break; + case '&': + llvm::outs() << "&"; + break; default: llvm_unreachable("Unexpected character encountered!"); }