From 50ea16198d613629f7b57592a52ec834378f1c41 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 14 Apr 2022 14:39:44 -0700 Subject: [PATCH] Remove the concat text document api proposal Fixes #146781 --- extensions/vscode-api-tests/package.json | 1 - extensions/vscode-notebook-tests/package.json | 1 - .../workbench/api/common/extHost.api.impl.ts | 6 - .../common/extHostNotebookConcatDocument.ts | 192 ------ .../extHostNotebookConcatDocument.test.ts | 620 ------------------ .../common/extensionsApiProposals.ts | 1 - ...e.proposed.notebookConcatTextDocument.d.ts | 50 -- 7 files changed, 871 deletions(-) delete mode 100644 src/vs/workbench/api/common/extHostNotebookConcatDocument.ts delete mode 100644 src/vs/workbench/api/test/browser/extHostNotebookConcatDocument.test.ts delete mode 100644 src/vscode-dts/vscode.proposed.notebookConcatTextDocument.d.ts diff --git a/extensions/vscode-api-tests/package.json b/extensions/vscode-api-tests/package.json index 22a274a9c68db..2a1bad686775f 100644 --- a/extensions/vscode-api-tests/package.json +++ b/extensions/vscode-api-tests/package.json @@ -19,7 +19,6 @@ "fsChunks", "inlineCompletions", "notebookCellExecutionState", - "notebookConcatTextDocument", "notebookContentProvider", "notebookControllerKind", "notebookDebugOptions", diff --git a/extensions/vscode-notebook-tests/package.json b/extensions/vscode-notebook-tests/package.json index e0a672ca17933..8792cd4e6fb1a 100644 --- a/extensions/vscode-notebook-tests/package.json +++ b/extensions/vscode-notebook-tests/package.json @@ -11,7 +11,6 @@ "main": "./out/extension", "enabledApiProposals": [ "notebookCellExecutionState", - "notebookConcatTextDocument", "notebookContentProvider", "notebookControllerKind", "notebookDebugOptions", diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 668f8eb02c65f..6cb1dd4fdfb33 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -70,7 +70,6 @@ import { IExtHostTunnelService } from 'vs/workbench/api/common/extHostTunnelServ import { IExtHostApiDeprecationService } from 'vs/workbench/api/common/extHostApiDeprecationService'; import { ExtHostAuthentication } from 'vs/workbench/api/common/extHostAuthentication'; import { ExtHostTimeline } from 'vs/workbench/api/common/extHostTimeline'; -import { ExtHostNotebookConcatDocument } from 'vs/workbench/api/common/extHostNotebookConcatDocument'; import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths'; import { IExtHostConsumerFileSystem } from 'vs/workbench/api/common/extHostFileSystemConsumer'; import { ExtHostWebviewViews } from 'vs/workbench/api/common/extHostWebviewView'; @@ -1130,11 +1129,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I checkProposedApiEnabled(extension, 'notebookCellExecutionState'); return extHostNotebookKernels.onDidChangeNotebookCellExecutionState(listener, thisArgs, disposables); }, - createConcatTextDocument(notebook, selector) { - checkProposedApiEnabled(extension, 'notebookConcatTextDocument'); - extHostApiDeprecation.report('notebookConcatTextDocument', extension, 'This proposal is not on track for finalization and will be removed.'); - return new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook, selector); - }, createNotebookProxyController(id: string, notebookType: string, label: string, handler: () => vscode.NotebookController | string | Thenable) { checkProposedApiEnabled(extension, 'notebookProxyController'); return extHostNotebookProxyKernels.createNotebookProxyController(extension, id, notebookType, label, handler); diff --git a/src/vs/workbench/api/common/extHostNotebookConcatDocument.ts b/src/vs/workbench/api/common/extHostNotebookConcatDocument.ts deleted file mode 100644 index 65ecebc97c189..0000000000000 --- a/src/vs/workbench/api/common/extHostNotebookConcatDocument.ts +++ /dev/null @@ -1,192 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as types from 'vs/workbench/api/common/extHostTypes'; -import * as vscode from 'vscode'; -import { Event, Emitter } from 'vs/base/common/event'; -import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments'; -import { PrefixSumComputer } from 'vs/editor/common/model/prefixSumComputer'; -import { DisposableStore } from 'vs/base/common/lifecycle'; -import { score } from 'vs/editor/common/languageSelector'; -import { ResourceMap } from 'vs/base/common/map'; -import { URI } from 'vs/base/common/uri'; -import { generateUuid } from 'vs/base/common/uuid'; -import { ExtHostNotebookDocuments } from 'vs/workbench/api/common/extHostNotebookDocuments'; - -export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextDocument { - - private _disposables = new DisposableStore(); - private _isClosed = false; - - private _cells!: vscode.NotebookCell[]; - private _cellUris!: ResourceMap; - private _cellLengths!: PrefixSumComputer; - private _cellLines!: PrefixSumComputer; - private _versionId = 0; - - private readonly _onDidChange = new Emitter(); - readonly onDidChange: Event = this._onDidChange.event; - - readonly uri = URI.from({ scheme: 'vscode-concat-doc', path: generateUuid() }); - - constructor( - extHostNotebooks: ExtHostNotebookDocuments, - extHostDocuments: ExtHostDocuments, - private readonly _notebook: vscode.NotebookDocument, - private readonly _selector: vscode.DocumentSelector | undefined, - ) { - this._init(); - - this._disposables.add(extHostDocuments.onDidChangeDocument(e => { - const cellIdx = this._cellUris.get(e.document.uri); - if (cellIdx !== undefined) { - this._cellLengths.setValue(cellIdx, this._cells[cellIdx].document.getText().length + 1); - this._cellLines.setValue(cellIdx, this._cells[cellIdx].document.lineCount); - this._versionId += 1; - this._onDidChange.fire(undefined); - } - })); - const documentChange = (document: vscode.NotebookDocument) => { - if (document === this._notebook) { - this._init(); - this._versionId += 1; - this._onDidChange.fire(undefined); - } - }; - - this._disposables.add(extHostNotebooks.onDidChangeNotebookDocument(e => documentChange(e.notebook))); - } - - dispose(): void { - this._disposables.dispose(); - this._isClosed = true; - } - - get isClosed() { - return this._isClosed; - } - - private _init() { - this._cells = []; - this._cellUris = new ResourceMap(); - const cellLengths: number[] = []; - const cellLineCounts: number[] = []; - for (const cell of this._notebook.getCells()) { - if (cell.kind === types.NotebookCellKind.Code && (!this._selector || score(this._selector, cell.document.uri, cell.document.languageId, true, undefined))) { - this._cellUris.set(cell.document.uri, this._cells.length); - this._cells.push(cell); - cellLengths.push(cell.document.getText().length + 1); - cellLineCounts.push(cell.document.lineCount); - } - } - this._cellLengths = new PrefixSumComputer(new Uint32Array(cellLengths)); - this._cellLines = new PrefixSumComputer(new Uint32Array(cellLineCounts)); - } - - get version(): number { - return this._versionId; - } - - getText(range?: vscode.Range): string { - if (!range) { - let result = ''; - for (const cell of this._cells) { - result += cell.document.getText() + '\n'; - } - // remove last newline again - result = result.slice(0, -1); - return result; - } - - if (range.isEmpty) { - return ''; - } - - // get start and end locations and create substrings - const start = this.locationAt(range.start); - const end = this.locationAt(range.end); - - const startIdx = this._cellUris.get(start.uri); - const endIdx = this._cellUris.get(end.uri); - - if (startIdx === undefined || endIdx === undefined) { - return ''; - } - - if (startIdx === endIdx) { - return this._cells[startIdx].document.getText(new types.Range(start.range.start, end.range.end)); - } - - const parts = [this._cells[startIdx].document.getText(new types.Range(start.range.start, new types.Position(this._cells[startIdx].document.lineCount, 0)))]; - for (let i = startIdx + 1; i < endIdx; i++) { - parts.push(this._cells[i].document.getText()); - } - parts.push(this._cells[endIdx].document.getText(new types.Range(new types.Position(0, 0), end.range.end))); - return parts.join('\n'); - } - - offsetAt(position: vscode.Position): number { - const idx = this._cellLines.getIndexOf(position.line); - const offset1 = this._cellLengths.getPrefixSum(idx.index - 1); - const offset2 = this._cells[idx.index].document.offsetAt(position.with(idx.remainder)); - return offset1 + offset2; - } - - positionAt(locationOrOffset: vscode.Location | number): vscode.Position { - if (typeof locationOrOffset === 'number') { - const idx = this._cellLengths.getIndexOf(locationOrOffset); - const lineCount = this._cellLines.getPrefixSum(idx.index - 1); - return this._cells[idx.index].document.positionAt(idx.remainder).translate(lineCount); - } - - const idx = this._cellUris.get(locationOrOffset.uri); - if (idx !== undefined) { - const line = this._cellLines.getPrefixSum(idx - 1); - return new types.Position(line + locationOrOffset.range.start.line, locationOrOffset.range.start.character); - } - // do better? - // return undefined; - return new types.Position(0, 0); - } - - locationAt(positionOrRange: vscode.Range | vscode.Position): types.Location { - if (!types.Range.isRange(positionOrRange)) { - positionOrRange = new types.Range(positionOrRange, positionOrRange); - } - - const startIdx = this._cellLines.getIndexOf(positionOrRange.start.line); - let endIdx = startIdx; - if (!positionOrRange.isEmpty) { - endIdx = this._cellLines.getIndexOf(positionOrRange.end.line); - } - - const startPos = new types.Position(startIdx.remainder, positionOrRange.start.character); - const endPos = new types.Position(endIdx.remainder, positionOrRange.end.character); - const range = new types.Range(startPos, endPos); - - const startCell = this._cells[startIdx.index]; - return new types.Location(startCell.document.uri, startCell.document.validateRange(range)); - } - - contains(uri: vscode.Uri): boolean { - return this._cellUris.has(uri); - } - - validateRange(range: vscode.Range): vscode.Range { - const start = this.validatePosition(range.start); - const end = this.validatePosition(range.end); - return range.with(start, end); - } - - validatePosition(position: vscode.Position): vscode.Position { - const startIdx = this._cellLines.getIndexOf(position.line); - - const cellPosition = new types.Position(startIdx.remainder, position.character); - const validCellPosition = this._cells[startIdx.index].document.validatePosition(cellPosition); - - const line = this._cellLines.getPrefixSum(startIdx.index - 1); - return new types.Position(line + validCellPosition.line, validCellPosition.character); - } -} diff --git a/src/vs/workbench/api/test/browser/extHostNotebookConcatDocument.test.ts b/src/vs/workbench/api/test/browser/extHostNotebookConcatDocument.test.ts deleted file mode 100644 index 6267d24994172..0000000000000 --- a/src/vs/workbench/api/test/browser/extHostNotebookConcatDocument.test.ts +++ /dev/null @@ -1,620 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as assert from 'assert'; -import { TestRPCProtocol } from 'vs/workbench/api/test/common/testRPCProtocol'; -import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments'; -import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors'; -import { NullLogService } from 'vs/platform/log/common/log'; -import { ExtHostNotebookConcatDocument } from 'vs/workbench/api/common/extHostNotebookConcatDocument'; -import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook'; -import { ExtHostNotebookDocument } from 'vs/workbench/api/common/extHostNotebookDocument'; -import { URI } from 'vs/base/common/uri'; -import { CellKind, CellUri, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon'; -import { Position, Location, Range } from 'vs/workbench/api/common/extHostTypes'; -import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands'; -import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions'; -import * as vscode from 'vscode'; -import { mock } from 'vs/workbench/test/common/workbenchTestServices'; -import { MainContext, MainThreadCommandsShape, MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol'; -import { DisposableStore } from 'vs/base/common/lifecycle'; -import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths'; -import { generateUuid } from 'vs/base/common/uuid'; -import { ExtHostNotebookDocuments } from 'vs/workbench/api/common/extHostNotebookDocuments'; -import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier'; - -suite('NotebookConcatDocument', function () { - - let rpcProtocol: TestRPCProtocol; - let notebook: ExtHostNotebookDocument; - let extHostDocumentsAndEditors: ExtHostDocumentsAndEditors; - let extHostDocuments: ExtHostDocuments; - let extHostNotebooks: ExtHostNotebookController; - let extHostNotebookDocuments: ExtHostNotebookDocuments; - - const notebookUri = URI.parse('test:///notebook.file'); - const disposables = new DisposableStore(); - - setup(async function () { - disposables.clear(); - - rpcProtocol = new TestRPCProtocol(); - rpcProtocol.set(MainContext.MainThreadCommands, new class extends mock() { - override $registerCommand() { } - }); - rpcProtocol.set(MainContext.MainThreadNotebook, new class extends mock() { - override async $registerNotebookProvider() { } - override async $unregisterNotebookProvider() { } - }); - extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService()); - extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors); - const extHostStoragePaths = new class extends mock() { - override workspaceValue() { - return URI.from({ scheme: 'test', path: generateUuid() }); - } - }; - extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, extHostDocuments, extHostStoragePaths); - extHostNotebookDocuments = new ExtHostNotebookDocuments(extHostNotebooks); - - let reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock() { - // async openNotebook() { } - }); - extHostNotebooks.$acceptDocumentAndEditorsDelta(new SerializableObjectWithBuffers({ - addedDocuments: [{ - uri: notebookUri, - viewType: 'test', - cells: [{ - handle: 0, - uri: CellUri.generate(notebookUri, 0), - source: ['### Heading'], - eol: '\n', - language: 'markdown', - cellKind: CellKind.Markup, - outputs: [], - }], - versionId: 0 - }], - addedEditors: [{ - documentUri: notebookUri, - id: '_notebook_editor_0', - selections: [{ start: 0, end: 1 }], - visibleRanges: [] - }] - })); - extHostNotebooks.$acceptDocumentAndEditorsDelta(new SerializableObjectWithBuffers({ newActiveEditor: '_notebook_editor_0' })); - - notebook = extHostNotebooks.notebookDocuments[0]!; - - disposables.add(reg); - disposables.add(notebook); - disposables.add(extHostDocuments); - }); - - test('empty', function () { - let doc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, undefined); - assert.strictEqual(doc.getText(), ''); - assert.strictEqual(doc.version, 0); - - // assert.strictEqual(doc.locationAt(new Position(0, 0)), undefined); - // assert.strictEqual(doc.positionAt(SOME_FAKE_LOCATION?), undefined); - }); - - - function assertLocation(doc: vscode.NotebookConcatTextDocument, pos: Position, expected: Location, reverse = true) { - const actual = doc.locationAt(pos); - assert.strictEqual(actual.uri.toString(), expected.uri.toString()); - assert.strictEqual(actual.range.isEqual(expected.range), true); - - if (reverse) { - // reverse - offset - const offset = doc.offsetAt(pos); - assert.strictEqual(doc.positionAt(offset).isEqual(pos), true); - - // reverse - pos - const actualPosition = doc.positionAt(actual); - assert.strictEqual(actualPosition.isEqual(pos), true); - } - } - - function assertLines(doc: vscode.NotebookConcatTextDocument, ...lines: string[]) { - let actual = doc.getText().split(/\r\n|\n|\r/); - assert.deepStrictEqual(actual, lines); - } - - test('contains', function () { - - const cellUri1 = CellUri.generate(notebook.uri, 1); - const cellUri2 = CellUri.generate(notebook.uri, 2); - - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [{ - kind: NotebookCellsChangeType.ModelChange, - changes: [[0, 0, [{ - handle: 1, - uri: cellUri1, - source: ['Hello', 'World', 'Hello World!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }, { - handle: 2, - uri: cellUri2, - source: ['Hallo', 'Welt', 'Hallo Welt!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }]] - ] - }] - }), false); - - - assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code - - let doc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, undefined); - - assert.strictEqual(doc.contains(cellUri1), true); - assert.strictEqual(doc.contains(cellUri2), true); - assert.strictEqual(doc.contains(URI.parse('some://miss/path')), false); - }); - - test('location, position mapping', function () { - - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [ - { - kind: NotebookCellsChangeType.ModelChange, - changes: [[0, 0, [{ - handle: 1, - uri: CellUri.generate(notebook.uri, 1), - source: ['Hello', 'World', 'Hello World!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }, { - handle: 2, - uri: CellUri.generate(notebook.uri, 2), - source: ['Hallo', 'Welt', 'Hallo Welt!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }]]] - } - ] - }), false); - - - assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code - - let doc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, undefined); - assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!'); - - assertLocation(doc, new Position(0, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(0, 0))); - assertLocation(doc, new Position(4, 0), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 0))); - assertLocation(doc, new Position(4, 3), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 3))); - assertLocation(doc, new Position(5, 11), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(2, 11))); - assertLocation(doc, new Position(5, 12), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(2, 11)), false); // don't check identity because position will be clamped - }); - - - test('location, position mapping, cell changes', function () { - - let doc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, undefined); - - // UPDATE 1 - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [ - { - kind: NotebookCellsChangeType.ModelChange, - changes: [[0, 0, [{ - handle: 1, - uri: CellUri.generate(notebook.uri, 1), - source: ['Hello', 'World', 'Hello World!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }]]] - } - ] - }), false); - assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 1); - assert.strictEqual(doc.version, 1); - assertLines(doc, 'Hello', 'World', 'Hello World!'); - - assertLocation(doc, new Position(0, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(0, 0))); - assertLocation(doc, new Position(2, 2), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 2))); - assertLocation(doc, new Position(4, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 12)), false); // clamped - - - // UPDATE 2 - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [ - { - kind: NotebookCellsChangeType.ModelChange, - changes: [[1, 0, [{ - handle: 2, - uri: CellUri.generate(notebook.uri, 2), - source: ['Hallo', 'Welt', 'Hallo Welt!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }]]] - } - ] - }), false); - - assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); - assert.strictEqual(doc.version, 2); - assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!'); - assertLocation(doc, new Position(0, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(0, 0))); - assertLocation(doc, new Position(4, 0), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 0))); - assertLocation(doc, new Position(4, 3), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 3))); - assertLocation(doc, new Position(5, 11), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(2, 11))); - assertLocation(doc, new Position(5, 12), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(2, 11)), false); // don't check identity because position will be clamped - - // UPDATE 3 (remove cell #2 again) - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [ - { - kind: NotebookCellsChangeType.ModelChange, - changes: [[1, 1, []]] - } - ] - }), false); - assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 1); - assert.strictEqual(doc.version, 3); - assertLines(doc, 'Hello', 'World', 'Hello World!'); - assertLocation(doc, new Position(0, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(0, 0))); - assertLocation(doc, new Position(2, 2), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 2))); - assertLocation(doc, new Position(4, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 12)), false); // clamped - }); - - test('location, position mapping, cell-document changes', function () { - - let doc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, undefined); - - // UPDATE 1 - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [ - { - - kind: NotebookCellsChangeType.ModelChange, - changes: [[0, 0, [{ - handle: 1, - uri: CellUri.generate(notebook.uri, 1), - source: ['Hello', 'World', 'Hello World!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }, { - handle: 2, - uri: CellUri.generate(notebook.uri, 2), - source: ['Hallo', 'Welt', 'Hallo Welt!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }]]] - } - ] - }), false); - assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); - assert.strictEqual(doc.version, 1); - - assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!'); - assertLocation(doc, new Position(0, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(0, 0))); - assertLocation(doc, new Position(2, 2), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 2))); - assertLocation(doc, new Position(2, 12), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 12))); - assertLocation(doc, new Position(4, 0), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 0))); - assertLocation(doc, new Position(4, 3), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 3))); - - // offset math - let cell1End = doc.offsetAt(new Position(2, 12)); - assert.strictEqual(doc.positionAt(cell1End).isEqual(new Position(2, 12)), true); - - extHostDocuments.$acceptModelChanged(notebook.apiNotebook.cellAt(0).document.uri, { - versionId: 0, - eol: '\n', - changes: [{ - range: { startLineNumber: 3, startColumn: 1, endLineNumber: 3, endColumn: 6 }, - rangeLength: 6, - rangeOffset: 12, - text: 'Hi' - }], - isRedoing: false, - isUndoing: false, - }, false); - assertLines(doc, 'Hello', 'World', 'Hi World!', 'Hallo', 'Welt', 'Hallo Welt!'); - assertLocation(doc, new Position(2, 12), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 9)), false); - - assert.strictEqual(doc.positionAt(cell1End).isEqual(new Position(3, 2)), true); - - }); - - test('selector', function () { - - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [ - { - kind: NotebookCellsChangeType.ModelChange, - changes: [[0, 0, [{ - handle: 1, - uri: CellUri.generate(notebook.uri, 1), - source: ['fooLang-document'], - eol: '\n', - language: 'fooLang', - cellKind: CellKind.Code, - outputs: [], - }, { - handle: 2, - uri: CellUri.generate(notebook.uri, 2), - source: ['barLang-document'], - eol: '\n', - language: 'barLang', - cellKind: CellKind.Code, - outputs: [], - }]]] - } - ] - }), false); - - const mixedDoc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, undefined); - const fooLangDoc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, 'fooLang'); - const barLangDoc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, 'barLang'); - - assertLines(mixedDoc, 'fooLang-document', 'barLang-document'); - assertLines(fooLangDoc, 'fooLang-document'); - assertLines(barLangDoc, 'barLang-document'); - - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [ - { - kind: NotebookCellsChangeType.ModelChange, - changes: [[2, 0, [{ - handle: 3, - uri: CellUri.generate(notebook.uri, 3), - source: ['barLang-document2'], - eol: '\n', - language: 'barLang', - cellKind: CellKind.Code, - outputs: [], - }]]] - } - ] - }), false); - - assertLines(mixedDoc, 'fooLang-document', 'barLang-document', 'barLang-document2'); - assertLines(fooLangDoc, 'fooLang-document'); - assertLines(barLangDoc, 'barLang-document', 'barLang-document2'); - }); - - function assertOffsetAtPosition(doc: vscode.NotebookConcatTextDocument, offset: number, expected: { line: number; character: number }, reverse = true) { - const actual = doc.positionAt(offset); - - assert.strictEqual(actual.line, expected.line); - assert.strictEqual(actual.character, expected.character); - - if (reverse) { - const actualOffset = doc.offsetAt(actual); - assert.strictEqual(actualOffset, offset); - } - } - - - test('offsetAt(position) <-> positionAt(offset)', function () { - - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [ - { - kind: NotebookCellsChangeType.ModelChange, - changes: [[0, 0, [{ - handle: 1, - uri: CellUri.generate(notebook.uri, 1), - source: ['Hello', 'World', 'Hello World!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }, { - handle: 2, - uri: CellUri.generate(notebook.uri, 2), - source: ['Hallo', 'Welt', 'Hallo Welt!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }]]] - } - ] - }), false); - - assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code - - let doc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, undefined); - assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!'); - - assertOffsetAtPosition(doc, 0, { line: 0, character: 0 }); - assertOffsetAtPosition(doc, 1, { line: 0, character: 1 }); - assertOffsetAtPosition(doc, 9, { line: 1, character: 3 }); - assertOffsetAtPosition(doc, 32, { line: 4, character: 1 }); - assertOffsetAtPosition(doc, 47, { line: 5, character: 11 }); - }); - - - function assertLocationAtPosition(doc: vscode.NotebookConcatTextDocument, pos: { line: number; character: number }, expected: { uri: URI; line: number; character: number }, reverse = true) { - - const actual = doc.locationAt(new Position(pos.line, pos.character)); - assert.strictEqual(actual.uri.toString(), expected.uri.toString()); - assert.strictEqual(actual.range.start.line, expected.line); - assert.strictEqual(actual.range.end.line, expected.line); - assert.strictEqual(actual.range.start.character, expected.character); - assert.strictEqual(actual.range.end.character, expected.character); - - if (reverse) { - const actualPos = doc.positionAt(actual); - assert.strictEqual(actualPos.line, pos.line); - assert.strictEqual(actualPos.character, pos.character); - } - } - - test('locationAt(position) <-> positionAt(location)', function () { - - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [ - { - kind: NotebookCellsChangeType.ModelChange, - changes: [[0, 0, [{ - handle: 1, - uri: CellUri.generate(notebook.uri, 1), - source: ['Hello', 'World', 'Hello World!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }, { - handle: 2, - uri: CellUri.generate(notebook.uri, 2), - source: ['Hallo', 'Welt', 'Hallo Welt!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }]]] - } - ] - }), false); - - assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code - - let doc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, undefined); - assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!'); - - assertLocationAtPosition(doc, { line: 0, character: 0 }, { uri: notebook.apiNotebook.cellAt(0).document.uri, line: 0, character: 0 }); - assertLocationAtPosition(doc, { line: 2, character: 0 }, { uri: notebook.apiNotebook.cellAt(0).document.uri, line: 2, character: 0 }); - assertLocationAtPosition(doc, { line: 2, character: 12 }, { uri: notebook.apiNotebook.cellAt(0).document.uri, line: 2, character: 12 }); - assertLocationAtPosition(doc, { line: 3, character: 0 }, { uri: notebook.apiNotebook.cellAt(1).document.uri, line: 0, character: 0 }); - assertLocationAtPosition(doc, { line: 5, character: 0 }, { uri: notebook.apiNotebook.cellAt(1).document.uri, line: 2, character: 0 }); - assertLocationAtPosition(doc, { line: 5, character: 11 }, { uri: notebook.apiNotebook.cellAt(1).document.uri, line: 2, character: 11 }); - }); - - test('getText(range)', function () { - - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [ - { - kind: NotebookCellsChangeType.ModelChange, - changes: [[0, 0, [{ - handle: 1, - uri: CellUri.generate(notebook.uri, 1), - source: ['Hello', 'World', 'Hello World!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }, { - handle: 2, - uri: CellUri.generate(notebook.uri, 2), - source: ['Hallo', 'Welt', 'Hallo Welt!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }, { - handle: 3, - uri: CellUri.generate(notebook.uri, 3), - source: ['Three', 'Drei', 'Drüü'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }]]] - } - ] - }), false); - - assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 3); // markdown and code - - let doc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, undefined); - assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!', 'Three', 'Drei', 'Drüü'); - - assert.strictEqual(doc.getText(new Range(0, 0, 0, 0)), ''); - assert.strictEqual(doc.getText(new Range(0, 0, 1, 0)), 'Hello\n'); - assert.strictEqual(doc.getText(new Range(2, 0, 4, 0)), 'Hello World!\nHallo\n'); - assert.strictEqual(doc.getText(new Range(2, 0, 8, 0)), 'Hello World!\nHallo\nWelt\nHallo Welt!\nThree\nDrei\n'); - }); - - test('validateRange/Position', function () { - - extHostNotebookDocuments.$acceptModelChanged(notebookUri, new SerializableObjectWithBuffers({ - versionId: notebook.apiNotebook.version + 1, - rawEvents: [ - { - kind: NotebookCellsChangeType.ModelChange, - changes: [[0, 0, [{ - handle: 1, - uri: CellUri.generate(notebook.uri, 1), - source: ['Hello', 'World', 'Hello World!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }, { - handle: 2, - uri: CellUri.generate(notebook.uri, 2), - source: ['Hallo', 'Welt', 'Hallo Welt!'], - eol: '\n', - language: 'test', - cellKind: CellKind.Code, - outputs: [], - }]]] - } - ] - }), false); - - assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code - - let doc = new ExtHostNotebookConcatDocument(extHostNotebookDocuments, extHostDocuments, notebook.apiNotebook, undefined); - assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!'); - - - function assertPosition(actual: vscode.Position, expectedLine: number, expectedCh: number) { - assert.strictEqual(actual.line, expectedLine); - assert.strictEqual(actual.character, expectedCh); - } - - - // "fixed" - assertPosition(doc.validatePosition(new Position(0, 1000)), 0, 5); - assertPosition(doc.validatePosition(new Position(2, 1000)), 2, 12); - assertPosition(doc.validatePosition(new Position(5, 1000)), 5, 11); - assertPosition(doc.validatePosition(new Position(5000, 1000)), 5, 11); - - // "good" - assertPosition(doc.validatePosition(new Position(0, 1)), 0, 1); - assertPosition(doc.validatePosition(new Position(0, 5)), 0, 5); - assertPosition(doc.validatePosition(new Position(2, 8)), 2, 8); - assertPosition(doc.validatePosition(new Position(2, 12)), 2, 12); - assertPosition(doc.validatePosition(new Position(5, 11)), 5, 11); - - }); -}); diff --git a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts index 4bb2426b9a3a9..04e760d97ce40 100644 --- a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts +++ b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts @@ -30,7 +30,6 @@ export const allApiProposals = Object.freeze({ inputBoxSeverity: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.inputBoxSeverity.d.ts', ipc: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.ipc.d.ts', notebookCellExecutionState: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookCellExecutionState.d.ts', - notebookConcatTextDocument: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookConcatTextDocument.d.ts', notebookContentProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookContentProvider.d.ts', notebookControllerKind: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookControllerKind.d.ts', notebookDebugOptions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookDebugOptions.d.ts', diff --git a/src/vscode-dts/vscode.proposed.notebookConcatTextDocument.d.ts b/src/vscode-dts/vscode.proposed.notebookConcatTextDocument.d.ts deleted file mode 100644 index 259708cbe8ee9..0000000000000 --- a/src/vscode-dts/vscode.proposed.notebookConcatTextDocument.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -declare module 'vscode' { - - // https://github.com/microsoft/vscode/issues/106744 - - export namespace notebooks { - /** - * @deprecated - */ - // todo@API really needed? we didn't find a user here - export function createConcatTextDocument(notebook: NotebookDocument, selector?: DocumentSelector): NotebookConcatTextDocument; - } - - /** @deprecated */ - export interface NotebookConcatTextDocument { - /** @deprecated */ - readonly uri: Uri; - /** @deprecated */ - readonly isClosed: boolean; - /** @deprecated */ - dispose(): void; - /** @deprecated */ - readonly onDidChange: Event; - /** @deprecated */ - readonly version: number; - /** @deprecated */ - getText(): string; - /** @deprecated */ - getText(range: Range): string; - - offsetAt(position: Position): number; - /** @deprecated */ - positionAt(offset: number): Position; - /** @deprecated */ - validateRange(range: Range): Range; - /** @deprecated */ - validatePosition(position: Position): Position; - - /** @deprecated */ - locationAt(positionOrRange: Position | Range): Location; - /** @deprecated */ - positionAt(location: Location): Position; - /** @deprecated */ - contains(uri: Uri): boolean; - } -}