[PATCH] D12407: [clang-format-vs] Add an option to reformat source code when file is saved to disk

Kim Gräsman via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 7 01:17:34 PST 2015


kimgr added a subscriber: kimgr.
kimgr added a comment.

Add debugging ideas.


================
Comment at: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs:86
@@ -69,1 +85,3 @@
 
+            IComponentModel componentModel = GetService(typeof(SComponentModel)) as IComponentModel;
+            editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
----------------
aaron.ballman wrote:
> hans wrote:
> > aaron.ballman wrote:
> > > berenm wrote:
> > > > I did more tests on my side, and apparently this line does not work on VS2012, componentModel is null. I don't know at all why and how to fix it, and it works fine starting with VS2013.
> > > Our minimum supported MSVC version for development is 2013. Do we document supported versions for clang-format? Do we want to support versions older than the development version we're on?
> > The manifest claims support for 2010 and later. I usually test with 2012 when I build the weekly snapshot.
> > 
> > Our clang-cl VS integration also tries to support 2010 and later, so I think it would be nice if the clang-format plugin does too.
> Thank you for the information! That sounds good to me. Then I think berenm's issue should be resolved if possible.
I haven't had time to dig into this too much, but here's an idea:

You're only getting the IComponentModel to get the IVsEditorAdaptersFactoryService, which in turn is only used to get at the document's text buffer in OnBeforeSave.

It seems to me there *should* be a more straightforward way to do that without involving COM interop. Unfortunately, I don't know what it is :-)

Google around, and this article describes something similar:
http://schmalls.com/2015/01/19/adventures-in-visual-studio-extension-development-part-2

I don't know if maybe you have the wrong RunningDocumentTable service, it seems very COM-styled, compared to the one used in the article.


http://reviews.llvm.org/D12407





More information about the cfe-commits mailing list