Preserve Jupyter kernels during notebook file rename #16809
Draft
+399
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When renaming a notebook file (
.ipynb
) in VS Code, the Jupyter kernel would restart unnecessarily, losing all variables and execution state. This PR implements kernel preservation during file rename operations to match JupyterLab's behavior.Problem
Previously, when a user renamed a notebook file:
onDidCloseNotebookDocument
event would trigger kernel disposalThis differs from JupyterLab where renaming preserves the kernel session.
Solution
This PR adds a
NotebookRenameHandler
service that:workspace.onWillRenameFiles
events.ipynb
files are being renamedKey Changes
src/kernels/notebookRenameHandler.ts
- New service to handle rename eventssrc/kernels/kernelProvider.base.ts
- Enhanced with kernel migration logicsrc/kernels/serviceRegistry.node.ts
- Service registrationExample Usage
Testing
Fixes #11010.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
0.0.0.123
node /home/REDACTED/work/vscode-jupyter/vscode-jupyter/node_modules/.bin/mocha --config ./build/.mocha.unittests.js.json ./out/interactive-window/generatedCodeStorageManager.unit.test.js ./out/interactive-window/shiftEnterBanner.unit.test.js ./out/kernels/helpers.unit.test.js ./out/kernels/kernelAutoReConnectMonitor.unit.test.js ./out/kernels/kernelAutoRestartMonitor.unit.test.js ./out/kernels/kernelCrashMonitor.unit.test.js ./out/kernels/kernelDependencyService.unit.test.js ./out/kernels/kernelFinder.unit.test.js ./out/kernels/kernelProvider.node.unit.test.js ./out/kernels/kernelProvider.web.unit.test.js ./out/kernels/kernelRefreshIndicator.node.unit.test.js ./out/kernels/kernelRefreshIndicator.web.unit.test.js ./out/test/package.nls.json.unit.test.js
(packet block)node /home/REDACTED/work/vscode-jupyter/vscode-jupyter/node_modules/.bin/mocha --config ./build/.mocha.unittests.js.json ./out/interactive-window/generatedCodeStorageManager.unit.test.js ./out/interactive-window/shiftEnterBanner.unit.test.js ./out/kernels/helpers.unit.test.js ./out/kernels/kernelAutoReConnectMonitor.unit.test.js ./out/kernels/kernelAutoRestartMonitor.unit.test.js ./out/kernels/kernelCrashMonitor.unit.test.js ./out/kernels/kernelDependencyService.unit.test.js ./out/kernels/kernelFinder.unit.test.js ./out/kernels/kernelProvider.base.unit.test.js ./out/kernels/kernelProvider.node.unit.test.js ./out/kernels/kernelProvider.web.unit.test.js ./out/kernels/kernelRefreshIndicator.node.unit.test.js ./out/kernels/kernelRefreshIndicator.web.unit.test.js ./out/kernels/notebookRenameHandler.unit.test.js ./out/test/package.nls.json.unit.test.js
(packet block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.