2

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.

asked Mar 24, 2021 at 18:56
1
  • 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. Commented Mar 24, 2021 at 18:57

1 Answer 1

6

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

answered Mar 25, 2021 at 5:23
Sign up to request clarification or add additional context in comments.

2 Comments

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 EnvDTE.TextSelection ts = dte.ActiveDocument.Selection as EnvDTE.TextSelection; ts.MoveToLineAndOffset(...);

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.