Domanda

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.

È stato utile?

Soluzione

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

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

Altri suggerimenti

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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top