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

respond to latest api changes #1381

Merged
merged 3 commits into from
Jun 2, 2021
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
20 changes: 2 additions & 18 deletions src/dotnet-interactive-vscode/common/interfaces/vscode-like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ export const ErrorOutputMimeType = 'application/vnd.code.notebook.error';
export interface NotebookCellOutputItem {
readonly mime: string;
readonly data: Uint8Array;
readonly metadata?: { [key: string]: any };
[key: string]: any; // this is to make compilation on stable happy
}

export interface NotebookCellOutput {
id: string;
outputs: NotebookCellOutputItem[];
items: NotebookCellOutputItem[];
metadata?: { [key: string]: any };
}

Expand All @@ -30,21 +29,6 @@ export enum NotebookCellRunState {
Error = 4
}

export interface NotebookCellMetadata {
editable?: boolean,
breakpointMargin?: boolean,
runnable?: boolean,
hasExecutionOrder?: boolean,
executionOrder?: number,
runState?: NotebookCellRunState,
runStartTime?: number,
statusMessage?: string,
lastRunDuration?: number,
inputCollapsed?: boolean,
outputCollapsed?: boolean,
custom?: Record<string, any>,
}

export interface Uri {
fsPath: string;
scheme: string;
Expand Down Expand Up @@ -72,7 +56,7 @@ export interface NotebookCellData {
source: string;
language: string;
outputs: NotebookCellOutput[];
metadata?: NotebookCellMetadata;
metadata?: { [key: string]: any };
}

export interface NotebookDocumentBackup {
Expand Down
20 changes: 10 additions & 10 deletions src/dotnet-interactive-vscode/common/tests/unit/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('InteractiveClient tests', () => {
expect(decodedResults).to.deep.equal([
{
id: '1',
outputs: [
items: [
{
mime: 'text/plain',
decodedData: 'deferred output',
Expand All @@ -88,7 +88,7 @@ describe('InteractiveClient tests', () => {
},
{
id: '2',
outputs: [
items: [
{
mime: 'text/html',
decodedData: '2',
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('InteractiveClient tests', () => {
expect(decodedResults).to.deep.equal([
{
id: '1',
outputs: [
items: [
{
mime: 'text/plain',
decodedData: 'deferred output',
Expand All @@ -170,7 +170,7 @@ describe('InteractiveClient tests', () => {
},
{
id: '3',
outputs: [
items: [
{
mime: 'text/html',
decodedData: '2',
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('InteractiveClient tests', () => {
expect(decodedResults).to.deep.equal([
{
id: '1',
outputs: [
items: [
{
mime: 'text/plain',
decodedData: 'deferred output 1',
Expand All @@ -267,7 +267,7 @@ describe('InteractiveClient tests', () => {
},
{
id: '4',
outputs: [
items: [
{
mime: 'text/html',
decodedData: '2',
Expand All @@ -276,7 +276,7 @@ describe('InteractiveClient tests', () => {
},
{
id: '3',
outputs: [
items: [
{
mime: 'text/plain',
decodedData: 'deferred output 2',
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('InteractiveClient tests', () => {
expect(decodedResults1).to.deep.equal([
{
id: '1',
outputs: [
items: [
{
mime: 'text/html',
decodedData: '1',
Expand All @@ -361,7 +361,7 @@ describe('InteractiveClient tests', () => {
expect(decodedResults1).to.deep.equal([
{
id: '2',
outputs: [
items: [
{
mime: 'text/html',
decodedData: '2',
Expand Down Expand Up @@ -481,7 +481,7 @@ describe('InteractiveClient tests', () => {
const decodedOutputs = decodeNotebookCellOutputs(seenOutputs);
expect(decodedOutputs).to.deep.equal([{
id: '1',
outputs: [{
items: [{
mime: vscodeLike.ErrorOutputMimeType,
decodedData: {
name: 'Error',
Expand Down
14 changes: 7 additions & 7 deletions src/dotnet-interactive-vscode/common/tests/unit/notebook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Notebook tests', () => {
expect(decodedResults).to.deep.equal([
{
id: '1',
outputs: [
items: [
{
mime: 'text/html',
decodedData: '2',
Expand Down Expand Up @@ -164,7 +164,7 @@ Console.WriteLine(1);
expect(decodedResults).to.deep.equal([
{
id: '1',
outputs: [
items: [
{
mime: 'text/plain',
decodedData: '1\r\n',
Expand All @@ -173,7 +173,7 @@ Console.WriteLine(1);
},
{
id: '2',
outputs: [
items: [
{
mime: 'text/plain',
decodedData: '2\r\n',
Expand All @@ -182,7 +182,7 @@ Console.WriteLine(1);
},
{
id: '3',
outputs: [
items: [
{
mime: 'text/plain',
decodedData: '3\r\n',
Expand Down Expand Up @@ -260,7 +260,7 @@ Console.WriteLine(1);
expect(decodedResults).to.deep.equal([
{
id: '2',
outputs: [
items: [
{
mime: 'text/plain',
decodedData: 'Installed package Newtonsoft.Json version 1.2.3.4',
Expand All @@ -269,7 +269,7 @@ Console.WriteLine(1);
},
{
id: '3',
outputs: [
items: [
{
mime: 'text/plain',
decodedData: 'sentinel',
Expand Down Expand Up @@ -326,7 +326,7 @@ Console.WriteLine(1);
expect(decodedResults).to.deep.equal([
{
id: '1',
outputs: [
items: [
{
mime: 'application/json',
decodedData: {
Expand Down
10 changes: 5 additions & 5 deletions src/dotnet-interactive-vscode/common/tests/unit/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ export function decodeToString(data: Uint8Array): string {
}

export function decodeNotebookCellOutputs(outputs: vscodeLike.NotebookCellOutput[]): any[] {
const jsonLikeMimes = new Set<string>();
jsonLikeMimes.add('application/json');
jsonLikeMimes.add(vscodeLike.ErrorOutputMimeType);
const jsonLikeMimeTypes = new Set<string>();
jsonLikeMimeTypes.add('application/json');
jsonLikeMimeTypes.add(vscodeLike.ErrorOutputMimeType);
return outputs.map(o => ({
...o, outputs: o.outputs.map(oi => {
...o, items: o.items.map(oi => {
const decoded = decodeToString(oi.data);
let result = <any>{
...oi,
decodedData: jsonLikeMimes.has(oi.mime) ? JSON.parse(decoded) : decoded,
decodedData: jsonLikeMimeTypes.has(oi.mime) ? JSON.parse(decoded) : decoded,
};
delete result.data;
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet-interactive-vscode/common/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function createOutput(outputItems: Array<NotebookCellOutputItem>, outputI

const output: NotebookCellOutput = {
id: outputId,
outputs: outputItems,
items: outputItems,
};
return output;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet-interactive-vscode/common/vscode/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function registerKernelCommands(context: vscode.ExtensionContext, clientM
}));

context.subscriptions.push(vscode.commands.registerCommand('dotnet-interactive.stopAllNotebookKernels', async () => {
vscode.notebook.notebookDocuments
versionSpecificFunctions.notebookDocuments
.filter(document => clientMapper.isDotNetClient(document.uri))
.forEach(async document => await vscode.commands.executeCommand('dotnet-interactive.stopCurrentNotebookKernel', document));
}));
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-interactive-vscode/common/vscode/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export async function activate(context: vscode.ExtensionContext) {

registerFileCommands(context, clientMapper);

context.subscriptions.push(vscode.notebook.onDidCloseNotebookDocument(notebookDocument => clientMapper.closeClient(notebookDocument.uri)));
context.subscriptions.push(versionSpecificFunctions.onDidCloseNotebookDocument(notebookDocument => clientMapper.closeClient(notebookDocument.uri)));
context.subscriptions.push(vscode.workspace.onDidRenameFiles(e => handleFileRenames(e, clientMapper)));

// language registration
Expand Down Expand Up @@ -205,7 +205,7 @@ async function waitForSdkInstall(requiredSdkVersion: string): Promise<void> {
async function updateNotebookCellLanguageInMetadata(candidateNotebookCellDocument: vscode.TextDocument) {
const notebook = candidateNotebookCellDocument.notebook;
if (notebook &&
isJupyterNotebookViewType(notebook.viewType) &&
isJupyterNotebookViewType(versionSpecificFunctions.getNotebookType(notebook)) &&
isDotnetInteractiveLanguage(candidateNotebookCellDocument.languageId)) {
const cell = notebook.getCells().find(c => c.document === candidateNotebookCellDocument);
if (cell) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Diagnostic, DiagnosticSeverity, LinePosition, LinePositionSpan, Noteboo

import { getSimpleLanguage } from '../interactiveNotebook';
import * as vscodeLike from '../interfaces/vscode-like';
import * as versionSpecificFunctions from '../../versionSpecificFunctions';

export function isInsidersBuild(): boolean {
return vscode.version.indexOf('-insider') >= 0;
Expand Down Expand Up @@ -88,7 +89,8 @@ export function toNotebookCell(cell: vscode.NotebookCell): NotebookCell {
}

export function vsCodeCellOutputToContractCellOutput(output: vscode.NotebookCellOutput): NotebookCellOutput {
const errorOutputItems = output.outputs.filter(oi => oi.mime === vscodeLike.ErrorOutputMimeType || oi.metadata?.mimeType === vscodeLike.ErrorOutputMimeType);
const outputItems = versionSpecificFunctions.getCellOutputItems(output);
const errorOutputItems = outputItems.filter(oi => oi.mime === vscodeLike.ErrorOutputMimeType);
if (errorOutputItems.length > 0) {
// any error-like output takes precedence
const errorOutputItem = errorOutputItems[0];
Expand All @@ -101,7 +103,7 @@ export function vsCodeCellOutputToContractCellOutput(output: vscode.NotebookCell
} else {
//otherwise build the mime=>value dictionary
const data: { [key: string]: any } = {};
for (const outputItem of output.outputs) {
for (const outputItem of outputItems) {
data[outputItem.mime] = outputItem.data;
}

Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-interactive-vscode/insiders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"contributes": {
"notebooks": [
{
"viewType": "dotnet-interactive",
"type": "dotnet-interactive",
"displayName": ".NET Interactive Notebook",
"selector": [
{
Expand All @@ -71,7 +71,7 @@
]
},
{
"viewType": "dotnet-interactive-legacy",
"type": "dotnet-interactive-legacy",
"displayName": ".NET Interactive Notebook",
"selector": [
{
Expand Down
24 changes: 12 additions & 12 deletions src/dotnet-interactive-vscode/insiders/src/notebookControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class DotNetNotebookKernel {
const preloads = config.preloadUris.map(uri => new vscode.NotebookRendererScript(uri));

// .dib execution
const dibController = vscode.notebook.createNotebookController(
const dibController = vscode.notebooks.createNotebookController(
'dotnet-interactive',
viewType,
'.NET Interactive',
Expand All @@ -43,7 +43,7 @@ export class DotNetNotebookKernel {
this.commonControllerInit(dibController);

// .dotnet-interactive execution
const legacyController = vscode.notebook.createNotebookController(
const legacyController = vscode.notebooks.createNotebookController(
'dotnet-interactive-legacy',
legacyViewType,
'.NET Interactive',
Expand All @@ -53,7 +53,7 @@ export class DotNetNotebookKernel {
this.commonControllerInit(legacyController);

// .ipynb execution via Jupyter extension (optional)
const jupyterController = vscode.notebook.createNotebookController(
const jupyterController = vscode.notebooks.createNotebookController(
'dotnet-interactive-for-jupyter',
jupyterViewType,
'.NET Interactive',
Expand All @@ -67,8 +67,8 @@ export class DotNetNotebookKernel {
}
});
this.commonControllerInit(jupyterController);
this.disposables.push(vscode.notebook.onDidOpenNotebookDocument(async notebook => {
if (notebook.viewType === jupyterViewType && isDotNetNotebook(notebook)) {
this.disposables.push(vscode.notebooks.onDidOpenNotebookDocument(async notebook => {
brettfo marked this conversation as resolved.
Show resolved Hide resolved
if (notebook.notebookType === jupyterViewType && isDotNetNotebook(notebook)) {
jupyterController.updateNotebookAffinity(notebook, vscode.NotebookControllerAffinity.Preferred);
await selectDotNetInteractiveKernelForJupyter();
await updateNotebookMetadata(notebook, this.config.clientMapper);
Expand Down Expand Up @@ -119,19 +119,19 @@ export class DotNetNotebookKernel {
});


executionTask.clearOutput(cell.index);
executionTask.clearOutput(cell);
const client = await this.config.clientMapper.getOrAddClient(cell.notebook.uri);
executionTask.token.onCancellationRequested(() => {
const errorOutput = this.config.createErrorOutput("Cell execution cancelled by user");
const resultPromise = () => updateCellOutputs(executionTask, cell, [...cell.outputs, errorOutput])
const resultPromise = () => updateCellOutputs(executionTask, [...cell.outputs, errorOutput])
.then(() => endExecution(cell, false));
client.cancel()
.then(resultPromise)
.catch(resultPromise);
});
const source = cell.document.getText();
function outputObserver(outputs: Array<vscodeLike.NotebookCellOutput>) {
updateCellOutputs(executionTask!, cell, outputs).then(() => { });
updateCellOutputs(executionTask!, outputs).then(() => { });
}

const diagnosticCollection = diagnostics.getDiagnosticCollection(cell.document.uri);
Expand All @@ -145,7 +145,7 @@ export class DotNetNotebookKernel {
).catch(() => endExecution(cell, false));
} catch (err) {
const errorOutput = this.config.createErrorOutput(`Error executing cell: ${err}`);
await updateCellOutputs(executionTask, cell, [errorOutput]);
await updateCellOutputs(executionTask, [errorOutput]);
endExecution(cell, false);
throw err;
}
Expand Down Expand Up @@ -193,9 +193,9 @@ export async function updateCellLanguages(document: vscode.NotebookDocument): Pr
await vscode.workspace.applyEdit(edit);
}

async function updateCellOutputs(executionTask: vscode.NotebookCellExecution, cell: vscode.NotebookCell, outputs: Array<vscodeLike.NotebookCellOutput>): Promise<void> {
const reshapedOutputs = outputs.map(o => new vscode.NotebookCellOutput(o.outputs.map(oi => generateVsCodeNotebookCellOutputItem(oi.data, oi.mime))));
await executionTask.replaceOutput(reshapedOutputs, cell.index);
async function updateCellOutputs(executionTask: vscode.NotebookCellExecution, outputs: Array<vscodeLike.NotebookCellOutput>): Promise<void> {
const reshapedOutputs = outputs.map(o => new vscode.NotebookCellOutput(o.items.map(oi => generateVsCodeNotebookCellOutputItem(oi.data, oi.mime))));
await executionTask.replaceOutput(reshapedOutputs);
}

export function endExecution(cell: vscode.NotebookCell, success: boolean) {
Expand Down
Loading