-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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 Notebook formatting via Code Actions #212381
Comments
Also cc'ing the other folks that have worked on Notebook support in Ruff: @snowsignal @dhruvmanila |
@Yoyokrazy Can you clarify where we use fully qualified For
Would VS Code provide the completion similar to For the
|
@Yoyokrazy One thing to verify is what gets added as |
Updates after initial support has been implemented:Note -- This information isn't necessarily specific to notebook format code actions. This information covers code actions as a whole, including our more niche notebook format situation.
As always, feel free to leave any and all questions! |
related: #161284 the end goal would be that extension authors contribute a specific private createCodeActionsOnSave(settingItems: readonly string[]): HierarchicalKind[] {
const kinds = settingItems.map(x => new HierarchicalKind(x));
// Remove subsets
return kinds.filter(kind => {
return kinds.every(otherKind => otherKind.equals(kind) || !otherKind.contains(kind));
});
} if users have both |
Another example:
|
Also related to: #174295 This does not solve the corrupted code issue from running multiple providers against the same document, and getting edits from both. However, this information does outline the more precise way for providers to register their provided Kinds, allowing users more granular control over the execution of code actions. On another note, referring to the following:
There is currently no way for a user to disable a specific code action, if they request a broader scope in
This is the user trying to opt-out of a specific action running under the "organize imports" group. This is not a functionality that is supported. In this case the user should remove their broader kind, and simply opt-in to the the providers that they specifically want. |
Ruff has Just dropping my 2cents here: Non-breaking proposal:{
# only ruff organizes imports
"notebook.codeActionsOnSave": {
"source.organizeImports.ruff": "always"
}
# all except ruff organizes imports
"notebook.codeActionsOnSave": {
"source.organizeImports.ruff": "never",
"source.organizeImports": "always"
}
# a `codeActionKind` called `sourceFormat` which will deprecate `formatOnSave` and `defaultFormatter` settings.
"notebook.codeActionsOnSave": {
"source.format": "always"
}
} Breaking proposal:{
"notebook.codeActionsOnSave": {
"source.format.ruff": "explicit",
"source.organizeImports.ruff": "always",
"source.organizeImports.isort": "always",
"source.fixAll.ruff": "explicit",
}
} Pure code actions NOT allowed. (e.g. |
@T-256 thanks for the input! A lot of the points you brought up have made their way through discussions on the team as we've planned this out, and I agree with a lot of the logic behind them. Unfortunately, there's been a lot of work done throughout the years and enough users (+ our product) rely on the current behavior of code action kinds that we can't adopt some of the behaviors that you brought up. Specifically the thoughts you outlined with the following code block:
We're going to be trying to write enough documentation that extension authors provide the correct code action kinds to begin with. The thinking being that introducing this structure as a layer on top of the existing code action logic will prevent us from breaking any existing workflows, while giving people like ruff the rich support to develop better notebook formatting support. |
Also wanted to check with @snowsignal @dhruvmanila to see if there is any plan or timeline for using vscode api + the new notebook format code action kind with ruff. Feel free to reach out if there's anything I can do to help out 👍 |
@Yoyokrazy We don't have a timeline for that yet, but we'll keep you updated! |
Reading through this thread as an end user. The This does not seem to work: // NOTEBOOKS
"notebook.formatOnSave.enabled": true,
"notebook.codeActionsOnSave": {
"source.organizeImports": "explicit"
}, |
Overview
Opening this issue up as a discussion point for the current work around notebook formatting. As a way to accomplish this without the introduction of new API, the thought is to introduce a new Code Action Kind
notebook.format.extensionID
. Looping in some relevant notebook formatting people.cc: @rebornix @karthiknadig @charliermarsh
Proposed Plan
notebook.format.xyz
xyz
is unique to your extension, but this is not a restrictionDocumentFilter
that containsnotebookType
"notebook.defaultFormatter": "extensionID"
(mirrors the editor setting)notebook.format.xyz
providers, only the first will be used.notebook.format
Code Action is applied on save, the standardprovideDocumentFormatting
flow will be skippednotebook.format
Code Action can be applied in the following ways:"notebook.formatOnSave.enabled": true
(this means that there will only be explicit triggering of this for saves, due toformatOnSave
requiring the file to NOT be saved after a delay)Format Notebook
Rough Example
settings.json
:Other relevant notes
notebook.
will only ever be called against the 0th cell of the notebook. Additionally, the providedTextDocument
will always correspond to the 0th cell in the notebook and contain auri
that can retrieve the notebook. It is the responsibility of the provider to extract theNotebookDocument
from this (an example will be provided in a sample extension, coming 🔜).notebook.codeActionsOnSave
without thenotebook.
prefix, the codeaction will be applied to every valid cell asynchronously, in parallel.NotebookEdit.replaceCells()
is less performant than simply usingTextEdit.replace()
against that document. Additionally, usingNotebookEdit.replaceCells()
will fully replace cells, including output. When possible, useTextEdits
for editing just the content of a cell.Questions
The text was updated successfully, but these errors were encountered: