문제

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.

도움이 되었습니까?

해결책

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

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

다른 팁

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top