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

PoC: emit code actions from the compiler that the editor tooling can use #7040

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

zth
Copy link
Collaborator

@zth zth commented Sep 16, 2024

Very messy PoC, but this is intended to show that we could fairly easily add a specific mode to bsc that the editor tooling and/or build system can enable to get the compiler to emit code action data.

The main advantage here is that we can co-locate the code that produces code actions with the actual type checker and what produces the error messages. Currently, we parse the error log to extract these things. This would make it more robust and easier to maintain, and automatically tied to the current ReScript version.

Example:
image

To start we could port all actions in https://github.com/rescript-lang/rescript-vscode/blob/fd911045515edd1c82e981e407281ee9f311a8ed/server/src/codeActions.ts and then add more as needed.

Comment on lines +276 to +278
"-code-action-data", unit_call(fun _ -> Js_config.code_action_data := true),
"*internal* Emit code action data";

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't actually used yet, but we can probably have a bsc config like this.

match !code_action_data with
| [] -> ()
| code_actions ->
Format.fprintf ppf "@\n=== CODE ACTIONS ===@\n";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build system and editor tooling can extract this line + the rest of the content whenever it encounters it, and extract the code actions from there. And show the actual error in the terminal and in the editor without this text.

@zth
Copy link
Collaborator Author

zth commented Sep 17, 2024

Maybe this should incorporate #6203 at the same time. This type of functionality opens up for a JSON format anyway.

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

Successfully merging this pull request may close these issues.

1 participant