Skip to content

Port custom editor changes to release branch #12222

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

Merged
merged 3 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// Enable this to turn on redux logging during debugging
"XVSC_PYTHON_FORCE_LOGGING": "1",
// Enable this to try out new experiments locally
"XVSC_PYTHON_LOAD_EXPERIMENTS_FROM_FILE": "1",
"VSC_PYTHON_LOAD_EXPERIMENTS_FROM_FILE": "1",
// Enable this to log telemetry to the output during debugging
"XVSC_PYTHON_LOG_TELEMETRY": "1",
// Enable this to log debugger output. Directory must exist ahead of time
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## 2020.6.0-rc (8 June 2020)
## 2020.6.0-rc (15 June 2020)
Copy link
Member

Choose a reason for hiding this comment

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

Date seems wrong?

Copy link
Author

Choose a reason for hiding this comment

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

That's the ship date. I suppose I didn't need to change it yet.


### Enhancements

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

### Fixes

Expand Down
19 changes: 19 additions & 0 deletions customEditor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"activationEvents": [
"onCustomEditor:ms-python.python.notebook.ipynb"
],
"contributes": {
"customEditors": [
{
"viewType": "ms-python.python.notebook.ipynb",
"displayName": "Jupyter Notebook",
"selector": [
{
"filenamePattern": "*.ipynb"
}
],
"priority": "default"
}
]
}
}
12 changes: 12 additions & 0 deletions experiments.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@
"salt": "RunByLine",
"max": 0,
"min": 0
},
{
"name": "CustomEditorSupport - control",
"salt": "CustomEditorSupport",
"min": 0,
"max": 100
},
{
"name": "CustomEditorSupport - experiment",
"salt": "CustomEditorSupport",
"max": 0,
"min": 0
}

]
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"onCommand:python.datascience.selectJupyterInterpreter",
"onCommand:python.datascience.selectjupytercommandline",
"onCommand:python.enableSourceMapSupport",
"onCustomEditor:NativeEditorProvider.ipynb",

"onNotebookEditor:jupyter-notebook",
"workspaceContains:**/mspythonconfig.json"
],
Expand Down Expand Up @@ -3161,7 +3161,7 @@
"@types/tmp": "0.0.33",
"@types/untildify": "^3.0.0",
"@types/uuid": "^3.4.3",
"@types/vscode": "^1.43.0",
"@types/vscode": "^1.45.0",
"@types/webpack-bundle-analyzer": "^2.13.0",
"@types/winreg": "^1.2.30",
"@types/ws": "^6.0.1",
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -510,5 +510,6 @@
"DataScience.continueRunByLine": "Stop",
"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.",
"DataScience.rawKernelSessionFailed": "Unable to start session for kernel {0}. Select another kernel to launch with.",
"DataScience.rawKernelConnectingSession": "Connecting to kernel."
"DataScience.rawKernelConnectingSession": "Connecting to kernel.",
"DataScience.reloadCustomEditor": "Please reload VS Code to use the custom editor API"
}
41 changes: 36 additions & 5 deletions src/client/common/application/customEditorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import * as path from 'path';
import * as vscode from 'vscode';
import { DataScience } from '../../common/utils/localize';

import { UseCustomEditorApi } from '../constants';
import { traceError } from '../../logging';
import { EXTENSION_ROOT_DIR, UseCustomEditorApi } from '../constants';
import { IFileSystem } from '../platform/types';
import { noop } from '../utils/misc';
import { CustomEditorProvider, ICommandManager, ICustomEditorService } from './types';
import { CustomEditorProvider, IApplicationEnvironment, ICommandManager, ICustomEditorService } from './types';

@injectable()
export class CustomEditorService implements ICustomEditorService {
constructor(
@inject(ICommandManager) private commandManager: ICommandManager,
@inject(UseCustomEditorApi) private readonly useCustomEditorApi: boolean
) {}
@inject(UseCustomEditorApi) private readonly useCustomEditorApi: boolean,
@inject(IApplicationEnvironment) private readonly appEnvironment: IApplicationEnvironment,
@inject(IFileSystem) private readonly fileSystem: IFileSystem
) {
// Double check the package json has the necessary entries for contributing a custom editor
if (this.useCustomEditorApi && !appEnvironment.packageJson.contributes?.customEditors) {
this.rewritePackageJson().catch((e) => traceError(`Error rewriting package json: `, e));
}
}

public registerCustomEditorProvider(
viewType: string,
provider: CustomEditorProvider,
options?: vscode.WebviewPanelOptions
options?: {
readonly webviewOptions?: vscode.WebviewPanelOptions;
readonly supportsMultipleEditorsPerDocument?: boolean;
}
): vscode.Disposable {
if (this.useCustomEditorApi) {
// tslint:disable-next-line: no-any
Expand All @@ -33,4 +47,21 @@ export class CustomEditorService implements ICustomEditorService {
await this.commandManager.executeCommand('vscode.openWith', file, viewType);
}
}

private async rewritePackageJson() {
// tslint:disable-next-line:no-require-imports no-var-requires
const _mergeWith = require('lodash/mergeWith') as typeof import('lodash/mergeWith');
const current = this.appEnvironment.packageJson;
const improvedContents = await this.fileSystem.readFile(path.join(EXTENSION_ROOT_DIR, 'customEditor.json'));
const improved = _mergeWith({ ...current }, JSON.parse(improvedContents), (l, r) => {
if (Array.isArray(l) && Array.isArray(r)) {
return [...l, ...r];
}
});
await this.fileSystem.writeFile(
path.join(EXTENSION_ROOT_DIR, 'package.json'),
JSON.stringify(improved, null, 4)
);
this.commandManager.executeCommand('python.reloadVSCode', DataScience.reloadCustomEditor());
}
}
8 changes: 5 additions & 3 deletions src/client/common/application/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import type {
NotebookOutputSelector
} from 'vscode-proposed';
import { UseProposedApi } from '../constants';
import { IDisposableRegistry } from '../types';
import { NativeNotebook } from '../experiments/groups';
import { IDisposableRegistry, IExperimentsManager } from '../types';
import {
IVSCodeNotebook,
NotebookCellLanguageChangeEvent,
Expand Down Expand Up @@ -62,9 +63,10 @@ export class VSCodeNotebook implements IVSCodeNotebook {
private readonly handledCellChanges = new WeakSet<VSCNotebookCellsChangeEvent>();
constructor(
@inject(UseProposedApi) private readonly useProposedApi: boolean,
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
@inject(IExperimentsManager) readonly experimentManager: IExperimentsManager
) {
if (this.useProposedApi) {
if (this.useProposedApi && experimentManager.inExperiment(NativeNotebook.experiment)) {
this.addEventHandlers();
}
}
Expand Down
Loading