[PATCH] Add clang-format VS extension
Nico Rieck
nico.rieck at gmail.com
Thu Aug 29 08:42:32 PDT 2013
================
Comment at: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs:150
@@ +149,3 @@
+ // The SVsTextManager is a service through which we can get the active view.
+ var textManager = Package.GetGlobalService(typeof(SVsTextManager)) as IVsTextManager;
+ IVsTextView textView;
----------------
Same here regarding "as".
================
Comment at: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs:167
@@ +166,3 @@
+ {
+ OptionPageGrid page = GetDialogPage(typeof(OptionPageGrid)) as OptionPageGrid;
+ return page.Style;
----------------
Same here.
================
Comment at: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs:94
@@ +93,3 @@
+ {
+ IVsUIShell uiShell = GetService(typeof(SVsUIShell)) as IVsUIShell;
+ Guid id = Guid.Empty;
----------------
If you're not checking the result for null, you might as well use a normal cast instead of as.
================
Comment at: tools/clang-format-vs/ClangFormat/PkgCmdID.cs:11
@@ +10,2 @@
+ };
+}
----------------
Mixed CRLF and LF here.
================
Comment at: tools/clang-format-vs/ClangFormat/Properties/AssemblyInfo.cs:17
@@ +16,3 @@
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+[assembly: ComVisible(false)]
----------------
Trailing whitespace.
================
Comment at: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs:70
@@ +69,3 @@
+ return;
+ var text = view.TextBuffer.CurrentSnapshot.GetText();
+ var start = view.Selection.Start.Position.GetContainingLine().Start.Position;
----------------
You use var here instead of string, but not for casts or new where it makes more sense.
================
Comment at: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs:122
@@ +121,3 @@
+ var style = GetStyle().Replace("\"", "\\\"");
+ process.StartInfo.Arguments = " -offset " + offset.ToString() +
+ " -length " + length.ToString() +
----------------
You can leave out the .ToString() here.
================
Comment at: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs:139
@@ +138,3 @@
+ {
+ throw new Exception(process.StandardError.ReadToEnd());
+ }
----------------
IIRC redirecting the standard streams and reading this way can become problematic if the internal buffer becomes full. It might be better to use the {Output,Error}DataReceived events to collect the output asynchronously into a StringBuffer.
================
Comment at: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs:174
@@ +173,3 @@
+ ITextDocument document;
+ if (view.TextBuffer.Properties.TryGetProperty<ITextDocument>(typeof(ITextDocument), out document))
+ {
----------------
You can leave out the <ITextDocument> here.
================
Comment at: tools/clang-format-vs/ClangFormat/PkgCmdID.cs:3
@@ +2,3 @@
+// MUST match PkgCmdID.h
+using System;
+
----------------
This using directive is unused and should be removed.
http://llvm-reviews.chandlerc.com/D1543
More information about the cfe-commits
mailing list