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

Conversation

davidanthoff
Copy link
Contributor

Following @mjbvz' suggestion over at https://github.com/julia-vscode/julia-vscode/pull/2424/files#r702128257.

I'm not setup to build VS Code, so this is a "blind" PR that I haven't tested.

I added a new API function here, under the assumption that the one that just shipped needs to stay stable as it is part of the public API now.

Copy link
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

Thanks! Looks like the right overall direction but I think I'd prefer a single function instead of two

Can you also please try building VS Code with this fix to just confirm it handles your use case: https://github.com/microsoft/vscode/wiki/How-to-Contribute

That should cut down on back and forths since I don't have a good understand of the specifics of what you need on the Julia side

@@ -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.

@mjbvz mjbvz added this to the August 2021 Recovery milestone Sep 3, 2021
@davidanthoff
Copy link
Contributor Author

Can you also please try building VS Code with this fix to just confirm it handles your use case

I don't have the bandwidth to do that before sometime mid next week, sorry.

I don't have a good understand of the specifics of what you need on the Julia side

Maybe @DonJayamanne can help out? He wrote the original code in the Julia extension that preps all the metadata, all we need is an API that allows us to finish the TODO that @DonJayamanne left there.

Copy link
Contributor

@DonJayamanne DonJayamanne left a comment

Choose a reason for hiding this comment

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

I'd suggest renaming the method and making it more generic and future proofing this for more metadata properties.

@DonJayamanne
Copy link
Contributor

Once done, I'll ensure we use this same API in the Jupyter extension as well.

@DonJayamanne
Copy link
Contributor

Updated the PR, will test and get back.

Copy link
Contributor Author

@davidanthoff davidanthoff left a comment

Choose a reason for hiding this comment

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

@DonJayamanne this looks great! In particular the option to add arbitrary additional metadata, I think that could be very useful down the road.

I left a couple of points where maybe we should not make some fields part of the API here? But I don't think this is a biggy, they are all optional, so probably doesn't matter that much.

extensions/ipynb/src/ipynbMain.ts Show resolved Hide resolved
extensions/ipynb/src/ipynbMain.ts Show resolved Hide resolved
extensions/ipynb/src/ipynbMain.ts Show resolved Hide resolved
@DonJayamanne DonJayamanne requested a review from mjbvz September 7, 2021 17:12
Copy link
Contributor

@DonJayamanne DonJayamanne left a comment

Choose a reason for hiding this comment

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

Submitted changes.

Copy link
Contributor

@DonJayamanne DonJayamanne left a comment

Choose a reason for hiding this comment

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

Approving my PR, as its blocked by me.
@mjbvz I think we should remove the other API, not sure whether we do that now or later.

Copy link
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

LGTM. I'd say also remove the existing api. It was only added for this use case

@DonJayamanne
Copy link
Contributor

GTM. I'd say also remove the existing api. It was only added for this use case

Done

@DonJayamanne DonJayamanne merged commit 2581658 into microsoft:main Sep 7, 2021
mjbvz added a commit to mjbvz/vscode that referenced this pull request Sep 7, 2021
@davidanthoff davidanthoff deleted the setKernelSpecAndLanguageInfo branch September 7, 2021 21:44
mjbvz added a commit that referenced this pull request Sep 7, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants