langium
langium copied to clipboard
Code Action: Adds Missing 'return' to Parser Rule
Closes one of the points of #442.
Adds return T to rule for general error
The type 'T' is already explicitly declared and cannot be inferred.
From https://github.com/langium/langium/issues/449.
There are a few cases that get mixed up in here which need a little more work to be separated cleanly. Missing returns & invalid returns are coupled together a bit, and invalid returns is in-turn coupled along with code that handles invalid infers. Plan is to come back to this at the start of Oct at the top of my list 📚 , and to clean this up a bit.
Not exactly on time, completely past October actually 😆 . But did come back to work on this again, as it wasn't too much to change. Seems good now, and ready to check again.
Alright, reworked this and it's now down to:
- code action to add missing 'returns'
- code action to correct invalid 'infers' (added due to some proximity)
- same tests as before
Shaves down some of the changes for InvalidInfers
by passing along the range of the appropriate CST node.
Missing returns case
Invalid infers case
The highlighting for invalid infers is only on the return type currently, let me know if that's a blocker.
@montymxb Looks really nice! Is the same for Actions already planned.
@dhuebner thanks! The original plan was to take care of the cases for parser rules, but it would be ideal to set that up for actions too. I believe once we have the code actions we want for parser rules, the same approach can be adapted to actions as well.