effekt-lang / effekt-lang/effekt
Option to add a quick-fix to a compiler error
- Dominant language
- Scala
- Stars
- 469
- Forks
- 41
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 23
Description
Relevant for #472 and other LSP-related quality of life improvements.
This is potentially a pretty difficult issue, I think it's worth it though...
It would be lovely to be able to attach a quick-fix / code action (resolvable by the user in the editor) to an error emitted in the compiler.
Currently our error messages don't allow attaching code actions to them, some slight architectural workarounds might be needed in Kiama (see below).
Moreover, it should be _relatively easy to add a new quick-fix_ to both an existing and a new error message in order to make doing the right thing easy :)
As an example of how attaching a quick-fix to an error looks like, take a look at Scala 3:
https://github.com/scala/scala3/blob/e0c030ccd44089e70629b59d76962c1dfc8dbb16/compiler/src/dotty/tools/dotc/reporting/messages.scala#L871-L891
I'd personally prefer something slightly subtler for now, such as `C.error("Expected 'new' before an object instance") { TextAction(pos, pos, "new ") }`. I also think it's fine to hardcode it for a single possible quick-fix/code action for now.
### Where to start
We need to pair a Kiama `Message` (a LSP `Diagnostic`) with a corresponding Kiama `TreeAction` (a LSP `CodeAction`).
As far as I can tell, we would need to dynamically register `CodeActions` based on the `Diagnostics` we currently have / sent to the user.
I think this also means we'd need to store some Message ID -> CodeAction pairing somewhere? (Since the user can tell us relatively late that they want a code action for a message we no longer have?) Something like the `Notebook` storage here: https://github.com/effekt-lang/kiama/pull/3/files#diff-7539cc29669c287a1796c04d6a185e48593a9d59fe587322995b6f3f82a79671R183-R185. Note that this needs to be performant and it should know when to empty such a map...
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.