1

I am generating a custom workflow diagram via DGML API where each node corresponds to a C# class. I would like to be able to use the built-in 'Go To Definition' feature but the documentation is lacking.

Den
  • 1,659
  • 3
  • 22
  • 42

3 Answers3

1

If you know the class´s filename and the position of the symbol definition, you can use the VsShellUtilities class to open the document and scroll the code artifact into the view (by setting the caret position). In one of my extensions I do something like this...

If have a SourceInfo type which I use to store the filename and text-range...

void GotoDefinition(
    IServiceProvider serviceProvider, 
    SourceInfo source)
{
    IVsUIHierarchy hierarchy;
    uint itemId;
    IVsWindowFrame windowFrame;
    IVsTextView view;

    VsShellUtilities.OpenDocument(
        serviceProvider,
        source.Filename,
        Guid.Empty,
        out hierarchy,
        out itemId,
        out windowFrame,
        out view);

    if (view != null)
    {
        int line, column;
        int pos = source.TextRange.Start;
        if (view.GetLineAndColumn(pos, out line, out column) == VSConstants.S_OK)
        {
            view.SetCaretPos(line, column);
            view.CenterLines(line, 1);
        }
    }
}

class SourceInfo
{
    public string Filename { get; set; }

    public TextRange TextRange { get; set; }
}
Matze
  • 4,433
  • 4
  • 45
  • 59
  • That is interesting, thank you, but I was wondering if it's just a matter of setting the right node category and label to make it work without any extra code. – Den Feb 13 '15 at 15:33
  • How do generate the `DGML` graph? How is the graph connected to your code? – Matze Feb 18 '15 at 15:40
  • I am generating it manually. It's not but I was wondering if I could just follow the Code Maps conventions and get same functionality auto-magically. Unfortunately don't have more time to investigate, was wondering if someone already done that. – Den Feb 18 '15 at 17:15
1

You cannot modify goto definition, but you can use "goto reference" instead. If you manually edit the DGML file in a text editor you can add a "Reference" property to a node, like this:

<Node Id="Boomerang" Reference="Boomerang.dgml"/>

Then when you right click this node in VS you will see a new menu appear named "Go To Reference" with a submenu containing "Reference", if you click this it will open the referenced DGML file.

See https://msdn.microsoft.com/en-us/library/ee842619.aspx#AddReferences for more detail.

Chris
  • 532
  • 3
  • 8
  • I am pretty sure it is possible to modify the goto definition. It's just not documented well. Thank you for workaround though. – Den May 03 '16 at 08:26
0

Visual studio have it's own property "SourceLocation"

You should declare it in properties

<Properties>
...
<Property Id="SourceLocation" Label="Start Line Number" DataType="Microsoft.VisualStudio.GraphModel.CodeSchema.SourceLocation" />
...
</Properties>

then use it inside Node element f.e.

<Node Id="class1" Label="FirstClass" SourceLocation="(Assembly=file:///D:/Prj/TestApp/AppConsole/Program.cs StartLineNumber=8 StartCharacterOffset=1 EndLineNumber=8 EndCharacterOffset=1)"/>
Igor
  • 174
  • 9