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

Explore support for notebook.codeActionsOnSave #179213

Closed
Yoyokrazy opened this issue Apr 4, 2023 · 5 comments
Closed

Explore support for notebook.codeActionsOnSave #179213

Yoyokrazy opened this issue Apr 4, 2023 · 5 comments
Assignees
Labels
feature-request Request for new features or functionality notebook-commands on-testplan
Milestone

Comments

@Yoyokrazy
Copy link
Contributor

Yoyokrazy commented Apr 4, 2023

  • list of user adjustable actions that happen just before save
  • integrate alongside formatOnSave
  • features:
    • notebook specific features
      • move all imports to top
      • delete empty cells
    • language server has things?
    • linting?
@Yoyokrazy Yoyokrazy added notebook-commands feature-request Request for new features or functionality labels Apr 4, 2023
@Yoyokrazy Yoyokrazy self-assigned this Apr 4, 2023
@Yoyokrazy Yoyokrazy transferred this issue from microsoft/vscode-jupyter Apr 4, 2023
@Yoyokrazy
Copy link
Contributor Author

merge all code with %pip install ... to a new top cell?

@jrieken
Copy link
Member

jrieken commented May 4, 2023

  • rule: source action can only modify its file (text document or notebook) @Yoyokrazy
  • code action kind for notebooks: source.notebook.xyz or notebook.source.xyz or notebook.xyz @Yoyokrazy
  • register code action provider for notebookType @Yoyokrazy
  • notebook on save: (1) call notebook-provider with first cell (2) call code providers for documents @Yoyokrazy

@Yoyokrazy
Copy link
Contributor Author

#182799 adds support for standard CodeAction providers to supply actions for notebook cells, also ensures that edits only apply to the given cell via a check between the TextEdit's resource and the model URI. Existing providers and extensions may need a document selector/filter capable of selecting notebook cells.

notebook on save: (1) call notebook-provider with first cell (2) call code providers for documents

Part (2) of this statement is now completed. This CodeAction sorting will need to be revised to prioritize the Notebook CodeAction type, rather than source.fixAll. Current thinking is that this should take priority over the parallel cell actions, as Notebook types will likely restructure the contents of multiple cells.

code action kind for notebooks: source.notebook.xyz or notebook.source.xyz or notebook.xyz

Current thought is to adopt notebook.xyz for actions affecting the entire notebook. Actively working on an extension to experiment with functionality

@Yoyokrazy
Copy link
Contributor Author

#183457 adds in the proper notebook kind into the SaveParticipants for notebooks. Currently upon save, CodeActions are applied as follows:

  • Actions are gathered from settings and split into cell CodeActions and notebook CodeActions
    • the prior group contains everything not starting with notebook.xyz. The latter contains ONLY actions starting with notebook.xyz
  • Notebook level codeactions are applied sequentially, calling providers against only the first cell in the notebook. It is the responsibility of the provider to iterate over the notebook and apply edits in a performant manner, and construct NotebookEdits that alter the desired cells.
    • note: if you are linking your provider to a selector that only runs against code cells, this will likely break functionality, as markdown cells are often the leading cell in notebooks. This behavior will be explored during next debt week.
  • Cell level codeactions are applied to each cell in parallel. this includes all source.fixAll, quickfix, and other existing CodeAction kinds.
    • note: the edits returned by these providers are restricted to only touching the passed in resource (the cell's TextDocument) when in the context of saving notebooks. outside of this, the restriction is not applied.

An example extension with a basic notebook CodeAction provider can be found here. This is still a personal wip, and currently only adds imports to a new top cell, rather than also removing them from throughout the notebook. The SaveParticipant handling CodeActions on save can be found here.

@Yoyokrazy
Copy link
Contributor Author

Notebook CodeActions are now in a good state of useability, and are no longer invasive in every lightbulb of every code cell in a notebook. Fixed by the above PR. They can only be leveraged via the notebook.codeActionsOnSave setting rather than a lightbulb in the cell.

Todo:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality notebook-commands on-testplan
Projects
None yet
Development

No branches or pull requests

5 participants