Skip to content

Commit b54228e

Browse files
committed
Revert "make NotebookConcatTextDocument extends "normal" TextDocument, microsoft#100186"
This reverts commit cda677d.
1 parent 97e3e2c commit b54228e

3 files changed

Lines changed: 11 additions & 109 deletions

File tree

src/vs/vscode.proposed.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ declare module 'vscode' {
15191519
metadata: NotebookDocumentMetadata;
15201520
}
15211521

1522-
export interface NotebookConcatTextDocument extends TextDocument {
1522+
export interface NotebookConcatTextDocument {
15231523
isClosed: boolean;
15241524
dispose(): void;
15251525
onDidChange: Event<void>;

src/vs/workbench/api/common/extHostNotebookConcatDocument.ts

Lines changed: 8 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,32 @@ import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer'
1212
import { DisposableStore } from 'vs/base/common/lifecycle';
1313
import { score } from 'vs/editor/common/modes/languageSelector';
1414
import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
15-
import { basename } from 'vs/base/common/resources';
16-
import { ResourceMap } from 'vs/base/common/map';
17-
import { ExtHostDocumentLine } from 'vs/workbench/api/common/extHostDocumentData';
15+
import { isEqual } from 'vs/base/common/resources';
1816

19-
export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextDocument, vscode.TextDocument {
17+
export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextDocument {
2018

2119
private _disposables = new DisposableStore();
2220
private _isClosed = false;
2321

2422
private _cells!: ExtHostCell[];
25-
private _cellByUri!: ResourceMap<number>;
2623
private _cellLengths!: PrefixSumComputer;
2724
private _cellLines!: PrefixSumComputer;
2825
private _versionId = 0;
2926

3027
private readonly _onDidChange = new Emitter<void>();
3128
readonly onDidChange: Event<void> = this._onDidChange.event;
3229

33-
readonly uri: vscode.Uri;
34-
readonly fileName: string;
35-
readonly languageId: string;
36-
readonly isUntitled: boolean = false;
37-
readonly isDirty: boolean = false;
38-
3930
constructor(
4031
extHostNotebooks: ExtHostNotebookController,
4132
extHostDocuments: ExtHostDocuments,
4233
private readonly _notebook: vscode.NotebookDocument,
4334
private readonly _selector: vscode.DocumentSelector | undefined,
4435
) {
45-
this.uri = _notebook.uri.with({ scheme: 'vscode-notebook-concat-doc' });
46-
this.fileName = basename(this.uri);
47-
this.languageId = this._createLanguageId();
48-
4936
this._init();
5037

5138
this._disposables.add(extHostDocuments.onDidChangeDocument(e => {
52-
const cellIdx = this._cellByUri.get(e.document.uri);
53-
if (typeof cellIdx === 'number') {
39+
let cellIdx = this._cells.findIndex(cell => isEqual(cell.uri, e.document.uri));
40+
if (cellIdx >= 0) {
5441
this._cellLengths.changeValue(cellIdx, this._cells[cellIdx].document.getText().length + 1);
5542
this._cellLines.changeValue(cellIdx, this._cells[cellIdx].document.lineCount);
5643
this._versionId += 1;
@@ -81,12 +68,10 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
8168

8269
private _init() {
8370
this._cells = [];
84-
this._cellByUri = new ResourceMap();
8571
const cellLengths: number[] = [];
8672
const cellLineCounts: number[] = [];
8773
for (let cell of this._notebook.cells) {
8874
if (cell.cellKind === CellKind.Code && (!this._selector || score(this._selector, cell.uri, cell.language, true))) {
89-
this._cellByUri.set(cell.uri, this._cells.length);
9075
this._cells.push(<ExtHostCell>cell);
9176
cellLengths.push(cell.document.getText().length + 1);
9277
cellLineCounts.push(cell.document.lineCount);
@@ -96,67 +81,6 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
9681
this._cellLines = new PrefixSumComputer(new Uint32Array(cellLineCounts));
9782
}
9883

99-
private _createLanguageId(): string {
100-
const languageIds = new Set<string>();
101-
(function fillInLanguageIds(selector: vscode.DocumentSelector | undefined) {
102-
if (Array.isArray(selector)) {
103-
selector.forEach(fillInLanguageIds);
104-
} else if (typeof selector === 'string') {
105-
languageIds.add(selector);
106-
} else if (selector?.language) {
107-
languageIds.add(selector.language);
108-
}
109-
})(this._selector);
110-
111-
if (languageIds.size === 0) {
112-
return 'unknown';
113-
}
114-
return [...languageIds.values()].sort().join(';');
115-
}
116-
117-
save(): Thenable<boolean> {
118-
// todo@jrieken throw error instead?
119-
return Promise.resolve(false);
120-
}
121-
122-
get eol(): vscode.EndOfLine {
123-
return types.EndOfLine.LF;
124-
}
125-
126-
get lineCount(): number {
127-
let total = 0;
128-
for (let cell of this._cells) {
129-
total += cell.document.lineCount;
130-
}
131-
return total;
132-
}
133-
134-
lineAt(lineOrPosition: number | vscode.Position): vscode.TextLine {
135-
const line = typeof lineOrPosition === 'number' ? lineOrPosition : lineOrPosition.line;
136-
const cellIdx = this._cellLines.getIndexOf(line);
137-
return new ExtHostDocumentLine(
138-
line,
139-
this._cells[cellIdx.index].document.lineAt(cellIdx.remainder).text,
140-
line >= this.lineCount
141-
);
142-
}
143-
144-
getWordRangeAtPosition(position: vscode.Position, regex?: RegExp | undefined): vscode.Range | undefined {
145-
const cellIdx = this._cellLines.getIndexOf(position.line);
146-
return this._cells[cellIdx.index].document.getWordRangeAtPosition(position.with({ line: cellIdx.remainder }), regex);
147-
}
148-
149-
validateRange(range: vscode.Range): vscode.Range {
150-
const start = this.validatePosition(range.start);
151-
const end = this.validatePosition(range.end);
152-
return range.with({ start, end });
153-
}
154-
155-
validatePosition(position: vscode.Position): vscode.Position {
156-
const cellIdx = this._cellLines.getIndexOf(position.line);
157-
return this._cells[cellIdx.index].document.validatePosition(position.with({ line: cellIdx.remainder }));
158-
}
159-
16084
get version(): number {
16185
return this._versionId;
16286
}
@@ -179,8 +103,8 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
179103
// get start and end locations and create substrings
180104
const start = this.locationAt(range.start);
181105
const end = this.locationAt(range.end);
182-
const startCell = this._cells[this._cellByUri.get(start.uri) ?? -1];
183-
const endCell = this._cells[this._cellByUri.get(end.uri) ?? -1];
106+
const startCell = this._cells.find(cell => isEqual(cell.uri, start.uri));
107+
const endCell = this._cells.find(cell => isEqual(cell.uri, end.uri));
184108

185109
if (!startCell || !endCell) {
186110
return '';
@@ -207,8 +131,8 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
207131
return this._cells[idx.index].document.positionAt(idx.remainder).translate(lineCount);
208132
}
209133

210-
const idx = this._cellByUri.get(locationOrOffset.uri);
211-
if (typeof idx === 'number') {
134+
const idx = this._cells.findIndex(cell => isEqual(cell.uri, locationOrOffset.uri));
135+
if (idx >= 0) {
212136
let line = this._cellLines.getAccumulatedValue(idx - 1);
213137
return new types.Position(line + locationOrOffset.range.start.line, locationOrOffset.range.start.character);
214138
}

src/vs/workbench/test/browser/api/extHostNotebookConcatDocument.test.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ExtHostNotebookConcatDocument } from 'vs/workbench/api/common/extHostNo
1212
import { ExtHostNotebookDocument, ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
1313
import { URI } from 'vs/base/common/uri';
1414
import { CellKind, CellUri, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
15-
import { Position, Location, Range, EndOfLine } from 'vs/workbench/api/common/extHostTypes';
15+
import { Position, Location, Range } from 'vs/workbench/api/common/extHostTypes';
1616
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
1717
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
1818
import * as vscode from 'vscode';
@@ -28,7 +28,7 @@ suite('NotebookConcatDocument', function () {
2828
let extHostDocumentsAndEditors: ExtHostDocumentsAndEditors;
2929
let extHostDocuments: ExtHostDocuments;
3030
let extHostNotebooks: ExtHostNotebookController;
31-
const notebookUri = URI.parse('test:/path/notebook.file');
31+
const notebookUri = URI.parse('test:///notebook.file');
3232
const disposables = new DisposableStore();
3333

3434
setup(async function () {
@@ -80,19 +80,6 @@ suite('NotebookConcatDocument', function () {
8080
disposables.add(extHostDocuments);
8181
});
8282

83-
test('basics', async function () {
84-
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, undefined);
85-
assert.equal(doc.uri.toString(), 'vscode-notebook-concat-doc:/path/notebook.file');
86-
assert.equal(doc.fileName, 'notebook.file');
87-
assert.equal(doc.isUntitled, false);
88-
assert.equal(doc.isDirty, false);
89-
assert.equal(await doc.save(), false);
90-
assert.equal(doc.isClosed, false);
91-
assert.equal(doc.eol, EndOfLine.LF);
92-
doc.dispose();
93-
assert.equal(doc.isClosed, true);
94-
});
95-
9683
test('empty', function () {
9784
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, undefined);
9885
assert.equal(doc.getText(), '');
@@ -122,11 +109,6 @@ suite('NotebookConcatDocument', function () {
122109
function assertLines(doc: vscode.NotebookConcatTextDocument, ...lines: string[]) {
123110
let actual = doc.getText().split(/\r\n|\n|\r/);
124111
assert.deepStrictEqual(actual, lines);
125-
assert.equal(doc.lineCount, lines.length);
126-
for (let i = 0; i < lines.length; i++) {
127-
assert.equal(doc.lineAt(i).text, lines[i]);
128-
assert.equal(doc.lineAt(i).range.start.line, i);
129-
}
130112
}
131113

132114
test('location, position mapping', function () {
@@ -320,10 +302,6 @@ suite('NotebookConcatDocument', function () {
320302
const fooLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, 'fooLang');
321303
const barLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, 'barLang');
322304

323-
assert.equal(mixedDoc.languageId, 'unknown');
324-
assert.equal(fooLangDoc.languageId, 'fooLang');
325-
assert.equal(barLangDoc.languageId, 'barLang');
326-
327305
assertLines(mixedDoc, 'fooLang-document', 'barLang-document');
328306
assertLines(fooLangDoc, 'fooLang-document');
329307
assertLines(barLangDoc, 'barLang-document');

0 commit comments

Comments
 (0)