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

Inconsistency with NotebookEdit.updateCellMetadata and updateNotebookMetadata #184606

Closed
Yoyokrazy opened this issue Jun 8, 2023 · 4 comments
Closed
Assignees
Labels
api-proposal author-verification-requested Issues potentially verifiable by issue author insiders-released Patch has been released in VS Code Insiders notebook-api verification-needed Verification of issue is requested verification-steps-needed Steps to verify are needed for verification verified Verification succeeded
Milestone

Comments

@Yoyokrazy
Copy link
Contributor

When updating cell metadata for a cell, users call NotebookEdit.updateCellMetadata which provides a function to alter the metadata of a cell. This uses replaceNotebookCellMetadata defined in extHostTypes.ts.

/**
* Utility to create an edit that update a cell's metadata.
*
* @param index The index of the cell to update.
* @param newCellMetadata The new metadata for the cell.
*/
static updateCellMetadata(index: number, newCellMetadata: { [key: string]: any }): NotebookEdit;

private replaceNotebookCellMetadata(uri: URI, index: number, cellMetadata: Record<string, any>, metadata?: vscode.WorkspaceEditEntryMetadata): void {
this._edits.push({ _type: FileEditType.Cell, metadata, uri, edit: { editType: CellEditType.PartialMetadata, index, metadata: cellMetadata } });
}

When replaceNotebookCellMetadata is called, the CellEditType is marked as PartialMetadata, resulting in the metadata of the cell only being updated with the passed in data, rather than fully replaced. This makes it difficult to determine how to remove fields from a cell's metadata, a change needed for fixing vscode/jupyter#13522. This can be worked around in this situation by setting the field to null.

However, if a user calls NotebookEdit.updateNotebookMetadata, it appears that the functionality is a full replacement of initial metadata. There is a slight inconsistency here between the functionality of the two functions.

Couple initial ideas:

  • better document vscode.d.ts to reflect the behavior of updateCellMetadata. Add in a line stating that this is an iterative change, only altering the fields passed into this function
    • * @param newCellMetadata The new metadata for the cell.
    • * @param newCellMetadata The **revised** metadata for the cell.
  • revise the functionality of either updateCell or updateNotebook metadata functions to align their behavior. This seems dangerous as it could likely break features leveraging this api.
  • deprecate these functions, and rewrite two new ones with clearer functionality and documentation, based on updated needs from the notebook and jupyter teams
@rebornix
Copy link
Member

rebornix commented Jun 12, 2023

Analyzed all extensions using this API and most of them are already doing the right thing: clone the existing metadata, apply the change, and then call the API to update. However there are a few extensions didn't do so:

@VSCodeTriageBot VSCodeTriageBot added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Jun 14, 2023
@rebornix rebornix added verification-needed Verification of issue is requested author-verification-requested Issues potentially verifiable by issue author and removed verification-needed Verification of issue is requested labels Jun 26, 2023
@VSCodeTriageBot
Copy link
Collaborator

This bug has been fixed in the latest release of VS Code Insiders!

@Yoyokrazy, you can help us out by commenting /verified if things are now working as expected.

If things still don't seem right, please ensure you're on version b4952d1 of Insiders (today's or later - you can use Help: About in the command palette to check), and leave a comment letting us know what isn't working as expected.

Happy Coding!

@alexr00
Copy link
Member

alexr00 commented Jun 28, 2023

@rebornix what is the best way to verify this?

@alexr00 alexr00 added the verification-steps-needed Steps to verify are needed for verification label Jun 28, 2023
@rebornix
Copy link
Member

It's a bit complex I would love either @Yoyokrazy or @amunger to help verify.

@amunger amunger added the verified Verification succeeded label Jun 28, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jul 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-proposal author-verification-requested Issues potentially verifiable by issue author insiders-released Patch has been released in VS Code Insiders notebook-api verification-needed Verification of issue is requested verification-steps-needed Steps to verify are needed for verification verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants