withastro / language-tools

Language tools for Astro
MIT License
240 stars 45 forks source link

💡 RFC: Add code fix to replace quotes with curly braces #867

Closed nojaf closed 1 month ago

nojaf commented 1 month ago

Background & Motivation

When typing code in the JSX-like syntax, I often need to wrap a property assignment in { }. Where autocomplete inserts " " after pressing =.

image

It would be great if we had a code action to change the empty quotes to empty curly braces.

Proposed Solution

Possible solutions

As was mentioned on Discord, this could be a code action in provideCodeActions in https://github.com/withastro/language-tools/blob/main/packages/language-server/src/plugins/astro.ts.

Alternatives considered

\/

Risks, downsides, and/or tradeoffs

I don't have enough insights to say anything about this.

Open Questions

\/

Detailed Design

Inside the code action, I would assume I can get the cursor position and then try to find the current AST node. If that node is this empty quotes of a property assignment, the code action should kick in. Or that is how I naively would approach the problem.

Does this make sense? If so, how would I get the AST nodes?

Help make it happen!