Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to add a quick-fix to a compiler error #832

Open
jiribenes opened this issue Feb 17, 2025 · 0 comments
Open

Option to add a quick-fix to a compiler error #832

jiribenes opened this issue Feb 17, 2025 · 0 comments

Comments

@jiribenes
Copy link
Contributor

jiribenes commented Feb 17, 2025

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant