Skip to content

Commit

Permalink
Revert "Updates to VS Code Proposed API (#5822)" (#5830)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed May 11, 2021
1 parent a100c9f commit f043328
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 284 deletions.
1 change: 0 additions & 1 deletion news/3 Code Health/5809.md

This file was deleted.

5 changes: 4 additions & 1 deletion src/client/common/net/portAttributeProvider.ts
Expand Up @@ -29,7 +29,10 @@ export class PortAttributesProviders implements PortAttributesProvider, IExtensi
): PortAttributes | undefined {
try {
if (KernelLauncher.usedPorts.includes(port) || NotebookStarter.usedPorts.includes(port)) {
return new PortAttributes(port, PortAutoForwardAction.Ignore);
return {
autoForwardAction: PortAutoForwardAction.Ignore,
port
};
}
} catch (ex) {
// In case proposed API changes.
Expand Down
Expand Up @@ -35,11 +35,7 @@ export class NotebookUsageTracker implements IExtensionSingleActivationService {
findFilesPromise.then((r) => (this.notebookCount += r.length), noop);
}
this.editorProvider.onDidOpenNotebookEditor(this.onEditorOpened, this, this.disposables);
notebook.onDidChangeNotebookCellExecutionState(
this.onDidChangeNotebookCellExecutionState,
this,
this.disposables
);
notebook.onDidChangeCellExecutionState(this.onDidChangeCellExecutionState, this, this.disposables);
}
public dispose() {
// Send a bunch of telemetry
Expand All @@ -64,7 +60,7 @@ export class NotebookUsageTracker implements IExtensionSingleActivationService {
editor.executed((e) => this.executedNotebooksIndexedByUri.add(e.file.fsPath), this, this.disposables);
}
}
private onDidChangeNotebookCellExecutionState(e: NotebookCellExecutionStateChangeEvent): void {
private onDidChangeCellExecutionState(e: NotebookCellExecutionStateChangeEvent): void {
this.executedNotebooksIndexedByUri.add(e.cell.notebook.uri.fsPath);
}
}
2 changes: 1 addition & 1 deletion src/client/datascience/jupyter/kernels/kernelExecution.ts
Expand Up @@ -43,7 +43,7 @@ export class KernelExecution implements IDisposable {

@captureTelemetry(Telemetry.ExecuteNativeCell, undefined, true)
public async executeCell(notebookPromise: Promise<INotebook>, cell: NotebookCell): Promise<void> {
if (cell.kind == NotebookCellKind.Markup) {
if (cell.kind == NotebookCellKind.Markdown) {
return;
}
sendKernelTelemetryEvent(cell.notebook.uri, Telemetry.ExecuteNativeCell);
Expand Down
17 changes: 8 additions & 9 deletions src/client/datascience/notebook/contentProvider.ts
Expand Up @@ -15,8 +15,7 @@ import {
NotebookDocumentBackupContext,
NotebookDocumentOpenContext,
NotebookDocumentMetadata,
NotebookCellMetadata,
NotebookCellData
NotebookCellMetadata
} from 'vscode';
import { IVSCodeNotebook } from '../../common/application/types';
import { MARKDOWN_LANGUAGE } from '../../common/constants';
Expand Down Expand Up @@ -48,13 +47,13 @@ export class NotebookContentProvider implements VSCNotebookContentProvider {
// We cannot, not display a notebook.
return {
cells: [
new NotebookCellData(
NotebookCellKind.Markup,
`# ${DataScience.usingPreviewNotebookWithOtherNotebookWarning()}`,
MARKDOWN_LANGUAGE,
[],
new NotebookCellMetadata()
)
{
kind: NotebookCellKind.Markdown,
language: MARKDOWN_LANGUAGE,
source: `# ${DataScience.usingPreviewNotebookWithOtherNotebookWarning()}`,
metadata: new NotebookCellMetadata(),
outputs: []
}
],
metadata: new NotebookDocumentMetadata()
};
Expand Down
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { inject, injectable } from 'inversify';
import { languages, NotebookCellKind, NotebookDocument } from 'vscode';
import { NotebookCellKind, NotebookCellOutput, NotebookDocument, NotebookRange } from 'vscode';
import { IExtensionSingleActivationService } from '../../activation/types';
import { IVSCodeNotebook } from '../../common/application/types';
import { PYTHON_LANGUAGE } from '../../common/constants';
Expand Down Expand Up @@ -89,12 +89,20 @@ export class EmptyNotebookCellLanguageService implements IExtensionSingleActivat
}

const monacoLanguage = translateKernelLanguageToMonaco(language);
chainWithPendingUpdates(editor.document, async () => {
await emptyCodeCells.map(async (cell) => {
chainWithPendingUpdates(editor.document, (edit) => {
emptyCodeCells.forEach((cell) => {
if (monacoLanguage.toLowerCase() === cell.document.languageId) {
return;
}
return languages.setTextDocumentLanguage(cell.document, monacoLanguage).then(noop, noop);
edit.replaceNotebookCells(editor.document.uri, new NotebookRange(cell.index, cell.index + 1), [
{
kind: cell.kind,
language: monacoLanguage,
metadata: cell.metadata,
outputs: cell.outputs.map((op) => new NotebookCellOutput(op.outputs)),
source: cell.document.getText()
}
]);
});
}).then(noop, noop);
}
Expand Down
18 changes: 8 additions & 10 deletions src/client/datascience/notebook/helpers/executionHelpers.ts
Expand Up @@ -4,15 +4,7 @@
'use strict';

import type { nbformat } from '@jupyterlab/coreutils';
import {
workspace,
Range,
WorkspaceEdit,
NotebookCellKind,
NotebookCell,
NotebookRange,
NotebookCellData
} from 'vscode';
import { workspace, Range, WorkspaceEdit, NotebookCellKind, NotebookCell, NotebookRange } from 'vscode';
import { traceCellMessage } from './helpers';
import { chainWithPendingUpdates } from './notebookUpdater';

Expand Down Expand Up @@ -49,7 +41,13 @@ export async function addNewCellAfter(cell: NotebookCell, text: string) {
await chainWithPendingUpdates(cell.notebook, (edit) => {
traceCellMessage(cell, 'Create new cell after current');
edit.replaceNotebookCells(cell.notebook.uri, new NotebookRange(cell.index + 1, cell.index + 1), [
new NotebookCellData(NotebookCellKind.Code, text, cell.document.languageId, [], cell.metadata.with({}))
{
kind: NotebookCellKind.Code,
language: cell.document.languageId,
metadata: cell.metadata.with({}),
outputs: [],
source: text
}
]);
});
}
20 changes: 11 additions & 9 deletions src/client/datascience/notebook/helpers/helpers.ts
Expand Up @@ -230,7 +230,13 @@ export function notebookModelToVSCNotebookData(
.map((item) => item!);

if (cells.length === 0 && (isUntitledFile(notebookUri) || Object.keys(originalJson).length === 0)) {
cells.push(new NotebookCellData(NotebookCellKind.Code, '', preferredLanguage));
cells.push({
kind: NotebookCellKind.Code,
language: preferredLanguage,
metadata: new NotebookCellMetadata(),
outputs: [],
source: ''
});
}
return new NotebookData(
cells,
Expand All @@ -254,7 +260,7 @@ export function createJupyterCellFromVSCNotebookCell(
vscCell: NotebookCell
): nbformat.IRawCell | nbformat.IMarkdownCell | nbformat.ICodeCell {
let cell: nbformat.IRawCell | nbformat.IMarkdownCell | nbformat.ICodeCell;
if (vscCell.kind === NotebookCellKind.Markup) {
if (vscCell.kind === NotebookCellKind.Markdown) {
cell = createMarkdownCellFromNotebookCell(vscCell);
} else if (vscCell.document.languageId === 'raw' || vscCell.document.languageId === 'plaintext') {
cell = createRawCellFromNotebookCell(vscCell);
Expand Down Expand Up @@ -339,7 +345,7 @@ function createNotebookCellDataFromMarkdownCell(cell: nbformat.IMarkdownCell): N
custom: getNotebookCellMetadata(cell)
});
return new NotebookCellData(
NotebookCellKind.Markup,
NotebookCellKind.Markdown,
concatMultilineString(cell.source),
MARKDOWN_LANGUAGE,
[],
Expand Down Expand Up @@ -407,19 +413,15 @@ export class NotebookCellStateTracker implements IDisposable {
private readonly disposables: IDisposable[] = [];
private static cellStates = new WeakMap<NotebookCell, NotebookCellExecutionState>();
constructor() {
notebook.onDidChangeNotebookCellExecutionState(
this.onDidChangeNotebookCellExecutionState,
this,
this.disposables
);
notebook.onDidChangeCellExecutionState(this.onDidChangeCellExecutionState, this, this.disposables);
}
dispose() {
disposeAllDisposables(this.disposables);
}
public static getCellState(cell: NotebookCell): NotebookCellExecutionState | undefined {
return NotebookCellStateTracker.cellStates.get(cell);
}
private onDidChangeNotebookCellExecutionState(e: NotebookCellExecutionStateChangeEvent) {
private onDidChangeCellExecutionState(e: NotebookCellExecutionStateChangeEvent) {
NotebookCellStateTracker.cellStates.set(e.cell, e.executionState);
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/client/datascience/notebook/notebookEditor.ts
Expand Up @@ -9,12 +9,12 @@ import {
EventEmitter,
NotebookCell,
NotebookCellKind,
NotebookCellMetadata,
NotebookRange,
NotebookDocument,
ProgressLocation,
Uri,
WebviewPanel,
NotebookCellData
WebviewPanel
} from 'vscode';
import { IApplicationShell, ICommandManager, IVSCodeNotebook } from '../../common/application/types';
import { traceError, traceInfo } from '../../common/logger';
Expand Down Expand Up @@ -148,7 +148,13 @@ export class NotebookEditor implements INotebookEditor {
if (editor) {
chainWithPendingUpdates(editor.document, (edit) =>
edit.replaceNotebookCells(editor.document.uri, new NotebookRange(0, this.document.cellCount), [
new NotebookCellData(NotebookCellKind.Code, '', defaultLanguage)
{
kind: NotebookCellKind.Code,
language: defaultLanguage,
metadata: new NotebookCellMetadata(),
outputs: [],
source: ''
}
])
).then(noop, noop);
}
Expand Down
12 changes: 4 additions & 8 deletions src/client/datascience/notebook/vscodeNotebookController.ts
Expand Up @@ -16,7 +16,6 @@ import {
UIKind,
Uri
} from 'vscode';
import { IS_CI_SERVER } from '../../../test/ciConstants';
import { ICommandManager, IVSCodeNotebook } from '../../common/application/types';
import { JVSC_EXTENSION_ID } from '../../common/constants';
import { disposeAllDisposables } from '../../common/helpers';
Expand Down Expand Up @@ -122,13 +121,10 @@ export class VSCodeNotebookController implements Disposable {

public async updateNotebookAffinity(notebook: NotebookDocument, affinity: NotebookControllerAffinity) {
this.controller.updateNotebookAffinity(notebook, affinity);
// Only on CI Server.
if (IS_CI_SERVER) {
await this.commandManager.executeCommand('notebook.selectKernel', {
id: this.id,
extension: JVSC_EXTENSION_ID
});
}
await this.commandManager.executeCommand('notebook.selectKernel', {
id: this.id,
extension: JVSC_EXTENSION_ID
});
}

// Handle the execution of notebook cell
Expand Down
8 changes: 2 additions & 6 deletions src/client/datascience/variablesView/notebookWatcher.ts
Expand Up @@ -69,15 +69,11 @@ export class NotebookWatcher implements INotebookWatcher {
this.notebookExtensibility.onKernelStateChange(this.kernelStateChanged, this, this.disposables);
this.notebookEditorProvider.onDidChangeActiveNotebookEditor(this.activeEditorChanged, this, this.disposables);
this.notebookEditorProvider.onDidCloseNotebookEditor(this.notebookEditorClosed, this, this.disposables);
notebook.onDidChangeNotebookCellExecutionState(
this.onDidChangeNotebookCellExecutionState,
this,
this.disposables
);
notebook.onDidChangeCellExecutionState(this.onDidChangeCellExecutionState, this, this.disposables);
}

// Handle when a cell finishes execution
private onDidChangeNotebookCellExecutionState(cellStateChange: NotebookCellExecutionStateChangeEvent): void {
private onDidChangeCellExecutionState(cellStateChange: NotebookCellExecutionStateChangeEvent): void {
// If a cell has moved to idle, update our state
if (cellStateChange.executionState === NotebookCellExecutionState.Idle) {
// Convert to the old KernelStateEventArgs format
Expand Down
4 changes: 2 additions & 2 deletions src/test/datascience/notebook/contentProvider.vscode.test.ts
Expand Up @@ -89,7 +89,7 @@ suite('DataScience - VSCode Notebook - (Open)', function () {

// We must have a default empty cell
assert.equal(notebookData.cells.length, 1);
assert.isEmpty(notebookData.cells[0].value);
assert.isEmpty(notebookData.cells[0].source);
});
test('Verify Notebook Json', async () => {
const storageProvider = api.serviceContainer.get<INotebookStorageProvider>(INotebookStorageProvider);
Expand Down Expand Up @@ -141,7 +141,7 @@ suite('DataScience - VSCode Notebook - (Open)', function () {
assert.deepEqual(notebook.cellAt(1).metadata.custom?.metadata.tags, ['WOW'], 'Cell2, metadata');

// Cell 3.
assert.equal(notebook.cellAt(2).kind, NotebookCellKind.Markup, 'Cell3, type');
assert.equal(notebook.cellAt(2).kind, NotebookCellKind.Markdown, 'Cell3, type');
assert.include(notebook.cellAt(2).document.getText(), '# HELLO WORLD', 'Cell3, source');
assert.lengthOf(notebook.cellAt(2).outputs, 0, 'Cell3, outputs');
assert.isUndefined(notebook.cellAt(2).latestExecutionSummary?.executionOrder, 'Cell3, execution count');
Expand Down
69 changes: 35 additions & 34 deletions src/test/datascience/notebook/contentProviderMain.vscode.test.ts
Expand Up @@ -14,8 +14,7 @@ import {
NotebookContentProvider as VSCodeNotebookContentProvider,
NotebookDocument,
NotebookCellMetadata,
CancellationTokenSource,
NotebookCellData
CancellationTokenSource
} from 'vscode';
import { IVSCodeNotebook } from '../../../client/common/application/types';
import { MARKDOWN_LANGUAGE, PYTHON_LANGUAGE } from '../../../client/common/constants';
Expand Down Expand Up @@ -79,31 +78,32 @@ suite('DataScience - VSCode Notebook ContentProvider', () => {
assert.isOk(notebook);

assert.deepEqual(notebook.cells, [
new NotebookCellData(
NotebookCellKind.Code,
'print(1)',
PYTHON_LANGUAGE,
[],
new NotebookCellMetadata().with({
{
kind: NotebookCellKind.Code,
language: PYTHON_LANGUAGE,
outputs: [],
source: 'print(1)',
metadata: new NotebookCellMetadata().with({
custom: {
metadata: {}
}
}),
{
latestExecutionSummary: {
executionOrder: 10
}
),
new NotebookCellData(
NotebookCellKind.Markup,
'# HEAD',
MARKDOWN_LANGUAGE,
[],
new NotebookCellMetadata().with({
},
{
kind: NotebookCellKind.Markdown,
language: MARKDOWN_LANGUAGE,
outputs: [],
source: '# HEAD',
metadata: new NotebookCellMetadata().with({
custom: {
metadata: {}
}
})
)
}),
latestExecutionSummary: undefined
}
]);
});

Expand Down Expand Up @@ -143,31 +143,32 @@ suite('DataScience - VSCode Notebook ContentProvider', () => {
assert.isOk(notebook);

assert.deepEqual(notebook.cells, [
new NotebookCellData(
NotebookCellKind.Code,
'Console.WriteLine("1")',
'csharp',
[],
new NotebookCellMetadata().with({
{
kind: NotebookCellKind.Code,
language: 'csharp',
outputs: [],
source: 'Console.WriteLine("1")',
metadata: new NotebookCellMetadata().with({
custom: {
metadata: {}
}
}),
{
latestExecutionSummary: {
executionOrder: 10
}
),
new NotebookCellData(
NotebookCellKind.Markup,
'# HEAD',
MARKDOWN_LANGUAGE,
[],
new NotebookCellMetadata().with({
},
{
kind: NotebookCellKind.Markdown,
language: MARKDOWN_LANGUAGE,
outputs: [],
source: '# HEAD',
metadata: new NotebookCellMetadata().with({
custom: {
metadata: {}
}
})
)
}),
latestExecutionSummary: undefined
}
]);
});
test('Verify mime types and order', () => {
Expand Down

0 comments on commit f043328

Please sign in to comment.