0

Im writing a policy plugin for VS which checks several issues with the code. If an issue occurs it will be displayed in the policy warnings tab. Now I want to jump to the line where the issue occurs in the editor when I double click it in the policy warning tab. How can I do that?

namespace PolicyPlugin
{
    [Serializable]
    public class MyPolicyPlugin : PolicyBase
    {
        //...

        //called if the user clicks on a policy warning
        public override void Activate(PolicyFailure failure)
        {
            // make jump to line x
        }
    }
}

Thanks!

1 Answers1

1

You could try to get DTE automation object first:

EnvDTE.DTE dte = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE));

or use alternative ways to get it.

An then execute standard command (that's what happens when you press CTRL+G in Visual Studio)

DTE.ExecuteCommand("Edit.Goto", "1234")

Note: I'm not sure about exact ExecuteCommand method signature. Also you can manipulate IDE the same way for other commands.

Pradeep
  • 3,258
  • 1
  • 23
  • 36
Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121
  • 1
    There are also commands for opening a file, which is the precondition for jumping to a line: ````Edit.OpenFile```` and ````File.OpenFile````. Make sure to wrap the file path in double quotes to escape whitespace: ````dte.ExecuteCommand("Edit.OpenFile", $"\"{filePath}\"");```` – Niklas Peter Sep 11 '18 at 10:38