1

I am writing a Visual Studio extension and I want to implement the Ctrl + Click command for my own file type. This is similar to the C#/C++ editor whereby Ctrl + clicking on a type name will take user to the definition of that type (aka. Go To Definition command.)

Is there any sample on how to achieve this? I searched on Microsoft Docs website but I couldn't find anything that I want.

superkinhluan
  • 733
  • 7
  • 23
  • Forgot to say that I also want to make the text under cursor become a hyperlink when user presses Ctrl and mouse over the text. – superkinhluan Mar 24 '21 at 18:57

1 Answers1

5

Ctrl+Click Go To Definition example from VS Productivity Power Tools may get you started.

Description https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.CtrlClickGoToDefinition

Source code https://github.com/microsoft/VS-PPT/tree/master/src/GoToDef

Sergey Vlasov
  • 26,641
  • 3
  • 64
  • 66
  • Thanks. That's very helpful. I read the source code and I understand that it invokes the built-in GoToDef command to handle the actual opening of the target file. For my extension, it's not a programming language, so I can't invoke the GoToDef command. I have to open the file manually, using VsShellUtility.OpenDocument() function. Do you know how I can navigate to a particular line number within the target file? – superkinhluan Mar 25 '21 at 11:30
  • 1
    @superkinhluan EnvDTE.TextSelection ts = dte.ActiveDocument.Selection as EnvDTE.TextSelection; ts.MoveToLineAndOffset(…); – Sergey Vlasov Mar 25 '21 at 16:31