mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 11:10:48 +00:00
parent
8454701b67
commit
bcb8c8a4f4
12 changed files with 128 additions and 147 deletions
|
@ -48,17 +48,104 @@ async function saveAllFilesAndCloseAll(resource: vscode.Uri | undefined) {
|
|||
await documentClosed;
|
||||
}
|
||||
|
||||
async function updateNotebookMetadata(uri: vscode.Uri, newMetadata: vscode.NotebookDocumentMetadata) {
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.replaceNotebookMetadata(uri, newMetadata);
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
}
|
||||
|
||||
async function withEvent<T>(event: vscode.Event<T>, callback: (e: Promise<T>) => Promise<void>) {
|
||||
const e = asPromise<T>(event);
|
||||
await callback(e);
|
||||
}
|
||||
|
||||
const kernel1: vscode.NotebookKernel = {
|
||||
id: 'mainKernel',
|
||||
label: 'Notebook Test Kernel',
|
||||
isPreferred: true,
|
||||
supportedLanguages: ['typescript', 'javascript'],
|
||||
executeAllCells: async (_document: vscode.NotebookDocument) => {
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
|
||||
edit.replaceNotebookCellOutput(_document.uri, 0, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/plain', ['my output'], undefined)
|
||||
])]);
|
||||
return vscode.workspace.applyEdit(edit);
|
||||
},
|
||||
cancelAllCellsExecution: async (_document: vscode.NotebookDocument) => { },
|
||||
executeCell: async (document: vscode.NotebookDocument, cell: vscode.NotebookCell | undefined) => {
|
||||
if (!cell) {
|
||||
cell = document.cells[0];
|
||||
}
|
||||
|
||||
if (document.uri.path.endsWith('customRenderer.vsctestnb')) {
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/custom', ['test'], undefined)
|
||||
])]);
|
||||
|
||||
return vscode.workspace.applyEdit(edit);
|
||||
}
|
||||
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
// const previousOutputs = cell.outputs;
|
||||
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/plain', ['my output'], undefined)
|
||||
])]);
|
||||
|
||||
return vscode.workspace.applyEdit(edit);
|
||||
},
|
||||
cancelCellExecution: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell) => { }
|
||||
};
|
||||
|
||||
const kernel2: vscode.NotebookKernel = {
|
||||
id: 'secondaryKernel',
|
||||
label: 'Notebook Secondary Test Kernel',
|
||||
isPreferred: false,
|
||||
supportedLanguages: ['typescript', 'javascript'],
|
||||
executeAllCells: async (_document: vscode.NotebookDocument) => {
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.replaceNotebookCellOutput(_document.uri, 0, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/plain', ['my second output'], undefined)
|
||||
])]);
|
||||
|
||||
return vscode.workspace.applyEdit(edit);
|
||||
},
|
||||
cancelAllCellsExecution: async (_document: vscode.NotebookDocument) => { },
|
||||
executeCell: async (document: vscode.NotebookDocument, cell: vscode.NotebookCell | undefined) => {
|
||||
if (!cell) {
|
||||
cell = document.cells[0];
|
||||
}
|
||||
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
|
||||
if (document.uri.path.endsWith('customRenderer.vsctestnb')) {
|
||||
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/custom', ['test 2'], undefined)
|
||||
])]);
|
||||
} else {
|
||||
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/plain', ['my second output'], undefined)
|
||||
])]);
|
||||
}
|
||||
|
||||
return vscode.workspace.applyEdit(edit);
|
||||
},
|
||||
cancelCellExecution: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell) => { }
|
||||
};
|
||||
|
||||
class KernelProvider implements vscode.NotebookKernelProvider {
|
||||
private _onDidChangeKernels = new vscode.EventEmitter<undefined>();
|
||||
onDidChangeKernels = this._onDidChangeKernels.event;
|
||||
|
||||
private _hasKernels = true;
|
||||
private readonly _kernels = [kernel1, kernel2];
|
||||
|
||||
provideKernels(): vscode.ProviderResult<vscode.NotebookKernel[]> {
|
||||
return this._hasKernels ? this._kernels : [];
|
||||
}
|
||||
|
||||
setHasKernels(hasKernels: boolean): void {
|
||||
this._hasKernels = hasKernels;
|
||||
this._onDidChangeKernels.fire(undefined);
|
||||
}
|
||||
}
|
||||
let currentKernerProvider: KernelProvider;
|
||||
|
||||
suite('Notebook API tests', function () {
|
||||
|
||||
const disposables: vscode.Disposable[] = [];
|
||||
|
@ -127,87 +214,8 @@ suite('Notebook API tests', function () {
|
|||
}
|
||||
}));
|
||||
|
||||
|
||||
const kernel: vscode.NotebookKernel = {
|
||||
id: 'mainKernel',
|
||||
label: 'Notebook Test Kernel',
|
||||
isPreferred: true,
|
||||
supportedLanguages: ['typescript', 'javascript'],
|
||||
executeAllCells: async (_document: vscode.NotebookDocument) => {
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
|
||||
edit.replaceNotebookCellOutput(_document.uri, 0, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/plain', ['my output'], undefined)
|
||||
])]);
|
||||
return vscode.workspace.applyEdit(edit);
|
||||
},
|
||||
cancelAllCellsExecution: async (_document: vscode.NotebookDocument) => { },
|
||||
executeCell: async (document: vscode.NotebookDocument, cell: vscode.NotebookCell | undefined) => {
|
||||
if (!cell) {
|
||||
cell = document.cells[0];
|
||||
}
|
||||
|
||||
if (document.uri.path.endsWith('customRenderer.vsctestnb')) {
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/custom', ['test'], undefined)
|
||||
])]);
|
||||
|
||||
return vscode.workspace.applyEdit(edit);
|
||||
}
|
||||
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
// const previousOutputs = cell.outputs;
|
||||
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/plain', ['my output'], undefined)
|
||||
])]);
|
||||
|
||||
return vscode.workspace.applyEdit(edit);
|
||||
},
|
||||
cancelCellExecution: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell) => { }
|
||||
};
|
||||
|
||||
const kernel2: vscode.NotebookKernel = {
|
||||
id: 'secondaryKernel',
|
||||
label: 'Notebook Secondary Test Kernel',
|
||||
isPreferred: false,
|
||||
supportedLanguages: ['typescript', 'javascript'],
|
||||
executeAllCells: async (_document: vscode.NotebookDocument) => {
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.replaceNotebookCellOutput(_document.uri, 0, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/plain', ['my second output'], undefined)
|
||||
])]);
|
||||
|
||||
return vscode.workspace.applyEdit(edit);
|
||||
},
|
||||
cancelAllCellsExecution: async (_document: vscode.NotebookDocument) => { },
|
||||
executeCell: async (document: vscode.NotebookDocument, cell: vscode.NotebookCell | undefined) => {
|
||||
if (!cell) {
|
||||
cell = document.cells[0];
|
||||
}
|
||||
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
|
||||
if (document.uri.path.endsWith('customRenderer.vsctestnb')) {
|
||||
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/custom', ['test 2'], undefined)
|
||||
])]);
|
||||
} else {
|
||||
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
|
||||
new vscode.NotebookCellOutputItem('text/plain', ['my second output'], undefined)
|
||||
])]);
|
||||
}
|
||||
|
||||
return vscode.workspace.applyEdit(edit);
|
||||
},
|
||||
cancelCellExecution: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell) => { }
|
||||
};
|
||||
|
||||
disposables.push(vscode.notebook.registerNotebookKernelProvider({ filenamePattern: '*.vsctestnb' }, {
|
||||
provideKernels: async () => {
|
||||
return [kernel, kernel2];
|
||||
}
|
||||
}));
|
||||
currentKernerProvider = new KernelProvider();
|
||||
disposables.push(vscode.notebook.registerNotebookKernelProvider({ filenamePattern: '*.vsctestnb' }, currentKernerProvider));
|
||||
});
|
||||
|
||||
test('shared document in notebook editors', async function () {
|
||||
|
@ -657,7 +665,7 @@ suite('Notebook API tests', function () {
|
|||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
|
||||
test('document runnable metadata is respected', async () => {
|
||||
test('document runnable based on kernel count', async () => {
|
||||
const resource = await createRandomFile('', undefined, '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
|
@ -666,18 +674,11 @@ suite('Notebook API tests', function () {
|
|||
const cell = editor.document.cells[0];
|
||||
assert.strictEqual(cell.outputs.length, 0);
|
||||
|
||||
await withEvent(vscode.notebook.onDidChangeNotebookDocumentMetadata, async event => {
|
||||
updateNotebookMetadata(editor.document.uri, editor.document.metadata.with({ runnable: false }));
|
||||
await event;
|
||||
});
|
||||
|
||||
currentKernerProvider.setHasKernels(false);
|
||||
await vscode.commands.executeCommand('notebook.execute');
|
||||
assert.strictEqual(cell.outputs.length, 0, 'should not execute'); // not runnable, didn't work
|
||||
|
||||
await withEvent(vscode.notebook.onDidChangeNotebookDocumentMetadata, async event => {
|
||||
updateNotebookMetadata(editor.document.uri, editor.document.metadata.with({ runnable: true }));
|
||||
await event;
|
||||
});
|
||||
currentKernerProvider.setHasKernels(true);
|
||||
|
||||
await withEvent<vscode.NotebookCellOutputsChangeEvent>(vscode.notebook.onDidChangeCellOutputs, async (event) => {
|
||||
await vscode.commands.executeCommand('notebook.execute');
|
||||
|
@ -710,11 +711,6 @@ suite('Notebook API tests', function () {
|
|||
const editor = vscode.window.activeNotebookEditor!;
|
||||
const cell = editor.document.cells[0];
|
||||
|
||||
await withEvent(vscode.notebook.onDidChangeNotebookDocumentMetadata, async event => {
|
||||
updateNotebookMetadata(editor.document.uri, editor.document.metadata.with({ runnable: true }));
|
||||
await event;
|
||||
});
|
||||
|
||||
await withEvent(vscode.notebook.onDidChangeCellOutputs, async (event) => {
|
||||
await vscode.commands.executeCommand('notebook.execute');
|
||||
await event;
|
||||
|
@ -747,11 +743,6 @@ suite('Notebook API tests', function () {
|
|||
const editor = vscode.window.activeNotebookEditor!;
|
||||
const cell = editor.document.cells[0];
|
||||
|
||||
const metadataChangeEvent = asPromise<vscode.NotebookDocumentMetadataChangeEvent>(vscode.notebook.onDidChangeNotebookDocumentMetadata);
|
||||
updateNotebookMetadata(editor.document.uri, editor.document.metadata.with({ runnable: true }));
|
||||
await metadataChangeEvent;
|
||||
assert.strictEqual(editor.document.metadata.runnable, true);
|
||||
|
||||
await withEvent<vscode.NotebookCellOutputsChangeEvent>(vscode.notebook.onDidChangeCellOutputs, async (event) => {
|
||||
await vscode.commands.executeCommand('notebook.execute');
|
||||
await event;
|
||||
|
@ -783,10 +774,6 @@ suite('Notebook API tests', function () {
|
|||
const editor = vscode.window.activeNotebookEditor!;
|
||||
const cell = editor.document.cells[0];
|
||||
|
||||
const metadataChangeEvent = asPromise<vscode.NotebookDocumentMetadataChangeEvent>(vscode.notebook.onDidChangeNotebookDocumentMetadata);
|
||||
updateNotebookMetadata(editor.document.uri, editor.document.metadata.with({ runnable: true }));
|
||||
await metadataChangeEvent;
|
||||
|
||||
await vscode.commands.executeCommand('notebook.cell.execute');
|
||||
assert.strictEqual(cell.outputs.length, 1, 'should execute'); // runnable, it worked
|
||||
assert.strictEqual(cell.outputs[0].outputs.length, 1);
|
||||
|
|
7
src/vs/vscode.proposed.d.ts
vendored
7
src/vs/vscode.proposed.d.ts
vendored
|
@ -1170,15 +1170,12 @@ declare module 'vscode' {
|
|||
// todo@API is this a kernel property?
|
||||
readonly cellHasExecutionOrder: boolean;
|
||||
|
||||
// run related, remove infer from kernel, exec
|
||||
// todo@API infer from kernel
|
||||
// todo@API remove
|
||||
readonly runnable: boolean;
|
||||
readonly runState: NotebookRunState;
|
||||
|
||||
constructor(editable?: boolean, runnable?: boolean, cellEditable?: boolean, cellHasExecutionOrder?: boolean, custom?: { [key: string]: any; }, runState?: NotebookRunState, trusted?: boolean);
|
||||
constructor(editable?: boolean, cellEditable?: boolean, cellHasExecutionOrder?: boolean, custom?: { [key: string]: any; }, runState?: NotebookRunState, trusted?: boolean);
|
||||
|
||||
with(change: { editable?: boolean | null, runnable?: boolean | null, cellEditable?: boolean | null, cellHasExecutionOrder?: boolean | null, custom?: { [key: string]: any; } | null, runState?: NotebookRunState | null, trusted?: boolean | null, }): NotebookDocumentMetadata
|
||||
with(change: { editable?: boolean | null, cellEditable?: boolean | null, cellHasExecutionOrder?: boolean | null, custom?: { [key: string]: any; } | null, runState?: NotebookRunState | null, trusted?: boolean | null, }): NotebookDocumentMetadata
|
||||
}
|
||||
|
||||
export interface NotebookDocumentContentOptions {
|
||||
|
|
|
@ -1431,7 +1431,7 @@ export namespace NotebookDocumentMetadata {
|
|||
}
|
||||
|
||||
export function to(data: notebooks.NotebookDocumentMetadata): types.NotebookDocumentMetadata {
|
||||
return new types.NotebookDocumentMetadata(data.editable, data.runnable, data.cellEditable, data.cellHasExecutionOrder, data.custom, data.runState, data.trusted);
|
||||
return new types.NotebookDocumentMetadata(data.editable, data.cellEditable, data.cellHasExecutionOrder, data.custom, data.runState, data.trusted);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3047,7 +3047,6 @@ export class NotebookDocumentMetadata {
|
|||
|
||||
constructor(
|
||||
readonly editable: boolean = true,
|
||||
readonly runnable: boolean = true,
|
||||
readonly cellEditable: boolean = true,
|
||||
readonly cellHasExecutionOrder: boolean = true,
|
||||
readonly custom: { [key: string]: any; } = {},
|
||||
|
@ -3057,7 +3056,6 @@ export class NotebookDocumentMetadata {
|
|||
|
||||
with(change: {
|
||||
editable?: boolean | null,
|
||||
runnable?: boolean | null,
|
||||
cellEditable?: boolean | null,
|
||||
cellHasExecutionOrder?: boolean | null,
|
||||
custom?: { [key: string]: any; } | null,
|
||||
|
@ -3065,18 +3063,13 @@ export class NotebookDocumentMetadata {
|
|||
trusted?: boolean | null,
|
||||
}): NotebookDocumentMetadata {
|
||||
|
||||
let { editable, runnable, cellEditable, cellHasExecutionOrder, custom, runState, trusted } = change;
|
||||
let { editable, cellEditable, cellHasExecutionOrder, custom, runState, trusted } = change;
|
||||
|
||||
if (editable === undefined) {
|
||||
editable = this.editable;
|
||||
} else if (editable === null) {
|
||||
editable = undefined;
|
||||
}
|
||||
if (runnable === undefined) {
|
||||
runnable = this.runnable;
|
||||
} else if (runnable === null) {
|
||||
runnable = undefined;
|
||||
}
|
||||
if (cellEditable === undefined) {
|
||||
cellEditable = this.cellEditable;
|
||||
} else if (cellEditable === null) {
|
||||
|
@ -3104,7 +3097,6 @@ export class NotebookDocumentMetadata {
|
|||
}
|
||||
|
||||
if (editable === this.editable &&
|
||||
runnable === this.runnable &&
|
||||
cellEditable === this.cellEditable &&
|
||||
cellHasExecutionOrder === this.cellHasExecutionOrder &&
|
||||
custom === this.custom &&
|
||||
|
@ -3117,7 +3109,6 @@ export class NotebookDocumentMetadata {
|
|||
|
||||
return new NotebookDocumentMetadata(
|
||||
editable,
|
||||
runnable,
|
||||
cellEditable,
|
||||
cellHasExecutionOrder,
|
||||
custom,
|
||||
|
|
|
@ -94,7 +94,6 @@ class NotebookClipboardContribution extends Disposable {
|
|||
const cloneMetadata = (cell: NotebookCellTextModel) => {
|
||||
return {
|
||||
editable: cell.metadata?.editable,
|
||||
runnable: cell.metadata?.runnable,
|
||||
breakpointMargin: cell.metadata?.breakpointMargin,
|
||||
hasExecutionOrder: cell.metadata?.hasExecutionOrder,
|
||||
inputCollapsed: cell.metadata?.inputCollapsed,
|
||||
|
|
|
@ -21,7 +21,7 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation
|
|||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
|
||||
import { CATEGORIES } from 'vs/workbench/common/actions';
|
||||
import { BaseCellRenderTemplate, CellEditState, CellFocusMode, EXECUTE_CELL_COMMAND_ID, EXPAND_CELL_CONTENT_COMMAND_ID, getNotebookEditorFromEditorPane, IActiveNotebookEditor, ICellViewModel, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_EDITOR_FOCUSED, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_INPUT_COLLAPSED, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_OUTPUT_COLLAPSED, NOTEBOOK_CELL_RUN_STATE, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_OUTPUT_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { BaseCellRenderTemplate, CellEditState, CellFocusMode, EXECUTE_CELL_COMMAND_ID, EXPAND_CELL_CONTENT_COMMAND_ID, getNotebookEditorFromEditorPane, IActiveNotebookEditor, ICellViewModel, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_EDITOR_FOCUSED, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_INPUT_COLLAPSED, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_OUTPUT_COLLAPSED, NOTEBOOK_CELL_RUN_STATE, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_OUTPUT_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
|
||||
import { CellEditType, CellKind, ICellEditOperation, ICellRange, INotebookDocumentFilter, isDocumentExcludePattern, NotebookCellMetadata, NotebookCellRunState, NOTEBOOK_EDITOR_CURSOR_BEGIN_END, NOTEBOOK_EDITOR_CURSOR_BOUNDARY, TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
|
||||
|
@ -258,6 +258,8 @@ const executeCellCondition = ContextKeyExpr.or(
|
|||
ContextKeyExpr.greater(NOTEBOOK_KERNEL_COUNT.key, 0)),
|
||||
NOTEBOOK_CELL_TYPE.isEqualTo('markdown'));
|
||||
|
||||
const executeNotebookCondition = ContextKeyExpr.greater(NOTEBOOK_KERNEL_COUNT.key, 0);
|
||||
|
||||
registerAction2(class ExecuteCell extends NotebookCellAction<ICellRange> {
|
||||
constructor() {
|
||||
super({
|
||||
|
@ -630,7 +632,7 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
|
|||
},
|
||||
order: -1,
|
||||
group: 'navigation',
|
||||
when: ContextKeyExpr.and(NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK.toNegated(), NOTEBOOK_EDITOR_RUNNABLE)
|
||||
when: ContextKeyExpr.and(NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK.toNegated(), executeNotebookCondition)
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
|
||||
|
@ -1514,7 +1516,7 @@ registerAction2(class extends NotebookCellAction {
|
|||
title: localize('clearCellOutputs', 'Clear Cell Outputs'),
|
||||
menu: {
|
||||
id: MenuId.NotebookCellTitle,
|
||||
when: ContextKeyExpr.and(NOTEBOOK_CELL_TYPE.isEqualTo('code'), NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_CELL_EDITABLE),
|
||||
when: ContextKeyExpr.and(NOTEBOOK_CELL_TYPE.isEqualTo('code'), executeNotebookCondition, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_CELL_EDITABLE),
|
||||
order: CellToolbarOrder.ClearCellOutput,
|
||||
group: CELL_TITLE_OUTPUT_GROUP_ID
|
||||
},
|
||||
|
|
|
@ -43,7 +43,6 @@ export const NOTEBOOK_EDITOR_OPEN = new RawContextKey<boolean>('notebookEditorOp
|
|||
export const NOTEBOOK_CELL_LIST_FOCUSED = new RawContextKey<boolean>('notebookCellListFocused', false);
|
||||
export const NOTEBOOK_OUTPUT_FOCUSED = new RawContextKey<boolean>('notebookOutputFocused', false);
|
||||
export const NOTEBOOK_EDITOR_EDITABLE = new RawContextKey<boolean>('notebookEditable', true);
|
||||
export const NOTEBOOK_EDITOR_RUNNABLE = new RawContextKey<boolean>('notebookRunnable', true);
|
||||
export const NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK = new RawContextKey<boolean>('notebookExecuting', false);
|
||||
|
||||
// Diff Editor Keys
|
||||
|
|
|
@ -15,7 +15,7 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
|
|||
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
|
||||
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
|
||||
import { Memento } from 'vs/workbench/common/memento';
|
||||
import { ICellViewModel, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_HAS_MULTIPLE_KERNELS, NOTEBOOK_KERNEL_COUNT } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { ICellViewModel, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_HAS_MULTIPLE_KERNELS, NOTEBOOK_KERNEL_COUNT } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { configureKernelIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons';
|
||||
import { NotebookKernelProviderAssociation, NotebookKernelProviderAssociations, notebookKernelProviderAssociationsSettingId } from 'vs/workbench/contrib/notebook/browser/notebookKernelAssociation';
|
||||
import { NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
|
||||
|
@ -46,7 +46,6 @@ export class NotebookEditorKernelManager extends Disposable {
|
|||
private _contributedKernelsComputePromise: CancelablePromise<INotebookKernel[]> | null = null;
|
||||
private _initialKernelComputationDone: boolean = false;
|
||||
|
||||
private readonly _editorRunnable: IContextKey<boolean>;
|
||||
private readonly _notebookExecuting: IContextKey<boolean>;
|
||||
private readonly _notebookHasMultipleKernels: IContextKey<boolean>;
|
||||
private readonly _notebookKernelCount: IContextKey<number>;
|
||||
|
@ -105,7 +104,6 @@ export class NotebookEditorKernelManager extends Disposable {
|
|||
|
||||
this._activeKernelMemento = new Memento(NotebookEditorActiveKernelCache, storageService);
|
||||
|
||||
this._editorRunnable = NOTEBOOK_EDITOR_RUNNABLE.bindTo(contextKeyService);
|
||||
this._notebookExecuting = NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK.bindTo(contextKeyService);
|
||||
this._notebookHasMultipleKernels = NOTEBOOK_HAS_MULTIPLE_KERNELS.bindTo(contextKeyService);
|
||||
this._notebookKernelCount = NOTEBOOK_KERNEL_COUNT.bindTo(contextKeyService);
|
||||
|
@ -175,7 +173,6 @@ export class NotebookEditorKernelManager extends Disposable {
|
|||
}
|
||||
|
||||
const notebookMetadata = this._delegate.viewModel.metadata;
|
||||
this._editorRunnable.set(this._delegate.viewModel.runnable);
|
||||
this._notebookExecuting.set(notebookMetadata.runState === NotebookRunState.Running);
|
||||
}
|
||||
|
||||
|
@ -382,11 +379,11 @@ export class NotebookEditorKernelManager extends Disposable {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!this._delegate.viewModel.runnable) {
|
||||
await this._ensureActiveKernel();
|
||||
if (!this.canExecuteNotebook()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this._ensureActiveKernel();
|
||||
this._activeKernelExecuted = true;
|
||||
await this._activeKernel?.executeNotebookCell!(this._delegate.viewModel.uri, undefined);
|
||||
}
|
||||
|
@ -414,15 +411,27 @@ export class NotebookEditorKernelManager extends Disposable {
|
|||
return;
|
||||
}
|
||||
|
||||
await this._ensureActiveKernel();
|
||||
if (!this.canExecuteCell(cell)) {
|
||||
throw new Error('Cell is not executable: ' + cell.uri);
|
||||
}
|
||||
|
||||
await this._ensureActiveKernel();
|
||||
this._activeKernelExecuted = true;
|
||||
await this._activeKernel?.executeNotebookCell!(this._delegate.viewModel.uri, cell.handle);
|
||||
}
|
||||
|
||||
private canExecuteNotebook(): boolean {
|
||||
if (!this.activeKernel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this._delegate.viewModel?.trusted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private canExecuteCell(cell: ICellViewModel): boolean {
|
||||
if (!this.activeKernel) {
|
||||
return false;
|
||||
|
|
|
@ -164,8 +164,8 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
|
|||
return this._notebook.metadata;
|
||||
}
|
||||
|
||||
get runnable() {
|
||||
return !!this._notebook.metadata?.runnable && !!this._notebook.metadata?.trusted;
|
||||
get trusted() {
|
||||
return !!this._notebook.metadata?.trusted;
|
||||
}
|
||||
|
||||
private readonly _onDidChangeViewCells = this._register(new Emitter<INotebookViewCellsUpdateEvent>());
|
||||
|
|
|
@ -60,7 +60,6 @@ export enum NotebookRunState {
|
|||
|
||||
export const notebookDocumentMetadataDefaults: Required<NotebookDocumentMetadata> = {
|
||||
editable: true,
|
||||
runnable: true,
|
||||
cellEditable: true,
|
||||
cellHasExecutionOrder: true,
|
||||
custom: {},
|
||||
|
@ -70,7 +69,6 @@ export const notebookDocumentMetadataDefaults: Required<NotebookDocumentMetadata
|
|||
|
||||
export interface NotebookDocumentMetadata {
|
||||
editable: boolean;
|
||||
runnable: boolean;
|
||||
cellEditable: boolean;
|
||||
cellHasExecutionOrder: boolean;
|
||||
custom?: { [key: string]: unknown };
|
||||
|
|
|
@ -144,7 +144,7 @@ suite('NotebookViewModel', () => {
|
|||
['var e = 5;', 'javascript', CellKind.Code, [], { editable: false }],
|
||||
],
|
||||
(editor, viewModel) => {
|
||||
viewModel.notebookDocument.metadata = { editable: true, runnable: true, cellEditable: true, cellHasExecutionOrder: true, trusted: true };
|
||||
viewModel.notebookDocument.metadata = { editable: true, cellEditable: true, cellHasExecutionOrder: true, trusted: true };
|
||||
|
||||
const defaults = { hasExecutionOrder: true };
|
||||
|
||||
|
@ -173,7 +173,7 @@ suite('NotebookViewModel', () => {
|
|||
...defaults
|
||||
});
|
||||
|
||||
viewModel.notebookDocument.metadata = { editable: true, runnable: true, cellEditable: true, cellHasExecutionOrder: true, trusted: true };
|
||||
viewModel.notebookDocument.metadata = { editable: true, cellEditable: true, cellHasExecutionOrder: true, trusted: true };
|
||||
|
||||
assert.deepEqual(viewModel.viewCells[0].getEvaluatedMetadata(viewModel.metadata), <NotebookCellMetadata>{
|
||||
editable: true,
|
||||
|
@ -200,7 +200,7 @@ suite('NotebookViewModel', () => {
|
|||
...defaults
|
||||
});
|
||||
|
||||
viewModel.notebookDocument.metadata = { editable: true, runnable: true, cellEditable: false, cellHasExecutionOrder: true, trusted: true };
|
||||
viewModel.notebookDocument.metadata = { editable: true, cellEditable: false, cellHasExecutionOrder: true, trusted: true };
|
||||
|
||||
assert.deepEqual(viewModel.viewCells[0].getEvaluatedMetadata(viewModel.metadata), <NotebookCellMetadata>{
|
||||
editable: false,
|
||||
|
|
|
@ -656,7 +656,6 @@ suite('ExtHostTypes', function () {
|
|||
assert.deepStrictEqual(obj.custom, notebookDocumentMetadataDefaults.custom);
|
||||
assert.strictEqual(obj.editable, notebookDocumentMetadataDefaults.editable);
|
||||
assert.strictEqual(obj.runState, notebookDocumentMetadataDefaults.runState);
|
||||
assert.strictEqual(obj.runnable, notebookDocumentMetadataDefaults.runnable);
|
||||
assert.strictEqual(obj.trusted, notebookDocumentMetadataDefaults.trusted);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue