Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 730c223

Browse files
authored
Use openWith command to open notebooks (microsoft#12104)
For #10496 #10744 Use vscode.openWith when opening a notebook.
1 parent c821c9e commit 730c223

File tree

9 files changed

+19
-12
lines changed

9 files changed

+19
-12
lines changed

src/client/common/application/commands.ts

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ interface ICommandNameWithoutArgumentTypeMapping {
8585
* @extends {ICommandNameWithoutArgumentTypeMapping}
8686
*/
8787
export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgumentTypeMapping {
88+
['vscode.openWith']: [Uri, string];
8889
['workbench.action.quickOpen']: [string];
8990
['workbench.extensions.installExtension']: [Uri | 'ms-python.python'];
9091
['setContext']: [string, boolean];

src/client/common/application/customEditorService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export class CustomEditorService implements ICustomEditorService {
2828
}
2929
}
3030

31-
public async openEditor(file: vscode.Uri): Promise<void> {
31+
public async openEditor(file: vscode.Uri, viewType: string): Promise<void> {
3232
if (this.useCustomEditorApi) {
33-
await this.commandManager.executeCommand('vscode.open', file);
33+
await this.commandManager.executeCommand('vscode.openWith', file, viewType);
3434
}
3535
}
3636
}

src/client/common/application/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ export interface ICustomEditorService {
14381438
/**
14391439
* Opens a file with a custom editor
14401440
*/
1441-
openEditor(file: Uri): Promise<void>;
1441+
openEditor(file: Uri, viewType: string): Promise<void>;
14421442
}
14431443

14441444
export const IClipboard = Symbol('IClipboard');

src/client/datascience/interactive-ipynb/nativeEditorProvider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class NativeEditorProvider
174174
disposable = this._onDidOpenNotebookEditor.event(handler);
175175

176176
// Send an open command.
177-
this.customEditorService.openEditor(file).ignoreErrors();
177+
this.customEditorService.openEditor(file, NativeEditorProvider.customEditorViewType).ignoreErrors();
178178

179179
// Promise should resolve when the file opens.
180180
return deferred.promise;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
export const JupyterNotebookView = 'jupyter-notebook';

src/client/datascience/notebook/notebookEditorProvider.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
monitorModelCellOutputChangesAndUpdateNotebookDocument,
3030
updateCellModelWithChangesToVSCCell
3131
} from './cellUpdateHelpers';
32+
import { JupyterNotebookView } from './constants';
3233
import { NotebookEditor } from './notebookEditor';
3334
import { INotebookExecutionService } from './types';
3435

@@ -147,7 +148,7 @@ export class NotebookEditorProvider implements INotebookEditorProvider {
147148

148149
// Tell VSC to open the notebook, at which point it will fire a callback when a notebook document has been opened.
149150
// Then our promise will get resolved.
150-
await this.commandManager.executeCommand('vscode.open', file);
151+
await this.commandManager.executeCommand('vscode.openWith', file, JupyterNotebookView);
151152

152153
// This gets resolved when we have handled the opening of the notebook.
153154
return deferred.promise;

src/test/datascience/interactive-ipynb/nativeEditorProvider.functional.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ suite('DataScience - Native Editor Provider', () => {
174174
});
175175

176176
customEditorService
177-
.setup((c) => c.openEditor(typemoq.It.isAny()))
177+
.setup((c) => c.openEditor(typemoq.It.isAny(), typemoq.It.isAny()))
178178
.returns(async (f) => {
179179
const doc = typemoq.Mock.ofType<CustomDocument>();
180180
doc.setup((d) => d.uri).returns(() => f);

src/test/datascience/mockCustomEditorService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class MockCustomEditorService implements ICustomEditorService {
5252

5353
return { dispose: noop };
5454
}
55-
public async openEditor(file: Uri): Promise<void> {
55+
public async openEditor(file: Uri, _viewType: string): Promise<void> {
5656
if (!this.provider) {
5757
throw new Error('Opening before registering');
5858
}

src/test/datascience/notebook/notebookEditorProvider.ds.test.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as sinon from 'sinon';
99
import { commands, Uri } from 'vscode';
1010
import { ICommandManager, IVSCodeNotebook } from '../../../client/common/application/types';
1111
import { IDisposable } from '../../../client/common/types';
12+
import { JupyterNotebookView } from '../../../client/datascience/notebook/constants';
1213
import { NotebookEditor } from '../../../client/datascience/notebook/notebookEditor';
1314
import { INotebookEditorProvider } from '../../../client/datascience/types';
1415
import { createEventHandler, IExtensionTestApi, waitForCondition } from '../../common';
@@ -125,7 +126,7 @@ suite('DataScience - VSCode Notebook', function () {
125126
await modelDisposed.assertFired();
126127
});
127128
test('Opening an nb multiple times will result in a single (our) INotebookEditor being created', async () => {
128-
await commandManager.executeCommand('vscode.open', Uri.file(templateIPynb));
129+
await commandManager.executeCommand('vscode.openWith', Uri.file(templateIPynb), JupyterNotebookView);
129130
await waitForCondition(async () => !!editorProvider.activeEditor, 2_000, 'Editor not created');
130131

131132
// Open a duplicate editor.
@@ -137,7 +138,7 @@ suite('DataScience - VSCode Notebook', function () {
137138
assert.lengthOf(editorProvider.editors, 1);
138139
});
139140
test('Closing one of the duplicate notebooks will not dispose (our) INotebookEditor until all VSC Editors are closed', async () => {
140-
await commandManager.executeCommand('vscode.open', Uri.file(templateIPynb));
141+
await commandManager.executeCommand('vscode.openWith', Uri.file(templateIPynb), JupyterNotebookView);
141142
await waitForCondition(async () => !!editorProvider.activeEditor, 2_000, 'Editor not created');
142143

143144
const editorDisposed = createEventHandler(editorProvider.activeEditor!, 'closed', disposables);
@@ -221,7 +222,7 @@ suite('DataScience - VSCode Notebook', function () {
221222
assert.isUndefined(editorProvider.activeEditor);
222223
assert.equal(editorProvider.editors.length, 0);
223224

224-
await commandManager.executeCommand('vscode.open', testIPynb);
225+
await commandManager.executeCommand('vscode.openWith', testIPynb, JupyterNotebookView);
225226

226227
assert.equal(editorProvider.editors.length, 1);
227228
assert.isOk(vscodeNotebook.activeNotebookEditor);
@@ -232,7 +233,7 @@ suite('DataScience - VSCode Notebook', function () {
232233
assert.isUndefined(editorProvider.activeEditor);
233234
assert.equal(editorProvider.editors.length, 0);
234235

235-
await commandManager.executeCommand('vscode.open', testIPynb);
236+
await commandManager.executeCommand('vscode.openWith', testIPynb, JupyterNotebookView);
236237

237238
assert.equal(editorProvider.editors.length, 1);
238239
assert.isOk(vscodeNotebook.activeNotebookEditor);
@@ -295,7 +296,7 @@ suite('DataScience - VSCode Notebook', function () {
295296
await activeNotebookChanged.assertFiredExactly(1);
296297

297298
// Open another notebook.
298-
await commandManager.executeCommand('vscode.open', testIPynb);
299+
await commandManager.executeCommand('vscode.openWith', testIPynb, JupyterNotebookView);
299300

300301
await notebookOpened.assertFiredExactly(2);
301302
await activeNotebookChanged.assertFiredExactly(2);

0 commit comments

Comments
 (0)