Accessing highlighted text and checking if it is a method

Hi,I'm just about getting started on developing a plugin, and here is the task at hand:- the user highlights a portion of code (by clicking and dragging)- how do I check if this highlighted code either constitutes a single method, or is strictly contained within the body of a single method?Since this is going to be part of an Action, it should come in the Update() method which has an IDataContext parameter, right?
2 comments
Comment actions Permalink
If I'm working on a context action, will I receive both an ICSharpContextActionDataProvider and an IDataContext instance? How do I link the two to do what I would like?
0
Comment actions Permalink

Your context action will receive an ICSharpContextActionDataProvider in the constructor. You don't get an IDataContext. You should be able to get all the information you need from ICSharpContextActionDataProvider, and the interfaces it inherits from.

Context actions are different to Actions, in that an Action represents a menu item, toolbar button or other command, and a Context Action represents a command that occurs when the text caret is at a certain position in the editor.

Given the ICSharpContextActionDataProvider, you can use provider.GetSelectedElement to get the tree element under the text caret. If you want to check if it's inside a method, walk up the tree node's Parent property until you get to an IMethod or IMethodDeclaration.

0

Please sign in to leave a comment.