Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the minimal working IVsTextViewCreationListener implementation?

I created a VISX project, and wrote this piece of code:

using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using System.ComponentModel.Composition;

namespace MyExtension
{
    [Export(typeof(IVsTextViewCreationListener))]
    public class Main : IVsTextViewCreationListener
    {
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
        }
    }
}

If I put a breakpoint inside the VsTextViewCreated method, Visual Studio informs me that it will never be hit. Opening files in the second instance of Visual Studio that launches in the debugger indeed does not trigger it.

What am I doing wrong?

like image 654
Ansis Māliņš Avatar asked Sep 29 '22 21:09

Ansis Māliņš


1 Answers

You need to specify ContentType and TextViewRole for your class:

[Microsoft.VisualStudio.Utilities.ContentType("text")]
[Microsoft.VisualStudio.Text.Editor.TextViewRole(Microsoft.VisualStudio.Text.Editor.PredefinedTextViewRoles.Editable)]

Also don't forget to declare a MefComponent asset in your extension manifest:

enter image description here

And make sure in .csproj:

<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
like image 181
Sergey Vlasov Avatar answered Oct 17 '22 18:10

Sergey Vlasov