mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
Fix #96433
This commit is contained in:
@@ -321,6 +321,19 @@ suite('notebook working copy', () => {
|
||||
});
|
||||
});
|
||||
|
||||
suite('metadata', () => {
|
||||
test('custom metadata should be supported', async function () {
|
||||
const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
|
||||
await waitFor(500);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.document.metadata.custom['testMetadata'] as boolean, false);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.metadata.custom['testCellMetadata'] as boolean, true);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
|
||||
});
|
||||
});
|
||||
|
||||
suite('regression', () => {
|
||||
test('microsoft/vscode-github-issue-notebooks#26. Insert template cell in the new empty document', async function () {
|
||||
const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './empty.vsctestnb'));
|
||||
|
||||
@@ -17,19 +17,25 @@ export function activate(context: vscode.ExtensionContext): any {
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
const dto: vscode.NotebookData = {
|
||||
languages: ['typescript'],
|
||||
metadata: {},
|
||||
metadata: {
|
||||
custom: { testMetadata: false }
|
||||
},
|
||||
cells: [
|
||||
{
|
||||
source: 'test',
|
||||
language: 'typescript',
|
||||
cellKind: vscode.CellKind.Code,
|
||||
outputs: [],
|
||||
metadata: {}
|
||||
metadata: {
|
||||
custom: { testCellMetadata: true }
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
return dto;
|
||||
},
|
||||
executeCell: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell | undefined, _token: vscode.CancellationToken) => {
|
||||
if (!_cell) {
|
||||
|
||||
Vendored
+10
@@ -1590,6 +1590,11 @@ declare module 'vscode' {
|
||||
* The total duration of the cell's last run
|
||||
*/
|
||||
lastRunDuration?: number;
|
||||
|
||||
/**
|
||||
* Additional attributes of a cell metadata.
|
||||
*/
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface NotebookCell {
|
||||
@@ -1635,6 +1640,11 @@ declare module 'vscode' {
|
||||
hasExecutionOrder?: boolean;
|
||||
|
||||
displayOrder?: GlobPattern[];
|
||||
|
||||
/**
|
||||
* Additional attributes of a cell metadata.
|
||||
*/
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface NotebookDocument {
|
||||
|
||||
@@ -38,7 +38,7 @@ export class MainThreadNotebookDocument extends Disposable {
|
||||
}));
|
||||
this._register(this._textModel.onDidSelectionChange(e => {
|
||||
const selectionsChange = e ? { selections: e } : null;
|
||||
this._proxy.$acceptEditorPropertiesChanged(uri, { selections: selectionsChange });
|
||||
this._proxy.$acceptEditorPropertiesChanged(uri, { selections: selectionsChange, metadata: null });
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -250,6 +250,8 @@ export class MainThreadNotebookController implements IMainNotebookController {
|
||||
document.textModel.insertTemplateCell(mainCell);
|
||||
}
|
||||
|
||||
this._proxy.$acceptEditorPropertiesChanged(uri, { selections: null, metadata: document.textModel.metadata });
|
||||
|
||||
return document.textModel;
|
||||
}
|
||||
|
||||
@@ -285,7 +287,8 @@ export class MainThreadNotebookController implements IMainNotebookController {
|
||||
addedDocuments: [{
|
||||
viewType: document.viewType,
|
||||
handle: document.handle,
|
||||
uri: document.uri
|
||||
uri: document.uri,
|
||||
metadata: document.textModel.metadata
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1539,6 +1539,7 @@ export interface INotebookSelectionChangeEvent {
|
||||
|
||||
export interface INotebookEditorPropertiesChangeData {
|
||||
selections: INotebookSelectionChangeEvent | null;
|
||||
metadata: NotebookDocumentMetadata | null;
|
||||
}
|
||||
|
||||
export interface INotebookModelAddedData {
|
||||
@@ -1546,6 +1547,7 @@ export interface INotebookModelAddedData {
|
||||
handle: number;
|
||||
// versionId: number;
|
||||
viewType: string;
|
||||
metadata?: NotebookDocumentMetadata;
|
||||
}
|
||||
|
||||
export interface INotebookDocumentsAndEditorsDelta {
|
||||
|
||||
@@ -949,6 +949,13 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
|
||||
editor.editor.selection = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.metadata) {
|
||||
editor.editor.document.metadata = {
|
||||
...notebookDocumentMetadataDefaults,
|
||||
...data.metadata
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async $acceptDocumentAndEditorsDelta(delta: INotebookDocumentsAndEditorsDelta) {
|
||||
@@ -978,6 +985,13 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
|
||||
const viewType = modelData.viewType;
|
||||
if (!this._documents.has(revivedUri.toString())) {
|
||||
let document = new ExtHostNotebookDocument(this._proxy, this._documentsAndEditors, viewType, revivedUri, this);
|
||||
if (modelData.metadata) {
|
||||
document.metadata = {
|
||||
...notebookDocumentMetadataDefaults,
|
||||
...modelData.metadata
|
||||
};
|
||||
}
|
||||
|
||||
this._documents.set(revivedUri.toString(), document);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,8 @@ export const notebookDocumentMetadataDefaults: Required<NotebookDocumentMetadata
|
||||
cellEditable: true,
|
||||
cellRunnable: true,
|
||||
hasExecutionOrder: true,
|
||||
displayOrder: NOTEBOOK_DISPLAY_ORDER
|
||||
displayOrder: NOTEBOOK_DISPLAY_ORDER,
|
||||
custom: {}
|
||||
};
|
||||
|
||||
export interface NotebookDocumentMetadata {
|
||||
@@ -65,6 +66,7 @@ export interface NotebookDocumentMetadata {
|
||||
cellRunnable: boolean;
|
||||
hasExecutionOrder: boolean;
|
||||
displayOrder?: GlobPattern[];
|
||||
custom?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export enum NotebookCellRunState {
|
||||
@@ -80,9 +82,9 @@ export interface NotebookCellMetadata {
|
||||
executionOrder?: number;
|
||||
statusMessage?: string;
|
||||
runState?: NotebookCellRunState;
|
||||
|
||||
runStartTime?: number;
|
||||
lastRunDuration?: number;
|
||||
custom?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface INotebookDisplayOrder {
|
||||
|
||||
Reference in New Issue
Block a user