Question

I am trying to write a visual studio MEF extension that captures the users current carret position, determines that name of the function currently selected and opens the corresponding help file.

I am able to capture the F1 event and get the corresponding IWpfTextView view that contains this information. However, I am not sure how to parse what the current word selected by the carret might be. I am able to determine the carret's current location using the position property, but that only gives me an integer. What's the best approach to determine the word currently at the carret position?

Eg. myFunction(null, MY_CONSTANT, MY_CONSTANT2); where the cursor is on myFunction.

Thank you in advance for all your help.

Was it helpful?

Solution

You can get the currently selected function with something like this:

DTE.ActiveWindow.Selection.ActivePoint.CodeElement(vsCMElement.vsCMElementFunction)

OTHER TIPS

I've been trying to do this too. After some trial and error, this seems to work:

if (DTE.ActiveWindow.Selection.IsEmpty)
{
   DTE.ActiveWindow.Selection.MoveLeft(FALSE);
   DTE.ActiveWindow.Selection.MoveRight(TRUE);
}
string curWord = DTE.ActiveWindow.Selection.Text;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top