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 command for new blank notebook #739

Merged
merged 2 commits into from Sep 2, 2020
Merged

add command for new blank notebook #739

merged 2 commits into from Sep 2, 2020

Conversation

@brettfo
Copy link
Member

brettfo commented Sep 1, 2020

The new command's display name is ".NET Interactive: Create new blank notebook" for two reasons:

  1. All of our other command names start with ".NET Interactive:" to remove any ambiguity and I thought that should continue.
  2. The Python command to create a new Jupyter notebook is "Create New Blank Jupyter Notebook".

I've added a keybinding of Ctrl+Alt+Shift+N to invoke this. It's extremely verbose, but I don't want to steal any existing keybinding, and unfortunately that means we can't use the chord Ctrl+N, D because that causes the default Ctrl+N to be unbound because it's waiting for a chord to continue, and that's bad. An alternative is to not have a default keybinding and let users add their own that simply invokes the command dotnet-interactive.newNotebook. I'm open to either approach.

As for changes to code, there were really only 3 of note:

  1. To create a new untitled notebook, I avoided calling workbench.action.files.newUntitledFile { viewType: 'dotnet-interactive' } because that creates a new notebook with the name Untitled-1 (note, no file extension) and when the user hits Ctrl+S, the save dialog defaults to the .txt extension, and that can cause a whole bunch of problems because the file format is chosen depending on the extension, and if the user chooses .txt (or .my-notebook, etc.) we have no idea how to serialize the notebook. Instead, I manually create a URI with the .dib file extension pre-applied. This means when the user finally saves their notebook, it'll have the correct extension. It's still possible for them to manually override this, but that's on them; if they're mangling the file extensions we can't help them. To enable multiple unsaved notebooks, I look through the existing notebooks until I can find a numeric suffix that's unused, e.g., Untitled-9.dib.

  2. Add the method ClientMapper.reassociateClient. This is necessary because the notebook's runtime is associated with the notebook's URI. In normal scenarios, this will be something like C:\Users\brettfo\Desktop\my-notebook.dib. In the case of a new unsaved notebook, the URI is Untitled-1.dib. Initially this is fine, but as soon as the user saves the notebook, the URI will suddenly be a file path like above and since we don't want them to loose their current runtime values and leave around a stale kernel, the reassociate method does exactly that: reassociates the kernel process with the new URI.

  3. VS Code will call openNotebook when creating a new notebook viewer, but if it's an unsaved notebook created through the new command, nothing exists on disk. The fix for this was simple; if it's a new unsaved file, short-circuit everything and create an empty notebook.

brettfo added 2 commits Sep 1, 2020
Also improve the experience when working with one.
@brettfo brettfo force-pushed the brettfo:new-notebook branch from a6575ac to fe1be62 Sep 2, 2020
@brettfo brettfo merged commit 8efa118 into dotnet:main Sep 2, 2020
8 checks passed
8 checks passed
interactive-ci Build #20200902.13 succeeded
Details
interactive-ci (Build and Test Dockerfile_Binder_Dependency) Build and Test Dockerfile_Binder_Dependency succeeded
Details
interactive-ci (Build and Test Dockerfile_Main) Build and Test Dockerfile_Main succeeded
Details
interactive-ci (Build and Test Dockerfile_official_image) Build and Test Dockerfile_official_image succeeded
Details
interactive-ci (Build and Test IntegrationTest) Build and Test IntegrationTest succeeded
Details
interactive-ci (Build and Test Linux) Build and Test Linux succeeded
Details
interactive-ci (Build and Test Windows_NT) Build and Test Windows_NT succeeded
Details
license/cla All CLA requirements met.
Details
@brettfo brettfo deleted the brettfo:new-notebook branch Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.