Skip to content

Commit 22092d9

Browse files
authored
Port custom editor changes to release branch (#12222)
* Implement the changes necessary to use the new custom editor (#12188) * Turn on custom editor again * Fix copy problem * Fix copy problem again * Get undo/redo to work * Some fixes for synching more than one editor * Fix untitled. Fix timeouts * fix command manager to not be used. Not necessary with temp path. fix delete/insert commands to undo properly * Fix functional test * Add experiment * Since package json is enabling proposed api, turn of notebooks with experiment * Turn off proposed api * Upgrade VS code to 1.45 so can use new api outside of insiders * Update package.json dynamically * Fix merge code to handle arrays * Fix unit tests. Backup happens at the provider level now * Fix hygiene * Fix untitled to work for old provider too * Some feedback and attempt to fix URI problem on linux/mac * Review feedback * Update changelog * Remove news entry
1 parent 842844e commit 22092d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+659
-355
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// Enable this to turn on redux logging during debugging
2626
"XVSC_PYTHON_FORCE_LOGGING": "1",
2727
// Enable this to try out new experiments locally
28-
"XVSC_PYTHON_LOAD_EXPERIMENTS_FROM_FILE": "1",
28+
"VSC_PYTHON_LOAD_EXPERIMENTS_FROM_FILE": "1",
2929
// Enable this to log telemetry to the output during debugging
3030
"XVSC_PYTHON_LOG_TELEMETRY": "1",
3131
// Enable this to log debugger output. Directory must exist ahead of time

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## 2020.6.0-rc (8 June 2020)
3+
## 2020.6.0-rc (15 June 2020)
44

55
### Enhancements
66

@@ -12,6 +12,8 @@
1212
([#11057](https://github.com/Microsoft/vscode-python/issues/11057))
1313
1. Preliminary support using other languages for the kernel.
1414
([#11919](https://github.com/Microsoft/vscode-python/issues/11919))
15+
1. Enable the use of the custom editor for native notebooks.
16+
([#10744](https://github.com/Microsoft/vscode-python/issues/10744))
1517

1618
### Fixes
1719

customEditor.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"activationEvents": [
3+
"onCustomEditor:ms-python.python.notebook.ipynb"
4+
],
5+
"contributes": {
6+
"customEditors": [
7+
{
8+
"viewType": "ms-python.python.notebook.ipynb",
9+
"displayName": "Jupyter Notebook",
10+
"selector": [
11+
{
12+
"filenamePattern": "*.ipynb"
13+
}
14+
],
15+
"priority": "default"
16+
}
17+
]
18+
}
19+
}

experiments.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@
196196
"salt": "RunByLine",
197197
"max": 0,
198198
"min": 0
199+
},
200+
{
201+
"name": "CustomEditorSupport - control",
202+
"salt": "CustomEditorSupport",
203+
"min": 0,
204+
"max": 100
205+
},
206+
{
207+
"name": "CustomEditorSupport - experiment",
208+
"salt": "CustomEditorSupport",
209+
"max": 0,
210+
"min": 0
199211
}
200212

201213
]

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"onCommand:python.datascience.selectJupyterInterpreter",
9292
"onCommand:python.datascience.selectjupytercommandline",
9393
"onCommand:python.enableSourceMapSupport",
94-
"onCustomEditor:NativeEditorProvider.ipynb",
94+
9595
"onNotebookEditor:jupyter-notebook",
9696
"workspaceContains:**/mspythonconfig.json"
9797
],
@@ -3161,7 +3161,7 @@
31613161
"@types/tmp": "0.0.33",
31623162
"@types/untildify": "^3.0.0",
31633163
"@types/uuid": "^3.4.3",
3164-
"@types/vscode": "^1.43.0",
3164+
"@types/vscode": "^1.45.0",
31653165
"@types/webpack-bundle-analyzer": "^2.13.0",
31663166
"@types/winreg": "^1.2.30",
31673167
"@types/ws": "^6.0.1",

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,5 +510,6 @@
510510
"DataScience.continueRunByLine": "Stop",
511511
"DataScience.couldNotInstallLibrary": "Could not install {0}. If pip is not available, please use the package manager of your choice to manually install this library into your Python environment.",
512512
"DataScience.rawKernelSessionFailed": "Unable to start session for kernel {0}. Select another kernel to launch with.",
513-
"DataScience.rawKernelConnectingSession": "Connecting to kernel."
513+
"DataScience.rawKernelConnectingSession": "Connecting to kernel.",
514+
"DataScience.reloadCustomEditor": "Please reload VS Code to use the custom editor API"
514515
}

src/client/common/application/customEditorService.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@
22
// Licensed under the MIT License.
33
'use strict';
44
import { inject, injectable } from 'inversify';
5+
import * as path from 'path';
56
import * as vscode from 'vscode';
7+
import { DataScience } from '../../common/utils/localize';
68

7-
import { UseCustomEditorApi } from '../constants';
9+
import { traceError } from '../../logging';
10+
import { EXTENSION_ROOT_DIR, UseCustomEditorApi } from '../constants';
11+
import { IFileSystem } from '../platform/types';
812
import { noop } from '../utils/misc';
9-
import { CustomEditorProvider, ICommandManager, ICustomEditorService } from './types';
13+
import { CustomEditorProvider, IApplicationEnvironment, ICommandManager, ICustomEditorService } from './types';
1014

1115
@injectable()
1216
export class CustomEditorService implements ICustomEditorService {
1317
constructor(
1418
@inject(ICommandManager) private commandManager: ICommandManager,
15-
@inject(UseCustomEditorApi) private readonly useCustomEditorApi: boolean
16-
) {}
19+
@inject(UseCustomEditorApi) private readonly useCustomEditorApi: boolean,
20+
@inject(IApplicationEnvironment) private readonly appEnvironment: IApplicationEnvironment,
21+
@inject(IFileSystem) private readonly fileSystem: IFileSystem
22+
) {
23+
// Double check the package json has the necessary entries for contributing a custom editor
24+
if (this.useCustomEditorApi && !appEnvironment.packageJson.contributes?.customEditors) {
25+
this.rewritePackageJson().catch((e) => traceError(`Error rewriting package json: `, e));
26+
}
27+
}
1728

1829
public registerCustomEditorProvider(
1930
viewType: string,
2031
provider: CustomEditorProvider,
21-
options?: vscode.WebviewPanelOptions
32+
options?: {
33+
readonly webviewOptions?: vscode.WebviewPanelOptions;
34+
readonly supportsMultipleEditorsPerDocument?: boolean;
35+
}
2236
): vscode.Disposable {
2337
if (this.useCustomEditorApi) {
2438
// tslint:disable-next-line: no-any
@@ -33,4 +47,21 @@ export class CustomEditorService implements ICustomEditorService {
3347
await this.commandManager.executeCommand('vscode.openWith', file, viewType);
3448
}
3549
}
50+
51+
private async rewritePackageJson() {
52+
// tslint:disable-next-line:no-require-imports no-var-requires
53+
const _mergeWith = require('lodash/mergeWith') as typeof import('lodash/mergeWith');
54+
const current = this.appEnvironment.packageJson;
55+
const improvedContents = await this.fileSystem.readFile(path.join(EXTENSION_ROOT_DIR, 'customEditor.json'));
56+
const improved = _mergeWith({ ...current }, JSON.parse(improvedContents), (l, r) => {
57+
if (Array.isArray(l) && Array.isArray(r)) {
58+
return [...l, ...r];
59+
}
60+
});
61+
await this.fileSystem.writeFile(
62+
path.join(EXTENSION_ROOT_DIR, 'package.json'),
63+
JSON.stringify(improved, null, 4)
64+
);
65+
this.commandManager.executeCommand('python.reloadVSCode', DataScience.reloadCustomEditor());
66+
}
3667
}

src/client/common/application/notebook.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import type {
1414
NotebookOutputSelector
1515
} from 'vscode-proposed';
1616
import { UseProposedApi } from '../constants';
17-
import { IDisposableRegistry } from '../types';
17+
import { NativeNotebook } from '../experiments/groups';
18+
import { IDisposableRegistry, IExperimentsManager } from '../types';
1819
import {
1920
IVSCodeNotebook,
2021
NotebookCellLanguageChangeEvent,
@@ -62,9 +63,10 @@ export class VSCodeNotebook implements IVSCodeNotebook {
6263
private readonly handledCellChanges = new WeakSet<VSCNotebookCellsChangeEvent>();
6364
constructor(
6465
@inject(UseProposedApi) private readonly useProposedApi: boolean,
65-
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry
66+
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
67+
@inject(IExperimentsManager) readonly experimentManager: IExperimentsManager
6668
) {
67-
if (this.useProposedApi) {
69+
if (this.useProposedApi && experimentManager.inExperiment(NativeNotebook.experiment)) {
6870
this.addEventHandlers();
6971
}
7072
}

0 commit comments

Comments
 (0)