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 setKernelSpecAndLanguageInfo to ipynb ext #132298

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions extensions/ipynb/src/ipynbMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ export function activate(context: vscode.ExtensionContext) {
});
return vscode.workspace.applyEdit(edit);
},
setKernelSpecAndLanguageInfo: async (resource: vscode.Uri, kernelspec: unknown, language_info: unknown): Promise<boolean> => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can languageInfo be an optional argument to setKernelSpec instead of its own function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I'm not entirely sure, though, whether the way I'm construction the custom dictionary now will work... In particular, just not entirely sure whether ...(language_info ? { language_info: language_info } : {}) does what I think it does.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mjbvz @davidanthoff Why not change the method name completely and pass the entire metadata?
I.e. as follows:

setNotebookMetaata(resoruce: vscode.Uri, metadata: Partial<nbformat.INotbeookMetadata>): Promise<boolean> {
...
}

After all, the requirement is to provide an API to set the metadata. and if we end up with more items in the notebook metadata the new method will be future proof.
Today there are at least 3 properties in the metadata (kernelSpec, language_info and orig_nbformat).
I propose changing the method to providing a partial of the metadata.
This will also allow others to add custom metadata into the notebook (after all the ipynb spec allows for that).

    /**
     * The default metadata for the notebook.
     */
    interface INotebookMetadata extends JSONObject {
        kernelspec?: IKernelspecMetadata;
        language_info?: ILanguageInfoMetadata;
        orig_nbformat: number;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that sounds like a good idea to me. Although the most important objective from our end is to get something into 1.60.1, I think :) @DonJayamanne do you want to take over this PR? You're probably in the best position to do the right thing here.

const document = vscode.workspace.notebookDocuments.find(doc => doc.uri.toString() === resource.toString());
if (!document) {
return false;
}

const edit = new vscode.WorkspaceEdit();
edit.replaceNotebookMetadata(resource, {
...document.metadata,
custom: {
...(document.metadata.custom ?? {}),
metadata: {
...(document.metadata.custom?.metadata ?? {}),
kernelspec: kernelspec,
language_info: language_info
},
}
});
return vscode.workspace.applyEdit(edit);
},
};
}

Expand Down