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

Implement the changes necessary to use the new custom editor #12188

Merged
merged 24 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bb5e0ad
Turn on custom editor again
rchiodo May 27, 2020
66ea1dd
Fix copy problem
rchiodo May 27, 2020
d27e2f6
Fix copy problem again
rchiodo May 27, 2020
08c0760
Merge remote-tracking branch 'origin/master' into rchiodo/renable_cus…
rchiodo May 27, 2020
e49e9ad
Get undo/redo to work
rchiodo May 27, 2020
d167a10
Merge remote-tracking branch 'origin/master' into rchiodo/renable_cus…
rchiodo May 29, 2020
0f48e1e
Some fixes for synching more than one editor
rchiodo May 29, 2020
d92a98b
Merge remote-tracking branch 'origin/master' into rchiodo/renable_cus…
rchiodo Jun 3, 2020
cc921af
Fix untitled. Fix timeouts
rchiodo Jun 4, 2020
c3a470c
fix command manager to not be used. Not necessary with temp path.
rchiodo Jun 5, 2020
ed58c18
Fix functional test
rchiodo Jun 5, 2020
80b881f
Merge remote-tracking branch 'origin/master' into rchiodo/renable_cus…
rchiodo Jun 5, 2020
d101156
Add experiment
rchiodo Jun 5, 2020
6b3d3b6
Merge remote-tracking branch 'origin/master' into rchiodo/renable_cus…
rchiodo Jun 5, 2020
2922e7c
Since package json is enabling proposed api, turn of notebooks with e…
rchiodo Jun 6, 2020
384e38c
Turn off proposed api
rchiodo Jun 6, 2020
a6a9479
Upgrade VS code to 1.45 so can use new api outside of insiders
rchiodo Jun 6, 2020
a115152
Update package.json dynamically
rchiodo Jun 8, 2020
7861c7d
Fix merge code to handle arrays
rchiodo Jun 8, 2020
4715a36
Fix unit tests. Backup happens at the provider level now
rchiodo Jun 8, 2020
b48c8d9
Fix hygiene
rchiodo Jun 8, 2020
23329a6
Fix untitled to work for old provider too
rchiodo Jun 8, 2020
496b8be
Some feedback and attempt to fix URI problem on linux/mac
rchiodo Jun 8, 2020
615caf5
Review feedback
rchiodo Jun 8, 2020
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",

Choose a reason for hiding this comment

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

Oops

Copy link
Author

Choose a reason for hiding this comment

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

Actually this was on purpose. Otherwise experiments won't load from the json file.

// 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
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"
}
]
}
}
2 changes: 1 addition & 1 deletion data/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"python.pythonPath": "/usr/bin/python3"
"python.pythonPath": "C:\\Users\\rchiodo.REDMOND\\AppData\\Local\\Continuum\\miniconda3\\envs\\jupyter\\python.exe"

Choose a reason for hiding this comment

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

Might want to revert

Copy link
Author

Choose a reason for hiding this comment

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

Will do.

}
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
}

]
1 change: 1 addition & 0 deletions news/1 Enhancements/10744.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable the use of the custom editor for native notebooks.
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 @@ -3162,7 +3162,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"
}
40 changes: 35 additions & 5 deletions src/client/common/application/customEditorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@
// 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 { 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().ignoreErrors();
rchiodo marked this conversation as resolved.
Show resolved Hide resolved
}
}

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 +46,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');
DonJayamanne marked this conversation as resolved.
Show resolved Hide resolved
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