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

Add CodeActionProvider#resolveCodeAction to plugin API #10730

Merged
merged 1 commit into from
Feb 16, 2022

Conversation

lucas-koehler
Copy link
Contributor

What it does

Fixes #9992 by extending the plugin API and implementing the corresponding code action resolvement.

Plugin-API:

  • Add resolveCodeAction method to CodeActionProvider in theia.d.ts

RPC-API:

  • Add $resolveCodeAction and $releaseCodeActions methods to LanguagesExt
  • Extend CodeAction DTO to contain its cache id

Ext:

  • Implement methods in LanguageExtImpl delegating to CodeActionAdapter
  • Extend CodeActionAdapter
    • Cache provided code actions with an id
    • Handle resolving of code actions given
    • Handle disposing obsolete code actions

Main:

  • Extend LanguagesMainImpl
    • Hand resolveCodeAction callback into quick fix providers registered with monaco
    • Dispose cached code actions on Ext side when monaco no longer needs them

Contributed on behalf of STMicroelectronics
Signed-off-by: Lucas Koehler lkoehler@eclipsesource.com

How to test

  • I adapted the VSCode sample code action extension to use code action resolvement. It will also log when an action is resolved. If resolvement wasn't working, the code actions (replacing :) with emojis) would fail. One of the provided actions (Learn more...) is a command to verify that these do not cause errors. The code actions are provided in .md files.
  • The extension can be downloaded here: code-actions-sample-0.0.2.vsix
  • Extension source code: code-actions-sample
  • Add the extension to your theia instance
  • Create a file example.md and add :) to it. the sample code actions trigger if your curser is right before a :)
  • Use one or more of the convert actions
  • Use the learn more action

image

Review checklist

Reminder for reviewers

@lucas-koehler lucas-koehler force-pushed the 9992-resolveCodeAction branch 3 times, most recently from c415e07 to 8f3d44e Compare February 11, 2022 08:57
@JonasHelming JonasHelming added the vscode issues related to VSCode compatibility label Feb 15, 2022
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

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

The changes are looking good for me! I have found a minor issue which could in theory result in unexpected behavior during execution, but I wasn't able to exploit it, so I'll approve this already. Please address the comment below and I'll merge this 👍

  • The example extension can be executed correctly
  • Normal code actions continue to work as expected

packages/plugin-ext/src/main/browser/languages-main.ts Outdated Show resolved Hide resolved
Fixes eclipse-theia#9992 by extending the plugin API and implementing the corresponding code action resolvement.

Plugin-API:
* Add resolveCodeAction method to CodeActionProvider in  theia.d.ts

RPC-API:
* Add $resolveCodeAction and $releaseCodeActions methods to LanguagesExt
* Extend CodeAction DTO to contain its cache id

Ext:
* Implement methods in LanguageExtImpl delegating to CodeActionAdapter
* Extend CodeActionAdapter
  * Cache provided code actions with an id
  * Handle resolving of code actions given
  * Handle disposing obsolete code actions

Main:
* Extend LanguagesMainImpl
  * Hand resolveCodeAction callback into quick fix providers registered with monaco
  * Dispose cached code actions on Ext side when monaco no longer needs them

Contributed on behalf of STMicroelectronics

Signed-off-by: Lucas Koehler <lkoehler@eclipsesource.com>
@lucas-koehler
Copy link
Contributor Author

@msujew Thanks for the review and test. I fixed the if(cacheId) as it can indeed be 0. Good catch! :)

@msujew msujew merged commit f7dda08 into eclipse-theia:master Feb 16, 2022
thegecko pushed a commit to ARMmbed/theia that referenced this pull request Feb 17, 2022
…#10730)

Fixes eclipse-theia#9992 by extending the plugin API and implementing the corresponding code action resolvement
@JonasHelming JonasHelming added this to the 1.23.0 milestone Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add CodeActionProvider#resolveCodeAction
3 participants