Making an Action "Available" when cursor

I want to create a pulgin that activates when the cursor if in the parenthesis of a classes constructor when instanciating an object

Example: If the cursor is in the BLUE selection in this code the action would be available:

 
public class Person
    {
        public Person(string firstName, string lastName)
        {
            FirstName = firstName;
            LastName = lastName;
        }
 
        public string FirstName { get; set; }
 
        public string LastName { get; set; }
 
        public void Speak(string message)
        {
        }
    }

 
var person = new Person("Bob", "Young");
 
person.Speak("test");
 
How can I know the cursor is in the blue area?
 
What do I want to get to get just this "new" statement? (I have tried)
 

 
var constructorDeclaration = _provider.GetSelectedElement<IConstructorDeclaration>();
var methodDeclaration = _provider.GetSelectedElement<IMethodDeclaration>();
var anonymousMethodParameterDeclaration = _provider.GetSelectedElement<IAnonymousMethodParameterDeclaration>();
var arglistParameterDeclaration = _provider.GetSelectedElement<IArglistParameterDeclaration>();
var cSharpParameterDeclaration = _provider.GetSelectedElement<ICSharpParameterDeclaration>();
var cSharpParametersOwnerDeclaration = _provider.GetSelectedElement<ICSharpParametersOwnerDeclaration>();
var formalParameterList = _provider.GetSelectedElement<IFormalParameterList>();
var parenthesizedExpression = _provider.GetSelectedElement<IParenthesizedExpression>();
var primaryConstructorDeclaration = _provider.GetSelectedElement<IPrimaryConstructorDeclaration>();
var regularParameterDeclaration = _provider.GetSelectedElement<IRegularParameterDeclaration>();
var typeParameterOfMethodDeclaration = _provider.GetSelectedElement<ITypeParameterOfMethodDeclaration>();


My action:

 
public class ContructorParametersAction : ContextActionBase
{
     ...
}


Am I approaching this wrong?

2 comments

That's the right approach - although I'm not sure what you mean with the multiple calls to provider.GetSelectedElement.

0

The multiple provider.GetSelectedElement are the things I have tried to get the just the section of code where the blue text is. Also can you help me with detecting this. I've spend days and am stuck.

 
var person = new Person("Bob", "Young");
 
person.Speak("test");
How can I know the cursor is in the blue area?
 
What do I want to get to get just this "new" statement? (I have tried)
0

Please sign in to leave a comment.