codeparser icon indicating copy to clipboard operation
codeparser copied to clipboard

Populate CodeAction if its parent should also be modified.

Open kenkangxgwe opened this issue 3 years ago • 1 comments

Currently, ApplyCodeAction deletes the very node that the CodeAction specifies, but this is not sound enough. Given

Module[{a, b = 2 (* b is unused *)}, a]

The symbol b is marked, but in fact, we want to remove b = 2. So I think a code action can be populated up until it reaches the node that can actually fix the problem. Moreover, the trailing comment seems easy to be removed if we treat it as the same as the trailing comma, but it will still be convenient to provide an additional list of nodes that can be removed as well.

I know that CodeParser`CodeAction` is not ready yet, so I am just sharing the idea.

kenkangxgwe avatar Mar 22 '21 05:03 kenkangxgwe

It would be good to handle stray commas in cases like this.

I don't know about handling comments. People may want to keep them.

A related problem that I am running into in some cases related to CodeActions is the mixing of abstract vs. concrete syntax.

For example, I have a rule to catch code like this: a_ -> a and I want to give the suggestion of changing the -> to :>

The problem is that the rule is working on abstract syntax where there is no longer the concept of -> or :> operators.

Currently, to give the suggestion, I would have to have a CodeAction to replace the entire a_ -> a node.

But all I really want to replace is the single -> operator.

So I am trying to think about this.

bostick avatar Mar 22 '21 13:03 bostick