chore(vscode): update to 1.56.0

This commit is contained in:
Akash Satheesan
2021-04-30 20:25:17 +05:30
1749 changed files with 88014 additions and 43316 deletions

View File

@@ -11,11 +11,11 @@ import { isWindows } from 'vs/base/common/platform';
suite('ExtHost API', function () {
test('issue #51387: originalFSPath', function () {
if (isWindows) {
assert.equal(originalFSPath(URI.file('C:\\test')).charAt(0), 'C');
assert.equal(originalFSPath(URI.file('c:\\test')).charAt(0), 'c');
assert.strictEqual(originalFSPath(URI.file('C:\\test')).charAt(0), 'C');
assert.strictEqual(originalFSPath(URI.file('c:\\test')).charAt(0), 'c');
assert.equal(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('C:\\test'))))).charAt(0), 'C');
assert.equal(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('c:\\test'))))).charAt(0), 'c');
assert.strictEqual(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('C:\\test'))))).charAt(0), 'C');
assert.strictEqual(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('c:\\test'))))).charAt(0), 'c');
}
});
});

View File

@@ -90,14 +90,14 @@ suite('ExtHostLanguageFeatureCommands', function () {
rpcProtocol = new TestRPCProtocol();
const services = new ServiceCollection();
services.set(IExtensionService, new class extends mock<IExtensionService>() {
async activateByEvent() {
override async activateByEvent() {
}
});
services.set(ICommandService, new SyncDescriptor(class extends mock<ICommandService>() {
executeCommand(id: string, ...args: any): any {
override executeCommand(id: string, ...args: any): any {
const command = CommandsRegistry.getCommands().get(id);
if (!command) {
return Promise.reject(new Error(id + ' NOT known'));
@@ -108,17 +108,17 @@ suite('ExtHostLanguageFeatureCommands', function () {
}));
services.set(IMarkerService, new MarkerService());
services.set(IModelService, new class extends mock<IModelService>() {
getModel() { return model; }
override getModel() { return model; }
});
services.set(ITextModelService, new class extends mock<ITextModelService>() {
async createModelReference() {
override async createModelReference() {
return new ImmortalReference<IResolvedTextEditorModel>(new class extends mock<IResolvedTextEditorModel>() {
textEditorModel = model;
override textEditorModel = model;
});
}
});
services.set(IEditorWorkerService, new class extends mock<IEditorWorkerService>() {
async computeMoreMinimalEdits(_uri: any, edits: any) {
override async computeMoreMinimalEdits(_uri: any, edits: any) {
return edits || undefined;
}
});
@@ -310,6 +310,42 @@ suite('ExtHostLanguageFeatureCommands', function () {
});
});
test('Definition, back and forth (sorting & de-deduping)', function () {
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
provideDefinition(doc: any): any {
return new types.Location(URI.parse('file:///b'), new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
provideDefinition(doc: any): any {
// duplicate result will get removed
return new types.Location(URI.parse('file:///b'), new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
provideDefinition(doc: any): any {
return [
new types.Location(URI.parse('file:///a'), new types.Range(2, 0, 0, 0)),
new types.Location(URI.parse('file:///c'), new types.Range(3, 0, 0, 0)),
new types.Location(URI.parse('file:///d'), new types.Range(4, 0, 0, 0)),
];
}
}));
return rpcProtocol.sync().then(() => {
return commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', model.uri, new types.Position(0, 0)).then(values => {
assert.strictEqual(values.length, 4);
assert.strictEqual(values[0].uri.path, '/a');
assert.strictEqual(values[1].uri.path, '/b');
assert.strictEqual(values[2].uri.path, '/c');
assert.strictEqual(values[3].uri.path, '/d');
});
});
});
test('Definition Link', () => {
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
provideDefinition(doc: any): (vscode.Location | vscode.LocationLink)[] {

View File

@@ -24,7 +24,7 @@ suite('ExtHostBulkEdits.applyWorkspaceEdit', () => {
let rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(MainContext.MainThreadBulkEdits, new class extends mock<MainThreadBulkEditsShape>() {
$tryApplyWorkspaceEdit(_workspaceResourceEdits: IWorkspaceEditDto): Promise<boolean> {
override $tryApplyWorkspaceEdit(_workspaceResourceEdits: IWorkspaceEditDto): Promise<boolean> {
workspaceResourceEdits = _workspaceResourceEdits;
return Promise.resolve(true);
}

View File

@@ -18,10 +18,10 @@ suite('ExtHostCommands', function () {
let lastUnregister: string;
const shape = new class extends mock<MainThreadCommandsShape>() {
$registerCommand(id: string): void {
override $registerCommand(id: string): void {
//
}
$unregisterCommand(id: string): void {
override $unregisterCommand(id: string): void {
lastUnregister = id;
}
};
@@ -41,10 +41,10 @@ suite('ExtHostCommands', function () {
let unregisterCounter = 0;
const shape = new class extends mock<MainThreadCommandsShape>() {
$registerCommand(id: string): void {
override $registerCommand(id: string): void {
//
}
$unregisterCommand(id: string): void {
override $unregisterCommand(id: string): void {
unregisterCounter += 1;
}
};
@@ -65,10 +65,10 @@ suite('ExtHostCommands', function () {
let count = 0;
const shape = new class extends mock<MainThreadCommandsShape>() {
$registerCommand(id: string): void {
override $registerCommand(id: string): void {
//
}
async $executeCommand<T>(id: string, args: any[], retry: boolean): Promise<T | undefined> {
override async $executeCommand<T>(id: string, args: any[], retry: boolean): Promise<T | undefined> {
count++;
assert.strictEqual(retry, count === 1);
if (count === 1) {

View File

@@ -18,20 +18,19 @@ import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitData
import { IExtHostFileSystemInfo } from 'vs/workbench/api/common/extHostFileSystemInfo';
import { FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
import { isLinux } from 'vs/base/common/platform';
import { WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust';
suite('ExtHostConfiguration', function () {
class RecordingShape extends mock<MainThreadConfigurationShape>() {
lastArgs!: [ConfigurationTarget, string, any];
$updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): Promise<void> {
override $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): Promise<void> {
this.lastArgs = [target, key, value];
return Promise.resolve(undefined);
}
}
function createExtHostWorkspace(): ExtHostWorkspace {
return new ExtHostWorkspace(new TestRPCProtocol(), new class extends mock<IExtHostInitDataService>() { }, new class extends mock<IExtHostFileSystemInfo>() { getCapabilities() { return isLinux ? FileSystemProviderCapabilities.PathCaseSensitive : undefined; } }, new NullLogService());
return new ExtHostWorkspace(new TestRPCProtocol(), new class extends mock<IExtHostInitDataService>() { }, new class extends mock<IExtHostFileSystemInfo>() { override getCapabilities() { return isLinux ? FileSystemProviderCapabilities.PathCaseSensitive : undefined; } }, new NullLogService());
}
function createExtHostConfiguration(contents: any = Object.create(null), shape?: MainThreadConfigurationShape) {
@@ -319,7 +318,7 @@ suite('ExtHostConfiguration', function () {
'id': 'foo',
'folders': [aWorkspaceFolder(URI.file('foo'), 0)],
'name': 'foo'
}, WorkspaceTrustState.Trusted);
}, true);
const testObject = new ExtHostConfigProvider(
new class extends mock<MainThreadConfigurationShape>() { },
extHostWorkspace,
@@ -395,7 +394,7 @@ suite('ExtHostConfiguration', function () {
'id': 'foo',
'folders': [aWorkspaceFolder(firstRoot, 0), aWorkspaceFolder(secondRoot, 1)],
'name': 'foo'
}, WorkspaceTrustState.Trusted);
}, true);
const testObject = new ExtHostConfigProvider(
new class extends mock<MainThreadConfigurationShape>() { },
extHostWorkspace,
@@ -498,7 +497,7 @@ suite('ExtHostConfiguration', function () {
'id': 'foo',
'folders': [aWorkspaceFolder(firstRoot, 0), aWorkspaceFolder(secondRoot, 1)],
'name': 'foo'
}, WorkspaceTrustState.Trusted);
}, true);
const testObject = new ExtHostConfigProvider(
new class extends mock<MainThreadConfigurationShape>() { },
extHostWorkspace,
@@ -657,7 +656,7 @@ suite('ExtHostConfiguration', function () {
test('update/error-state not OK', function () {
const shape = new class extends mock<MainThreadConfigurationShape>() {
$updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): Promise<any> {
override $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): Promise<any> {
return Promise.reject(new Error('Unknown Key')); // something !== OK
}
};
@@ -676,7 +675,7 @@ suite('ExtHostConfiguration', function () {
'id': 'foo',
'folders': [workspaceFolder],
'name': 'foo'
}, WorkspaceTrustState.Trusted);
}, true);
const testObject = new ExtHostConfigProvider(
new class extends mock<MainThreadConfigurationShape>() { },
extHostWorkspace,
@@ -732,7 +731,7 @@ suite('ExtHostConfiguration', function () {
function toConfigurationModel(obj: any): ConfigurationModel {
const parser = new ConfigurationModelParser('test');
parser.parseContent(JSON.stringify(obj));
parser.parse(JSON.stringify(obj));
return parser.configurationModel;
}

View File

@@ -25,14 +25,14 @@ suite('ExtHostDecorations', function () {
providers.clear();
mainThreadShape = new class extends mock<MainThreadDecorationsShape>() {
$registerDecorationProvider(handle: number) {
override $registerDecorationProvider(handle: number) {
providers.add(handle);
}
};
extHostDecorations = new ExtHostDecorations(
new class extends mock<IExtHostRpcService>() {
getProxy(): any {
override getProxy(): any {
return mainThreadShape;
}
},

View File

@@ -18,10 +18,10 @@ import { nullExtensionDescription } from 'vs/workbench/services/extensions/commo
suite('ExtHostDiagnostics', () => {
class DiagnosticsShape extends mock<MainThreadDiagnosticsShape>() {
$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
override $changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
//
}
$clear(owner: string): void {
override $clear(owner: string): void {
//
}
}
@@ -164,7 +164,7 @@ suite('ExtHostDiagnostics', () => {
let lastEntries!: [UriComponents, IMarkerData[]][];
let collection = new DiagnosticCollection('test', 'test', 100, new class extends DiagnosticsShape {
$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
override $changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
lastEntries = entries;
return super.$changeMany(owner, entries);
}
@@ -198,7 +198,7 @@ suite('ExtHostDiagnostics', () => {
const emitter = new Emitter<any>();
emitter.event(_ => eventCount += 1);
const collection = new DiagnosticCollection('test', 'test', 100, new class extends DiagnosticsShape {
$changeMany() {
override $changeMany() {
changeCount += 1;
}
}, emitter);
@@ -263,7 +263,7 @@ suite('ExtHostDiagnostics', () => {
let lastEntries!: [UriComponents, IMarkerData[]][];
let collection = new DiagnosticCollection('test', 'test', 250, new class extends DiagnosticsShape {
$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
override $changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
lastEntries = entries;
return super.$changeMany(owner, entries);
}
@@ -350,7 +350,7 @@ suite('ExtHostDiagnostics', () => {
test('diagnostics with related information', function (done) {
let collection = new DiagnosticCollection('ddd', 'test', 100, new class extends DiagnosticsShape {
$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]) {
override $changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]) {
let [[, data]] = entries;
assert.strictEqual(entries.length, 1);
@@ -408,7 +408,7 @@ suite('ExtHostDiagnostics', () => {
test('Error updating diagnostics from extension #60394', function () {
let callCount = 0;
let collection = new DiagnosticCollection('ddd', 'test', 100, new class extends DiagnosticsShape {
$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]) {
override $changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]) {
callCount += 1;
}
}, new Emitter<any>());

View File

@@ -50,7 +50,7 @@ suite('ExtHostDocumentData', () => {
test('save, when disposed', function () {
let saved: URI;
let data = new ExtHostDocumentData(new class extends mock<MainThreadDocumentsShape>() {
$trySaveDocument(uri: URI) {
override $trySaveDocument(uri: URI) {
assert.ok(!saved);
saved = uri;
return Promise.resolve(true);
@@ -365,16 +365,16 @@ suite('ExtHostDocumentData updates line mapping', () => {
let line = 0, character = 0, previousIsCarriageReturn = false;
for (let offset = 0; offset <= allText.length; offset++) {
// The position coordinate system cannot express the position between \r and \n
const position = new Position(line, character + (previousIsCarriageReturn ? -1 : 0));
const position: Position = new Position(line, character + (previousIsCarriageReturn ? -1 : 0));
if (direction === AssertDocumentLineMappingDirection.OffsetToPosition) {
let actualPosition = doc.document.positionAt(offset);
assert.equal(positionToStr(actualPosition), positionToStr(position), 'positionAt mismatch for offset ' + offset);
assert.strictEqual(positionToStr(actualPosition), positionToStr(position), 'positionAt mismatch for offset ' + offset);
} else {
// The position coordinate system cannot express the position between \r and \n
let expectedOffset = offset + (previousIsCarriageReturn ? -1 : 0);
let expectedOffset: number = offset + (previousIsCarriageReturn ? -1 : 0);
let actualOffset = doc.document.offsetAt(position);
assert.equal(actualOffset, expectedOffset, 'offsetAt mismatch for position ' + positionToStr(position));
assert.strictEqual(actualOffset, expectedOffset, 'offsetAt mismatch for position ' + positionToStr(position));
}
if (allText.charAt(offset) === '\n') {

View File

@@ -379,7 +379,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
test('Log failing listener', function () {
let didLogSomething = false;
let participant = new ExtHostDocumentSaveParticipant(new class extends NullLogService {
error(message: string | Error, ...args: any[]): void {
override error(message: string | Error, ...args: any[]): void {
didLogSomething = true;
}
}, documents, mainThreadBulkEdits);

View File

@@ -268,7 +268,7 @@ suite('ExtHostLanguageFeatures', function () {
assert.strictEqual(value.length, 2);
});
test('Definition, registration order ignored (results are sorted)', async () => {
test('Definition, registration order', async () => {
disposables.push(extHost.registerDefinitionProvider(defaultExtension, defaultSelector, new class implements vscode.DefinitionProvider {
provideDefinition(): any {
@@ -286,8 +286,8 @@ suite('ExtHostLanguageFeatures', function () {
const value = await getDefinitionsAtPosition(model, new EditorPosition(1, 1), CancellationToken.None);
assert.strictEqual(value.length, 2);
// let [first, second] = value;
assert.strictEqual(value[0].uri.authority, 'first');
assert.strictEqual(value[1].uri.authority, 'second');
assert.strictEqual(value[0].uri.authority, 'second');
assert.strictEqual(value[1].uri.authority, 'first');
});
test('Definition, evil provider', async () => {
@@ -521,7 +521,7 @@ suite('ExtHostLanguageFeatures', function () {
// --- references
test('References, registration order ignored (results are sorted)', async () => {
test('References, registration order', async () => {
disposables.push(extHost.registerReferenceProvider(defaultExtension, defaultSelector, new class implements vscode.ReferenceProvider {
provideReferences(): any {
@@ -539,8 +539,8 @@ suite('ExtHostLanguageFeatures', function () {
let value = await getReferencesAtPosition(model, new EditorPosition(1, 2), false, CancellationToken.None);
assert.strictEqual(value.length, 2);
let [first, second] = value;
assert.strictEqual(first.uri.path, '/first');
assert.strictEqual(second.uri.path, '/second');
assert.strictEqual(first.uri.path, '/second');
assert.strictEqual(second.uri.path, '/first');
});
test('References, data conversion', async () => {
@@ -966,7 +966,7 @@ suite('ExtHostLanguageFeatures', function () {
// --- format
const NullWorkerService = new class extends mock<IEditorWorkerService>() {
computeMoreMinimalEdits(resource: URI, edits: modes.TextEdit[] | null | undefined): Promise<modes.TextEdit[] | undefined> {
override computeMoreMinimalEdits(resource: URI, edits: modes.TextEdit[] | null | undefined): Promise<modes.TextEdit[] | undefined> {
return Promise.resolve(withNullAsUndefined(edits));
}
};

View File

@@ -117,7 +117,7 @@ suite('ExtHostMessageService', function () {
suite('modal', () => {
test('calls dialog service', async () => {
const service = new MainThreadMessageService(null!, emptyNotificationService, emptyCommandService, new class extends mock<IDialogService>() {
show(severity: Severity, message: string, buttons: string[]) {
override show(severity: Severity, message: string, buttons: string[]) {
assert.strictEqual(severity, 1);
assert.strictEqual(message, 'h');
assert.strictEqual(buttons.length, 2);
@@ -132,7 +132,7 @@ suite('ExtHostMessageService', function () {
test('returns undefined when cancelled', async () => {
const service = new MainThreadMessageService(null!, emptyNotificationService, emptyCommandService, new class extends mock<IDialogService>() {
show() {
override show() {
return Promise.resolve({ choice: 1 });
}
} as IDialogService);
@@ -143,7 +143,7 @@ suite('ExtHostMessageService', function () {
test('hides Cancel button when not needed', async () => {
const service = new MainThreadMessageService(null!, emptyNotificationService, emptyCommandService, new class extends mock<IDialogService>() {
show(severity: Severity, message: string, buttons: string[]) {
override show(severity: Severity, message: string, buttons: string[]) {
assert.strictEqual(buttons.length, 1);
return Promise.resolve({ choice: 0 });
}

View File

@@ -41,20 +41,20 @@ suite('NotebookCell#Document', function () {
setup(async function () {
rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(MainContext.MainThreadCommands, new class extends mock<MainThreadCommandsShape>() {
$registerCommand() { }
override $registerCommand() { }
});
rpcProtocol.set(MainContext.MainThreadNotebook, new class extends mock<MainThreadNotebookShape>() {
async $registerNotebookProvider() { }
async $unregisterNotebookProvider() { }
override async $registerNotebookProvider() { }
override async $unregisterNotebookProvider() { }
});
extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
const extHostStoragePaths = new class extends mock<IExtensionStoragePaths>() {
workspaceValue() {
override workspaceValue() {
return URI.from({ scheme: 'test', path: generateUuid() });
}
};
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, extHostDocuments, { isExtensionDevelopmentDebug: false, webviewCspSource: '', webviewResourceRoot: '' }, new NullLogService(), extHostStoragePaths);
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, extHostDocuments, new NullLogService(), extHostStoragePaths);
let reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookContentProvider>() {
// async openNotebook() { }
});
@@ -100,26 +100,26 @@ suite('NotebookCell#Document', function () {
test('cell document is vscode.TextDocument', async function () {
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
assert.strictEqual(notebook.apiNotebook.cellCount, 2);
const [c1, c2] = notebook.notebookDocument.cells;
const [c1, c2] = notebook.apiNotebook.getCells();
const d1 = extHostDocuments.getDocument(c1.document.uri);
assert.ok(d1);
assert.strictEqual(d1.languageId, c1.document.languageId);
assert.strictEqual(d1.version, 1);
assert.ok(d1.notebook === notebook.notebookDocument);
assert.ok(d1.notebook === notebook.apiNotebook);
const d2 = extHostDocuments.getDocument(c2.document.uri);
assert.ok(d2);
assert.strictEqual(d2.languageId, c2.document.languageId);
assert.strictEqual(d2.version, 1);
assert.ok(d2.notebook === notebook.notebookDocument);
assert.ok(d2.notebook === notebook.apiNotebook);
});
test('cell document goes when notebook closes', async function () {
const cellUris: string[] = [];
for (let cell of notebook.notebookDocument.cells) {
for (let cell of notebook.apiNotebook.getCells()) {
assert.ok(extHostDocuments.getDocument(cell.document.uri));
cellUris.push(cell.document.uri.toString());
}
@@ -163,7 +163,7 @@ suite('NotebookCell#Document', function () {
});
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -196,7 +196,7 @@ suite('NotebookCell#Document', function () {
const docs: vscode.TextDocument[] = [];
const addData: IModelAddedData[] = [];
for (let cell of notebook.notebookDocument.cells) {
for (let cell of notebook.apiNotebook.getCells()) {
const doc = extHostDocuments.getDocument(cell.document.uri);
assert.ok(doc);
assert.strictEqual(extHostDocuments.getDocument(cell.document.uri).isClosed, false);
@@ -218,14 +218,14 @@ suite('NotebookCell#Document', function () {
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({ removedDocuments: docs.map(d => d.uri) });
// notebook is still open -> cell documents stay open
for (let cell of notebook.notebookDocument.cells) {
for (let cell of notebook.apiNotebook.getCells()) {
assert.ok(extHostDocuments.getDocument(cell.document.uri));
assert.strictEqual(extHostDocuments.getDocument(cell.document.uri).isClosed, false);
}
// close notebook -> docs are closed
extHostNotebooks.$acceptDocumentAndEditorsDelta({ removedDocuments: [notebook.uri] });
for (let cell of notebook.notebookDocument.cells) {
for (let cell of notebook.apiNotebook.getCells()) {
assert.throws(() => extHostDocuments.getDocument(cell.document.uri));
}
for (let doc of docs) {
@@ -235,8 +235,8 @@ suite('NotebookCell#Document', function () {
test('cell document goes when cell is removed', async function () {
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
const [cell1, cell2] = notebook.notebookDocument.cells;
assert.strictEqual(notebook.apiNotebook.cellCount, 2);
const [cell1, cell2] = notebook.apiNotebook.getCells();
extHostNotebooks.$acceptModelChanged(notebook.uri, {
versionId: 2,
@@ -248,7 +248,7 @@ suite('NotebookCell#Document', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1);
assert.strictEqual(notebook.apiNotebook.cellCount, 1);
assert.strictEqual(cell1.document.isClosed, true); // ref still alive!
assert.strictEqual(cell2.document.isClosed, false);
@@ -256,32 +256,32 @@ suite('NotebookCell#Document', function () {
});
test('cell document knows notebook', function () {
for (let cells of notebook.notebookDocument.cells) {
assert.strictEqual(cells.document.notebook === notebook.notebookDocument, true);
for (let cells of notebook.apiNotebook.getCells()) {
assert.strictEqual(cells.document.notebook === notebook.apiNotebook, true);
}
});
test('cell#index', function () {
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
const [first, second] = notebook.notebookDocument.cells;
assert.strictEqual(notebook.apiNotebook.cellCount, 2);
const [first, second] = notebook.apiNotebook.getCells();
assert.strictEqual(first.index, 0);
assert.strictEqual(second.index, 1);
// remove first cell
extHostNotebooks.$acceptModelChanged(notebook.uri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [{
kind: NotebookCellsChangeType.ModelChange,
changes: [[0, 1, []]]
}]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1);
assert.strictEqual(notebook.apiNotebook.cellCount, 1);
assert.strictEqual(second.index, 0);
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [{
kind: NotebookCellsChangeType.ModelChange,
changes: [[0, 0, [{
@@ -304,7 +304,7 @@ suite('NotebookCell#Document', function () {
}]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 3);
assert.strictEqual(notebook.apiNotebook.cellCount, 3);
assert.strictEqual(second.index, 2);
});
@@ -313,7 +313,7 @@ suite('NotebookCell#Document', function () {
const p = Event.toPromise(extHostNotebooks.onDidChangeNotebookCells);
// DON'T call this, make sure the cell-documents have not been created yet
// assert.strictEqual(notebook.notebookDocument.cells.length, 2);
// assert.strictEqual(notebook.notebookDocument.cellCount, 2);
extHostNotebooks.$acceptModelChanged(notebook.uri, {
versionId: 100,
@@ -339,11 +339,11 @@ suite('NotebookCell#Document', function () {
}]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
assert.strictEqual(notebook.apiNotebook.cellCount, 2);
const event = await p;
assert.strictEqual(event.document === notebook.notebookDocument, true);
assert.strictEqual(event.document === notebook.apiNotebook, true);
assert.strictEqual(event.changes.length, 1);
assert.strictEqual(event.changes[0].deletedCount, 2);
assert.strictEqual(event.changes[0].deletedItems[0].document.isClosed, true);
@@ -391,7 +391,7 @@ suite('NotebookCell#Document', function () {
test('change cell language triggers onDidChange events', async function () {
const [first] = notebook.notebookDocument.cells;
const first = notebook.apiNotebook.cellAt(0);
assert.strictEqual(first.document.languageId, 'markdown');

View File

@@ -38,20 +38,20 @@ suite('NotebookConcatDocument', function () {
rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(MainContext.MainThreadCommands, new class extends mock<MainThreadCommandsShape>() {
$registerCommand() { }
override $registerCommand() { }
});
rpcProtocol.set(MainContext.MainThreadNotebook, new class extends mock<MainThreadNotebookShape>() {
async $registerNotebookProvider() { }
async $unregisterNotebookProvider() { }
override async $registerNotebookProvider() { }
override async $unregisterNotebookProvider() { }
});
extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
const extHostStoragePaths = new class extends mock<IExtensionStoragePaths>() {
workspaceValue() {
override workspaceValue() {
return URI.from({ scheme: 'test', path: generateUuid() });
}
};
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, extHostDocuments, { isExtensionDevelopmentDebug: false, webviewCspSource: '', webviewResourceRoot: '' }, new NullLogService(), extHostStoragePaths);
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, extHostDocuments, new NullLogService(), extHostStoragePaths);
let reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookContentProvider>() {
// async openNotebook() { }
});
@@ -70,14 +70,12 @@ suite('NotebookConcatDocument', function () {
}],
versionId: 0
}],
addedEditors: [
{
documentUri: notebookUri,
id: '_notebook_editor_0',
selections: [{ start: 0, end: 1 }],
visibleRanges: []
}
]
addedEditors: [{
documentUri: notebookUri,
id: '_notebook_editor_0',
selections: [{ start: 0, end: 1 }],
visibleRanges: []
}]
});
extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: '_notebook_editor_0' });
@@ -89,7 +87,7 @@ suite('NotebookConcatDocument', function () {
});
test('empty', function () {
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assert.strictEqual(doc.getText(), '');
assert.strictEqual(doc.version, 0);
@@ -125,7 +123,7 @@ suite('NotebookConcatDocument', function () {
const cellUri2 = CellUri.generate(notebook.uri, 2);
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [{
kind: NotebookCellsChangeType.ModelChange,
changes: [[0, 0, [{
@@ -150,9 +148,9 @@ suite('NotebookConcatDocument', function () {
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assert.strictEqual(doc.contains(cellUri1), true);
assert.strictEqual(doc.contains(cellUri2), true);
@@ -162,7 +160,7 @@ suite('NotebookConcatDocument', function () {
test('location, position mapping', function () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -188,26 +186,26 @@ suite('NotebookConcatDocument', function () {
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(0, 0)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 3)));
assertLocation(doc, new Position(5, 11), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(2, 11)));
assertLocation(doc, new Position(5, 12), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(2, 11)), false); // don't check identity because position will be clamped
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(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
// UPDATE 1
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -223,18 +221,18 @@ suite('NotebookConcatDocument', function () {
}
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 1);
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.notebookDocument.cells[0].document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 2)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 12)), false); // clamped
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
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -251,18 +249,18 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2);
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.notebookDocument.cells[0].document.uri, new Position(0, 0)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 3)));
assertLocation(doc, new Position(5, 11), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(2, 11)));
assertLocation(doc, new Position(5, 12), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(2, 11)), false); // don't check identity because position will be clamped
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)
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -270,21 +268,21 @@ suite('NotebookConcatDocument', function () {
}
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 1);
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.notebookDocument.cells[0].document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 2)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 12)), false); // clamped
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(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
// UPDATE 1
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
@@ -309,21 +307,21 @@ suite('NotebookConcatDocument', function () {
}
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2);
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.notebookDocument.cells[0].document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 2)));
assertLocation(doc, new Position(2, 12), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 12)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cells[1].document.uri, new Position(1, 3)));
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.notebookDocument.cells[0].document.uri, {
extHostDocuments.$acceptModelChanged(notebook.apiNotebook.cellAt(0).document.uri, {
versionId: 0,
eol: '\n',
changes: [{
@@ -334,7 +332,7 @@ suite('NotebookConcatDocument', function () {
}]
}, false);
assertLines(doc, 'Hello', 'World', 'Hi World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocation(doc, new Position(2, 12), new Location(notebook.notebookDocument.cells[0].document.uri, new Position(2, 9)), false);
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);
@@ -343,7 +341,7 @@ suite('NotebookConcatDocument', function () {
test('selector', function () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -368,16 +366,16 @@ suite('NotebookConcatDocument', function () {
]
}, false);
const mixedDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
const fooLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, 'fooLang');
const barLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, 'barLang');
const mixedDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
const fooLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, 'fooLang');
const barLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, 'barLang');
assertLines(mixedDoc, 'fooLang-document', 'barLang-document');
assertLines(fooLangDoc, 'fooLang-document');
assertLines(barLangDoc, 'barLang-document');
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -415,7 +413,7 @@ suite('NotebookConcatDocument', function () {
test('offsetAt(position) <-> positionAt(offset)', function () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -440,9 +438,9 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertOffsetAtPosition(doc, 0, { line: 0, character: 0 });
@@ -472,7 +470,7 @@ suite('NotebookConcatDocument', function () {
test('locationAt(position) <-> positionAt(location)', function () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -497,23 +495,23 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocationAtPosition(doc, { line: 0, character: 0 }, { uri: notebook.notebookDocument.cells[0].document.uri, line: 0, character: 0 });
assertLocationAtPosition(doc, { line: 2, character: 0 }, { uri: notebook.notebookDocument.cells[0].document.uri, line: 2, character: 0 });
assertLocationAtPosition(doc, { line: 2, character: 12 }, { uri: notebook.notebookDocument.cells[0].document.uri, line: 2, character: 12 });
assertLocationAtPosition(doc, { line: 3, character: 0 }, { uri: notebook.notebookDocument.cells[1].document.uri, line: 0, character: 0 });
assertLocationAtPosition(doc, { line: 5, character: 0 }, { uri: notebook.notebookDocument.cells[1].document.uri, line: 2, character: 0 });
assertLocationAtPosition(doc, { line: 5, character: 11 }, { uri: notebook.notebookDocument.cells[1].document.uri, line: 2, character: 11 });
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 () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -538,9 +536,9 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assert.strictEqual(doc.getText(new Range(0, 0, 0, 0)), '');
@@ -551,7 +549,7 @@ suite('NotebookConcatDocument', function () {
test('validateRange/Position', function () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -576,9 +574,9 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');

View File

@@ -1,109 +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/test/browser/api/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 { 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 } from 'vs/workbench/contrib/notebook/common/notebookCommon';
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 { CancellationToken } from 'vs/base/common/cancellation';
suite('NotebookKernel', function () {
let rpcProtocol: TestRPCProtocol;
let notebook: ExtHostNotebookDocument;
let extHostDocumentsAndEditors: ExtHostDocumentsAndEditors;
let extHostDocuments: ExtHostDocuments;
let extHostNotebooks: ExtHostNotebookController;
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<MainThreadCommandsShape>() {
$registerCommand() { }
});
rpcProtocol.set(MainContext.MainThreadNotebook, new class extends mock<MainThreadNotebookShape>() {
async $registerNotebookProvider() { }
async $unregisterNotebookProvider() { }
async $registerNotebookKernelProvider() { }
async $unregisterNotebookKernelProvider() { }
});
extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
const extHostStoragePaths = new class extends mock<IExtensionStoragePaths>() {
workspaceValue() {
return URI.from({ scheme: 'test', path: generateUuid() });
}
};
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, extHostDocuments, { isExtensionDevelopmentDebug: false, webviewCspSource: '', webviewResourceRoot: '' }, new NullLogService(), extHostStoragePaths);
let reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookContentProvider>() {
// async openNotebook() { }
});
const kernels = [new class extends mock<vscode.NotebookKernel>() {
id = 'first';
}, new class extends mock<vscode.NotebookKernel>() {
id = 'second';
}];
let kernelReg = extHostNotebooks.registerNotebookKernelProvider(nullExtensionDescription, { viewType: 'test' }, new class extends mock<vscode.NotebookKernelProvider>() {
async provideKernels() { return kernels; }
});
// init
extHostNotebooks.$acceptDocumentAndEditorsDelta({
addedDocuments: [{
uri: notebookUri,
viewType: 'test',
cells: [{
handle: 0,
uri: CellUri.generate(notebookUri, 0),
source: ['console.log'],
eol: '\n',
language: 'javascript',
cellKind: CellKind.Code,
outputs: [],
}],
versionId: 0
}],
addedEditors: [
{
documentUri: notebookUri,
id: '_notebook_editor_0',
selections: [{ start: 0, end: 1 }],
visibleRanges: []
}
]
});
extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: '_notebook_editor_0' });
notebook = extHostNotebooks.notebookDocuments[0]!;
disposables.add(reg);
disposables.add(kernelReg);
disposables.add(notebook);
disposables.add(extHostDocuments);
});
test('provide kernels', async function () {
const dto = await extHostNotebooks.$provideNotebookKernels(0, notebook.uri, CancellationToken.None);
assert.deepStrictEqual(dto.map(kernel => kernel.id), ['first', 'second']);
});
});

View File

@@ -0,0 +1,96 @@
/*---------------------------------------------------------------------------------------------
* 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/test/browser/api/testRPCProtocol';
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { mock } from 'vs/workbench/test/common/workbenchTestServices';
import { INotebookKernelDto2, MainContext, MainThreadCommandsShape, MainThreadNotebookKernelsShape } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostNotebookKernels } from 'vs/workbench/api/common/extHostNotebookKernels';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
suite('NotebookKernel', function () {
let rpcProtocol: TestRPCProtocol;
let extHostNotebookKernels: ExtHostNotebookKernels;
const kernelData = new Map<number, INotebookKernelDto2>();
setup(async function () {
kernelData.clear();
rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(MainContext.MainThreadCommands, new class extends mock<MainThreadCommandsShape>() {
override $registerCommand() { }
});
rpcProtocol.set(MainContext.MainThreadNotebookKernels, new class extends mock<MainThreadNotebookKernelsShape>() {
override async $addKernel(handle: number, data: INotebookKernelDto2): Promise<void> {
kernelData.set(handle, data);
}
override $removeKernel(handle: number) {
kernelData.delete(handle);
}
override $updateKernel(handle: number, data: Partial<INotebookKernelDto2>) {
assert.strictEqual(kernelData.has(handle), true);
kernelData.set(handle, { ...kernelData.get(handle)!, ...data, });
}
});
extHostNotebookKernels = new ExtHostNotebookKernels(
rpcProtocol,
new class extends mock<IExtHostInitDataService>() { },
new class extends mock<ExtHostNotebookController>() { }
);
});
test('create/dispose kernel', async function () {
const kernel = extHostNotebookKernels.createNotebookController(nullExtensionDescription, 'foo', '*', 'Foo');
assert.throws(() => (<any>kernel).id = 'dd');
assert.throws(() => (<any>kernel).viewType = 'dd');
assert.ok(kernel);
assert.strictEqual(kernel.id, 'foo');
assert.strictEqual(kernel.label, 'Foo');
assert.strictEqual(kernel.viewType, '*');
await rpcProtocol.sync();
assert.strictEqual(kernelData.size, 1);
let [first] = kernelData.values();
assert.strictEqual(first.id, 'nullExtensionDescription/foo');
assert.strictEqual(ExtensionIdentifier.equals(first.extensionId, nullExtensionDescription.identifier), true);
assert.strictEqual(first.label, 'Foo');
assert.strictEqual(first.viewType, '*');
kernel.dispose();
await rpcProtocol.sync();
assert.strictEqual(kernelData.size, 0);
});
test('update kernel', async function () {
const kernel = extHostNotebookKernels.createNotebookController(nullExtensionDescription, 'foo', '*', 'Foo');
await rpcProtocol.sync();
assert.ok(kernel);
let [first] = kernelData.values();
assert.strictEqual(first.id, 'nullExtensionDescription/foo');
assert.strictEqual(first.label, 'Foo');
kernel.label = 'Far';
assert.strictEqual(kernel.label, 'Far');
await rpcProtocol.sync();
[first] = kernelData.values();
assert.strictEqual(first.id, 'nullExtensionDescription/foo');
assert.strictEqual(first.label, 'Far');
});
});

View File

@@ -4,13 +4,16 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { CancellationToken } from 'vs/base/common/cancellation';
import { URI } from 'vs/base/common/uri';
import { createDefaultDocumentTestRoot, TestItemFilteredWrapper } from 'vs/workbench/api/common/extHostTesting';
import * as convert from 'vs/workbench/api/common/extHostTypeConverters';
import { TestDiffOpType, TestItemExpandState } from 'vs/workbench/contrib/testing/common/testCollection';
import { stubTest, testStubs } from 'vs/workbench/contrib/testing/common/testStubs';
import { stubTest, TestItemImpl, testStubs } from 'vs/workbench/contrib/testing/common/testStubs';
import { TestOwnedTestCollection, TestSingleUseCollection } from 'vs/workbench/contrib/testing/test/common/ownedTestCollection';
import { TestItem } from 'vscode';
import { TestItem, TextDocument } from 'vscode';
const simplify = (item: TestItem) => ({
const simplify = (item: TestItem<unknown>) => ({
id: item.id,
label: item.label,
uri: item.uri,
@@ -19,13 +22,21 @@ const simplify = (item: TestItem) => ({
debuggable: item.debuggable,
});
const assertTreesEqual = (a: TestItem, b: TestItem) => {
const assertTreesEqual = (a: TestItem<unknown> | undefined, b: TestItem<unknown> | undefined) => {
if (!a) {
throw new assert.AssertionError({ message: 'Expected a to be defined', actual: a });
}
if (!b) {
throw new assert.AssertionError({ message: 'Expected b to be defined', actual: b });
}
assert.deepStrictEqual(simplify(a), simplify(b));
const aChildren = [...a.children].slice().sort();
const bChildren = [...b.children].slice().sort();
const aChildren = [...a.children.keys()].slice().sort();
const bChildren = [...b.children.keys()].slice().sort();
assert.strictEqual(aChildren.length, bChildren.length, `expected ${a.label}.children.length == ${b.label}.children.length`);
aChildren.forEach((_, i) => assertTreesEqual(aChildren[i], bChildren[i]));
aChildren.forEach(key => assertTreesEqual(a.children.get(key), b.children.get(key)));
};
// const assertTreeListEqual = (a: ReadonlyArray<TestItem>, b: ReadonlyArray<TestItem>) => {
@@ -67,15 +78,15 @@ suite('ExtHost Testing', () => {
assert.deepStrictEqual(single.collectDiff(), [
[
TestDiffOpType.Add,
{ src: { tree: 0, provider: 'pid' }, parent: null, expand: TestItemExpandState.BusyExpanding, item: { ...convert.TestItem.from(stubTest('root')), expandable: true } }
{ src: { tree: 0, controller: 'pid' }, parent: null, expand: TestItemExpandState.BusyExpanding, item: { ...convert.TestItem.from(stubTest('root')) } }
],
[
TestDiffOpType.Add,
{ src: { tree: 0, provider: 'pid' }, parent: 'id-root', expand: TestItemExpandState.Expandable, item: { ...convert.TestItem.from(stubTest('a')), expandable: true } }
{ src: { tree: 0, controller: 'pid' }, parent: 'id-root', expand: TestItemExpandState.Expandable, item: { ...convert.TestItem.from(stubTest('a')) } }
],
[
TestDiffOpType.Add,
{ src: { tree: 0, provider: 'pid' }, parent: 'id-root', expand: TestItemExpandState.NotExpandable, item: convert.TestItem.from(stubTest('b')) }
{ src: { tree: 0, controller: 'pid' }, parent: 'id-root', expand: TestItemExpandState.NotExpandable, item: convert.TestItem.from(stubTest('b')) }
],
[
TestDiffOpType.Update,
@@ -87,11 +98,11 @@ suite('ExtHost Testing', () => {
],
[
TestDiffOpType.Add,
{ src: { tree: 0, provider: 'pid' }, parent: 'id-a', expand: TestItemExpandState.NotExpandable, item: convert.TestItem.from(stubTest('aa')) }
{ src: { tree: 0, controller: 'pid' }, parent: 'id-a', expand: TestItemExpandState.NotExpandable, item: convert.TestItem.from(stubTest('aa')) }
],
[
TestDiffOpType.Add,
{ src: { tree: 0, provider: 'pid' }, parent: 'id-a', expand: TestItemExpandState.NotExpandable, item: convert.TestItem.from(stubTest('ab')) }
{ src: { tree: 0, controller: 'pid' }, parent: 'id-a', expand: TestItemExpandState.NotExpandable, item: convert.TestItem.from(stubTest('ab')) }
],
[
TestDiffOpType.Update,
@@ -126,7 +137,7 @@ suite('ExtHost Testing', () => {
single.addRoot(tests, 'pid');
single.expand('id-root', Infinity);
single.collectDiff();
tests.children.delete('id-a');
tests.children.get('id-a')!.dispose();
assert.deepStrictEqual(single.collectDiff(), [
[TestDiffOpType.Remove, 'id-a'],
@@ -141,11 +152,11 @@ suite('ExtHost Testing', () => {
single.expand('id-root', Infinity);
single.collectDiff();
const child = stubTest('ac');
tests.children.get('id-a')!.children!.add(child);
tests.children.get('id-a')!.addChild(child);
assert.deepStrictEqual(single.collectDiff(), [
[TestDiffOpType.Add, {
src: { tree: 0, provider: 'pid' },
src: { tree: 0, controller: 'pid' },
parent: 'id-a',
expand: TestItemExpandState.NotExpandable,
item: convert.TestItem.from(child),
@@ -160,284 +171,256 @@ suite('ExtHost Testing', () => {
});
// todo@connor4312: re-renable when we figure out what observing looks like we async children
// suite('MirroredTestCollection', () => {
// let m: TestMirroredCollection;
// setup(() => m = new TestMirroredCollection());
suite('MirroredTestCollection', () => {
// todo@connor4312: re-renable when we figure out what observing looks like we async children
// let m: TestMirroredCollection;
// setup(() => m = new TestMirroredCollection());
// test('mirrors creation of the root', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// single.expand('id-root', Infinity);
// m.apply(single.collectDiff());
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// assert.strictEqual(m.length, single.itemToInternal.size);
// });
// test('mirrors creation of the root', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// single.expand('id-root', Infinity);
// m.apply(single.collectDiff());
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// assert.strictEqual(m.length, single.itemToInternal.size);
// });
// test('mirrors node deletion', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// single.expand('id-root', Infinity);
// tests.children!.splice(0, 1);
// single.onItemChange(tests, 'pid');
// single.expand('id-root', Infinity);
// m.apply(single.collectDiff());
// test('mirrors node deletion', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// single.expand('id-root', Infinity);
// tests.children!.splice(0, 1);
// single.onItemChange(tests, 'pid');
// single.expand('id-root', Infinity);
// m.apply(single.collectDiff());
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// assert.strictEqual(m.length, single.itemToInternal.size);
// });
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// assert.strictEqual(m.length, single.itemToInternal.size);
// });
// test('mirrors node addition', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// tests.children![0].children!.push(stubTest('ac'));
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// test('mirrors node addition', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// tests.children![0].children!.push(stubTest('ac'));
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// assert.strictEqual(m.length, single.itemToInternal.size);
// });
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// assert.strictEqual(m.length, single.itemToInternal.size);
// });
// test('mirrors node update', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// tests.children![0].description = 'Hello world'; /* item a */
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// test('mirrors node update', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// tests.children![0].description = 'Hello world'; /* item a */
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// });
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// });
// suite('MirroredChangeCollector', () => {
// let tests = testStubs.nested();
// setup(() => {
// tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// });
// suite('MirroredChangeCollector', () => {
// let tests = testStubs.nested();
// setup(() => {
// tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// });
// test('creates change for root', () => {
// assertTreeListEqual(m.changeEvent.added, [
// tests,
// tests.children[0],
// tests.children![0].children![0],
// tests.children![0].children![1],
// tests.children[1],
// ]);
// assertTreeListEqual(m.changeEvent.removed, []);
// assertTreeListEqual(m.changeEvent.updated, []);
// });
// test('creates change for root', () => {
// assertTreeListEqual(m.changeEvent.added, [
// tests,
// tests.children[0],
// tests.children![0].children![0],
// tests.children![0].children![1],
// tests.children[1],
// ]);
// assertTreeListEqual(m.changeEvent.removed, []);
// assertTreeListEqual(m.changeEvent.updated, []);
// });
// test('creates change for delete', () => {
// const rm = tests.children.shift()!;
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// test('creates change for delete', () => {
// const rm = tests.children.shift()!;
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// assertTreeListEqual(m.changeEvent.added, []);
// assertTreeListEqual(m.changeEvent.removed, [
// { ...rm },
// { ...rm.children![0] },
// { ...rm.children![1] },
// ]);
// assertTreeListEqual(m.changeEvent.updated, []);
// });
// assertTreeListEqual(m.changeEvent.added, []);
// assertTreeListEqual(m.changeEvent.removed, [
// { ...rm },
// { ...rm.children![0] },
// { ...rm.children![1] },
// ]);
// assertTreeListEqual(m.changeEvent.updated, []);
// });
// test('creates change for update', () => {
// tests.children[0].label = 'updated!';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// test('creates change for update', () => {
// tests.children[0].label = 'updated!';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// assertTreeListEqual(m.changeEvent.added, []);
// assertTreeListEqual(m.changeEvent.removed, []);
// assertTreeListEqual(m.changeEvent.updated, [tests.children[0]]);
// });
// assertTreeListEqual(m.changeEvent.added, []);
// assertTreeListEqual(m.changeEvent.removed, []);
// assertTreeListEqual(m.changeEvent.updated, [tests.children[0]]);
// });
// test('is a no-op if a node is added and removed', () => {
// const nested = testStubs.nested('id2-');
// tests.children.push(nested);
// single.onItemChange(tests, 'pid');
// tests.children.pop();
// single.onItemChange(tests, 'pid');
// const previousEvent = m.changeEvent;
// m.apply(single.collectDiff());
// assert.strictEqual(m.changeEvent, previousEvent);
// });
// test('is a no-op if a node is added and removed', () => {
// const nested = testStubs.nested('id2-');
// tests.children.push(nested);
// single.onItemChange(tests, 'pid');
// tests.children.pop();
// single.onItemChange(tests, 'pid');
// const previousEvent = m.changeEvent;
// m.apply(single.collectDiff());
// assert.strictEqual(m.changeEvent, previousEvent);
// });
// test('is a single-op if a node is added and changed', () => {
// const child = stubTest('c');
// tests.children.push(child);
// single.onItemChange(tests, 'pid');
// child.label = 'd';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// test('is a single-op if a node is added and changed', () => {
// const child = stubTest('c');
// tests.children.push(child);
// single.onItemChange(tests, 'pid');
// child.label = 'd';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// assertTreeListEqual(m.changeEvent.added, [child]);
// assertTreeListEqual(m.changeEvent.removed, []);
// assertTreeListEqual(m.changeEvent.updated, []);
// });
// assertTreeListEqual(m.changeEvent.added, [child]);
// assertTreeListEqual(m.changeEvent.removed, []);
// assertTreeListEqual(m.changeEvent.updated, []);
// });
// test('gets the common ancestor (1)', () => {
// tests.children![0].children![0].label = 'za';
// tests.children![0].children![1].label = 'zb';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// test('gets the common ancestor (1)', () => {
// tests.children![0].children![0].label = 'za';
// tests.children![0].children![1].label = 'zb';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// });
// });
// test('gets the common ancestor (2)', () => {
// tests.children![0].children![0].label = 'za';
// tests.children![1].label = 'ab';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// });
// });
// test('gets the common ancestor (2)', () => {
// tests.children![0].children![0].label = 'za';
// tests.children![1].label = 'ab';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// });
// });
// suite('TestItemFilteredWrapper', () => {
// const stubTestWithLocation = (label: string, location: Location, children: StubTestItem[] = []) => {
// const t = stubTest(label, undefined, children);
// t.location = location as any;
// return t;
// };
suite('TestItemFilteredWrapper', () => {
const textDocumentFilter = {
uri: URI.parse('file:///foo.ts'),
} as TextDocument;
// const location1: Location = {
// range: new Range(0, 0, 0, 0),
// uri: URI.parse('file:///foo.ts')
// };
let testsWithLocation: TestItemImpl;
setup(async () => {
testsWithLocation =
stubTest('root', undefined, [
stubTest('a', undefined, [
stubTest('aa', undefined, undefined, URI.parse('file:///foo.ts')),
stubTest('ab', undefined, undefined, URI.parse('file:///foo.ts'))
], URI.parse('file:///foo.ts')),
stubTest('b', undefined, [
stubTest('ba', undefined, undefined, URI.parse('file:///bar.ts')),
stubTest('bb', undefined, undefined, URI.parse('file:///bar.ts'))
], URI.parse('file:///bar.ts')),
stubTest('c', undefined, undefined, URI.parse('file:///baz.ts')),
]);
// const location2: Location = {
// range: new Range(0, 0, 0, 0),
// uri: URI.parse('file:///bar.ts')
// };
// todo: this is not used, don't think it's needed anymore
await createDefaultDocumentTestRoot<void>(
{
createWorkspaceTestRoot: () => testsWithLocation as TestItem<void>,
runTests() {
throw new Error('no implemented');
}
},
textDocumentFilter,
undefined,
CancellationToken.None
);
});
// const location3: Location = {
// range: new Range(0, 0, 0, 0),
// uri: URI.parse('file:///baz.ts')
// };
teardown(() => {
TestItemFilteredWrapper.removeFilter(textDocumentFilter);
});
// const textDocumentFilter = {
// uri: location1.uri
// } as TextDocument;
test('gets all actual properties', () => {
const testItem = stubTest('test1');
const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(testItem, textDocumentFilter);
// let testsWithLocation: StubTestItem;
// let hierarchy: TestHierarchy<TestItemFilteredWrapper>;
// setup(async () => {
// testsWithLocation =
// stubTest('root', undefined, [
// stubTestWithLocation('a', location1, [stubTestWithLocation('aa', location1), stubTestWithLocation('ab', location1)]),
// stubTestWithLocation('b', location2, [stubTestWithLocation('ba', location2), stubTestWithLocation('bb', location2)]),
// stubTestWithLocation('b', location3),
// ]);
assert.strictEqual(testItem.debuggable, wrapper.debuggable);
assert.strictEqual(testItem.description, wrapper.description);
assert.strictEqual(testItem.label, wrapper.label);
assert.strictEqual(testItem.uri, wrapper.uri);
assert.strictEqual(testItem.runnable, wrapper.runnable);
});
// hierarchy = (await createDefaultDocumentTestHierarchy<StubTestItem>(
// {
// provideWorkspaceTestHierarchy: () => ({
// getChildren.getChildren,
// getParent.getParent,
// onDidChangeTest: new Emitter<StubTestItem>().event,
// root: testsWithLocation
// }),
// runTests() {
// throw new Error('no implemented');
// }
// },
// textDocumentFilter,
// undefined,
// CancellationToken.None
// ))!;
// });
test('gets no children if nothing matches Uri filter', () => {
const tests = testStubs.nested();
const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(tests, textDocumentFilter);
wrapper.resolveHandler?.(CancellationToken.None);
assert.strictEqual(wrapper.children.size, 0);
});
// teardown(() => {
// TestItemFilteredWrapper.removeFilter(textDocumentFilter);
// });
test('filter is applied to children', () => {
const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
assert.strictEqual(wrapper.label, 'root');
wrapper.resolveHandler?.(CancellationToken.None);
// test('gets all actual properties', () => {
// const testItem: TestItem = stubTest('test1');
// const wrapper: TestItemFilteredWrapper = TestItemFilteredWrapper.getWrapperForTestItem(testItem, textDocumentFilter);
const children = [...wrapper.children.values()];
assert.strictEqual(children.length, 1);
assert.strictEqual(children[0] instanceof TestItemFilteredWrapper, true);
assert.strictEqual(children[0].label, 'a');
});
// assert.strictEqual(testItem.debuggable, wrapper.debuggable);
// assert.strictEqual(testItem.description, wrapper.description);
// assert.strictEqual(testItem.label, wrapper.label);
// assert.strictEqual(testItem.location, wrapper.location);
// assert.strictEqual(testItem.runnable, wrapper.runnable);
// });
test('can get if node has matching filter', () => {
const rootWrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
rootWrapper.resolveHandler?.(CancellationToken.None);
// test('gets no children if nothing matches Uri filter', () => {
// let tests: TestItem = testStubs.nested();
// const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(tests, textDocumentFilter);
// const children = hierarchy.getChildren(wrapper, CancellationToken.None) as TestItemFilteredWrapper[];
// assert.strictEqual(children.length, 0);
// });
const invisible = testsWithLocation.children.get('id-b')!;
const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
const visible = testsWithLocation.children.get('id-a')!;
const visibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(visible, textDocumentFilter);
// test('filter is applied to children', () => {
// const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
// assert.strictEqual(wrapper.label, 'root');
// const children = hierarchy.getChildren(wrapper, CancellationToken.None) as TestItemFilteredWrapper[];
// assert.strictEqual(children.length, 1);
// assert.strictEqual(children[0] instanceof TestItemFilteredWrapper, true);
// assert.strictEqual(children[0].label, 'a');
// });
// The root is always visible
assert.strictEqual(rootWrapper.hasNodeMatchingFilter, true);
assert.strictEqual(invisibleWrapper.hasNodeMatchingFilter, false);
assert.strictEqual(visibleWrapper.hasNodeMatchingFilter, true);
});
// test('can get if node has matching filter', () => {
// const rootWrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
test('can reset cached value of hasNodeMatchingFilter', () => {
const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
wrapper.resolveHandler?.(CancellationToken.None);
// const invisible = testsWithLocation.children![1];
// const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
// const visible = testsWithLocation.children![0];
// const visibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(visible, textDocumentFilter);
const invisible = testsWithLocation.children.get('id-b')!;
const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
// // The root is always visible
// assert.strictEqual(rootWrapper.hasNodeMatchingFilter, true);
// assert.strictEqual(invisibleWrapper.hasNodeMatchingFilter, false);
// assert.strictEqual(visibleWrapper.hasNodeMatchingFilter, true);
// });
assert.strictEqual(wrapper.children.get('id-b'), undefined);
assert.strictEqual(invisibleWrapper.hasNodeMatchingFilter, false);
// test('can get visible parent', () => {
// const rootWrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
invisible.addChild(stubTest('bc', undefined, undefined, URI.parse('file:///foo.ts')));
assert.strictEqual(invisibleWrapper.hasNodeMatchingFilter, true);
assert.strictEqual(invisibleWrapper.children.size, 1);
assert.strictEqual(wrapper.children.get('id-b'), invisibleWrapper);
});
// const invisible = testsWithLocation.children![1];
// const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
// const visible = testsWithLocation.children![0];
// const visibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(visible, textDocumentFilter);
// test('can reset cached value of hasNodeMatchingFilter of parents up to visible parent', () => {
// const rootWrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
// // The root is always visible
// assert.strictEqual(rootWrapper.visibleParent, rootWrapper);
// assert.strictEqual(invisibleWrapper.visibleParent, rootWrapper);
// assert.strictEqual(visibleWrapper.visibleParent, visibleWrapper);
// });
// const invisibleParent = testsWithLocation.children.get('id-b')!;
// const invisibleParentWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisibleParent, textDocumentFilter);
// const invisible = invisibleParent.children.get('id-bb')!;
// const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
// test('can reset cached value of hasNodeMatchingFilter', () => {
// TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
// assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, false);
// invisible.location = location1 as any;
// assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, false);
// invisibleWrapper.reset();
// assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, true);
// const invisible = testsWithLocation.children![1];
// const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
// assert.strictEqual(invisibleWrapper.hasNodeMatchingFilter, false);
// invisible.location = location1 as any;
// assert.strictEqual(invisibleWrapper.hasNodeMatchingFilter, false);
// invisibleWrapper.reset();
// assert.strictEqual(invisibleWrapper.hasNodeMatchingFilter, true);
// });
// test('can reset cached value of hasNodeMatchingFilter of parents up to visible parent', () => {
// const rootWrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
// const invisibleParent = testsWithLocation.children![1];
// const invisibleParentWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisibleParent, textDocumentFilter);
// const invisible = invisibleParent.children![1];
// const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
// assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, false);
// invisible.location = location1 as any;
// assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, false);
// invisibleWrapper.reset();
// assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, true);
// // the root should be undefined due to the reset.
// assert.strictEqual((rootWrapper as any).matchesFilter, undefined);
// });
// });
// });
// // the root should be undefined due to the reset.
// assert.strictEqual((rootWrapper as any).matchesFilter, undefined);
// });
});
});
});

View File

@@ -44,7 +44,7 @@ suite('ExtHostTextEditor', () => {
let applyCount = 0;
let editor = new ExtHostTextEditor('edt1',
new class extends mock<MainThreadTextEditorsShape>() {
$tryApplyEdits(): Promise<boolean> {
override $tryApplyEdits(): Promise<boolean> {
applyCount += 1;
return Promise.resolve(true);
}

View File

@@ -26,16 +26,16 @@ suite('ExtHostTreeView', function () {
onRefresh = new Emitter<{ [treeItemHandle: string]: ITreeItem }>();
async $registerTreeViewDataProvider(treeViewId: string): Promise<void> {
override async $registerTreeViewDataProvider(treeViewId: string): Promise<void> {
}
$refresh(viewId: string, itemsToRefresh: { [treeItemHandle: string]: ITreeItem }): Promise<void> {
override $refresh(viewId: string, itemsToRefresh: { [treeItemHandle: string]: ITreeItem }): Promise<void> {
return Promise.resolve(null).then(() => {
this.onRefresh.fire(itemsToRefresh);
});
}
$reveal(): Promise<void> {
override $reveal(): Promise<void> {
return Promise.resolve();
}

View File

@@ -651,10 +651,6 @@ suite('ExtHostTypes', function () {
test('NotebookMetadata - defaults', function () {
const obj = new types.NotebookDocumentMetadata();
assert.strictEqual(obj.cellEditable, notebookDocumentMetadataDefaults.cellEditable);
assert.strictEqual(obj.cellHasExecutionOrder, notebookDocumentMetadataDefaults.cellHasExecutionOrder);
assert.deepStrictEqual(obj.custom, notebookDocumentMetadataDefaults.custom);
assert.strictEqual(obj.editable, notebookDocumentMetadataDefaults.editable);
assert.strictEqual(obj.trusted, notebookDocumentMetadataDefaults.trusted);
});
@@ -668,18 +664,42 @@ suite('ExtHostTypes', function () {
assert.strictEqual(newObj.trusted, false);
});
test('NotebookCellMetadata - with', function () {
const obj = new types.NotebookCellMetadata(true, false, true);
const newObj = obj.with({ statusMessage: 'hello' });
test('NotebookMetadata - with custom', function () {
const obj = new types.NotebookDocumentMetadata();
const newObj = obj.with({ trusted: false, mycustom: { display: 'hello' } });
assert.ok(obj !== newObj);
assert.strictEqual(obj.statusMessage, undefined);
assert.strictEqual(obj.editable, true);
const sameObj = newObj.with({ trusted: false });
assert.ok(newObj === sameObj);
assert.strictEqual(obj.trusted, true);
assert.strictEqual(newObj.trusted, false);
assert.deepStrictEqual(newObj.mycustom, { display: 'hello' });
});
test('NotebookCellMetadata - with', function () {
const obj = new types.NotebookCellMetadata(true, true);
const newObj = obj.with({ inputCollapsed: false });
assert.ok(obj !== newObj);
assert.strictEqual(obj.inputCollapsed, true);
assert.strictEqual(obj.custom, undefined);
assert.strictEqual(newObj.statusMessage, 'hello');
assert.strictEqual(newObj.editable, true);
assert.strictEqual(newObj.inputCollapsed, false);
assert.strictEqual(newObj.custom, undefined);
});
test('NotebookCellMetadata - with custom', function () {
const obj = new types.NotebookCellMetadata(true, true);
const newObj = obj.with({ inputCollapsed: false, custom: { display: 'hello' } });
assert.ok(obj !== newObj);
const sameObj = newObj.with({ inputCollapsed: false });
assert.ok(newObj === sameObj);
assert.strictEqual(obj.inputCollapsed, true);
assert.strictEqual(newObj.inputCollapsed, false);
assert.deepStrictEqual(newObj.custom, { display: 'hello' });
const newCustom = newObj.with({ anotherCustom: { display: 'hello2' } });
assert.strictEqual(newCustom.inputCollapsed, false);
assert.deepStrictEqual(newCustom.mycustom, undefined);
assert.deepStrictEqual(newCustom.anotherCustom, { display: 'hello2' });
});
});

View File

@@ -23,16 +23,15 @@ import { IPatternInfo } from 'vs/workbench/services/search/common/search';
import { isLinux, isWindows } from 'vs/base/common/platform';
import { IExtHostFileSystemInfo } from 'vs/workbench/api/common/extHostFileSystemInfo';
import { FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
import { WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust';
function createExtHostWorkspace(mainContext: IMainContext, data: IWorkspaceData, logService: ILogService): ExtHostWorkspace {
const result = new ExtHostWorkspace(
new ExtHostRpcService(mainContext),
new class extends mock<IExtHostInitDataService>() { workspace = data; },
new class extends mock<IExtHostFileSystemInfo>() { getCapabilities() { return isLinux ? FileSystemProviderCapabilities.PathCaseSensitive : undefined; } },
new class extends mock<IExtHostFileSystemInfo>() { override getCapabilities() { return isLinux ? FileSystemProviderCapabilities.PathCaseSensitive : undefined; } },
logService,
);
result.$initializeWorkspace(data, WorkspaceTrustState.Trusted);
result.$initializeWorkspace(data, true);
return result;
}
@@ -271,7 +270,7 @@ suite('ExtHostWorkspace', function () {
ws.$acceptWorkspaceData({ id: 'foo', name: 'Test', folders: [aWorkspaceFolderData(URI.parse('foo:bar3'), 0)] });
ws.$acceptWorkspaceData({ id: 'foo', name: 'Test', folders: [aWorkspaceFolderData(URI.parse('foo:bar3'), 0), aWorkspaceFolderData(URI.parse('foo:bar'), 1)] });
assert.notEqual(firstFolder, ws.workspace!.folders[0]);
assert.notStrictEqual(firstFolder, ws.workspace!.folders[0]);
});
test('updateWorkspaceFolders - invalid arguments', function () {
@@ -590,7 +589,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
$startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
override $startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
mainThreadCalled = true;
assert.strictEqual(includePattern, 'foo');
assert.strictEqual(_includeFolder, null);
@@ -612,7 +611,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
$startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
override $startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
mainThreadCalled = true;
assert.strictEqual(includePattern, 'glob/**');
assert.deepStrictEqual(_includeFolder ? URI.from(_includeFolder).toJSON() : null, URI.file('/other/folder').toJSON());
@@ -641,7 +640,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
$startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
override $startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
mainThreadCalled = true;
assert.strictEqual(includePattern, 'glob/**');
assert.deepStrictEqual(_includeFolder, URI.file('/other/folder').toJSON());
@@ -662,7 +661,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
$startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
override $startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
mainThreadCalled = true;
return Promise.resolve(null);
}
@@ -682,7 +681,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
$startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
override $startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
mainThreadCalled = true;
assert(excludePatternOrDisregardExcludes, 'glob/**'); // Note that the base portion is ignored, see #52651
return Promise.resolve(null);
@@ -701,7 +700,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
override async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
mainThreadCalled = true;
assert.strictEqual(query.pattern, 'foo');
assert.strictEqual(folder, null);
@@ -722,7 +721,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
override async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
mainThreadCalled = true;
assert.strictEqual(query.pattern, 'foo');
assert.strictEqual(folder, null);
@@ -743,7 +742,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
override async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
mainThreadCalled = true;
assert.strictEqual(query.pattern, 'foo');
assert.deepStrictEqual(folder, URI.file('/other/folder').toJSON());
@@ -764,7 +763,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
override async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
mainThreadCalled = true;
return null;
}
@@ -782,7 +781,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
override async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
mainThreadCalled = true;
assert.strictEqual(query.pattern, 'foo');
assert.deepStrictEqual(folder, null);

View File

@@ -51,13 +51,13 @@ suite('MainThreadCommands', function () {
const commands = new MainThreadCommands(
SingleProxyRPCProtocol(null),
new class extends mock<ICommandService>() {
executeCommand<T>(id: string): Promise<T | undefined> {
override executeCommand<T>(id: string): Promise<T | undefined> {
runs.push(id);
return Promise.resolve(undefined);
}
},
new class extends mock<IExtensionService>() {
activateByEvent(id: string) {
override activateByEvent(id: string) {
activations.push(id);
return Promise.resolve();
}

View File

@@ -38,7 +38,7 @@ suite('MainThreadDiagnostics', function () {
},
markerService,
new class extends mock<IUriIdentityService>() {
asCanonicalUri(uri: URI) { return uri; }
override asCanonicalUri(uri: URI) { return uri; }
}
);

View File

@@ -22,13 +22,13 @@ suite('MainThreadDocumentContentProviders', function () {
let providers = new MainThreadDocumentContentProviders(new TestRPCProtocol(), null!, null!,
new class extends mock<IModelService>() {
getModel(_uri: URI) {
override getModel(_uri: URI) {
assert.strictEqual(uri.toString(), _uri.toString());
return model;
}
},
new class extends mock<IEditorWorkerService>() {
computeMoreMinimalEdits(_uri: URI, data: TextEdit[] | undefined) {
override computeMoreMinimalEdits(_uri: URI, data: TextEdit[] | undefined) {
assert.strictEqual(model.getValue(), '1');
return Promise.resolve(data);
}

View File

@@ -57,8 +57,8 @@ suite('MainThreadDocumentsAndEditors', () => {
modelService = new ModelServiceImpl(configService, new TestTextResourcePropertiesService(configService), new TestThemeService(), new NullLogService(), undoRedoService);
codeEditorService = new TestCodeEditorService();
textFileService = new class extends mock<ITextFileService>() {
isDirty() { return false; }
files = <any>{
override isDirty() { return false; }
override files = <any>{
onDidSave: Event.None,
onDidRevert: Event.None,
onDidChangeDirty: Event.None
@@ -68,14 +68,14 @@ suite('MainThreadDocumentsAndEditors', () => {
const editorGroupService = new TestEditorGroupsService();
const fileService = new class extends mock<IFileService>() {
onDidRunOperation = Event.None;
onDidChangeFileSystemProviderCapabilities = Event.None;
onDidChangeFileSystemProviderRegistrations = Event.None;
override onDidRunOperation = Event.None;
override onDidChangeFileSystemProviderCapabilities = Event.None;
override onDidChangeFileSystemProviderRegistrations = Event.None;
};
new MainThreadDocumentsAndEditors(
SingleProxyRPCProtocol(new class extends mock<ExtHostDocumentsAndEditorsShape>() {
$acceptDocumentsAndEditorsDelta(delta: IDocumentsAndEditorsDelta) { deltas.push(delta); }
override $acceptDocumentsAndEditorsDelta(delta: IDocumentsAndEditorsDelta) { deltas.push(delta); }
}),
modelService,
textFileService,
@@ -86,10 +86,9 @@ suite('MainThreadDocumentsAndEditors', () => {
editorGroupService,
null!,
new class extends mock<IPanelService>() implements IPanelService {
declare readonly _serviceBrand: undefined;
onDidPanelOpen = Event.None;
onDidPanelClose = Event.None;
getActivePanel() {
override onDidPanelOpen = Event.None;
override onDidPanelClose = Event.None;
override getActivePanel() {
return undefined;
}
},
@@ -97,7 +96,7 @@ suite('MainThreadDocumentsAndEditors', () => {
new TestWorkingCopyFileService(),
new UriIdentityService(fileService),
new class extends mock<IClipboardService>() {
readText() {
override readText() {
return Promise.resolve('clipboard_contents');
}
},

View File

@@ -51,7 +51,6 @@ import { TestTextResourcePropertiesService, TestContextService } from 'vs/workbe
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
import { extUri } from 'vs/base/common/resources';
import { ITextSnapshot } from 'vs/editor/common/model';
import { VSBuffer, VSBufferReadable } from 'vs/base/common/buffer';
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
@@ -100,44 +99,44 @@ suite('MainThreadEditors', () => {
services.set(ILifecycleService, new TestLifecycleService());
services.set(IEditorGroupsService, new TestEditorGroupsService());
services.set(ITextFileService, new class extends mock<ITextFileService>() {
isDirty() { return false; }
files = <any>{
override isDirty() { return false; }
override files = <any>{
onDidSave: Event.None,
onDidRevert: Event.None,
onDidChangeDirty: Event.None
};
create(operations: { resource: URI }[]) {
override create(operations: { resource: URI }[]) {
for (const o of operations) {
createdResources.add(o.resource);
}
return Promise.resolve(Object.create(null));
}
async getEncodedReadable(resource: URI, value?: string | ITextSnapshot): Promise<VSBuffer | VSBufferReadable | undefined> {
override async getEncodedReadable(resource: URI, value?: string | ITextSnapshot): Promise<any> {
return undefined;
}
});
services.set(IWorkingCopyFileService, new class extends mock<IWorkingCopyFileService>() {
onDidRunWorkingCopyFileOperation = Event.None;
createFolder(operations: ICreateOperation[]): any {
override onDidRunWorkingCopyFileOperation = Event.None;
override createFolder(operations: ICreateOperation[]): any {
this.create(operations);
}
create(operations: ICreateFileOperation[]) {
override create(operations: ICreateFileOperation[]) {
for (const operation of operations) {
createdResources.add(operation.resource);
}
return Promise.resolve(Object.create(null));
}
move(operations: IMoveOperation[]) {
override move(operations: IMoveOperation[]) {
const { source, target } = operations[0].file;
movedResources.set(source, target);
return Promise.resolve(Object.create(null));
}
copy(operations: ICopyOperation[]) {
override copy(operations: ICopyOperation[]) {
const { source, target } = operations[0].file;
copiedResources.set(source, target);
return Promise.resolve(Object.create(null));
}
delete(operations: IDeleteOperation[]) {
override delete(operations: IDeleteOperation[]) {
for (const operation of operations) {
deletedResources.add(operation.resource);
}
@@ -145,9 +144,9 @@ suite('MainThreadEditors', () => {
}
});
services.set(ITextModelService, new class extends mock<ITextModelService>() {
createModelReference(resource: URI): Promise<IReference<IResolvedTextEditorModel>> {
override createModelReference(resource: URI): Promise<IReference<IResolvedTextEditorModel>> {
const textEditorModel = new class extends mock<IResolvedTextEditorModel>() {
textEditorModel = modelService.getModel(resource)!;
override textEditorModel = modelService.getModel(resource)!;
};
textEditorModel.isReadonly = () => false;
return Promise.resolve(new ImmortalReference(textEditorModel));
@@ -157,26 +156,25 @@ suite('MainThreadEditors', () => {
});
services.set(IPanelService, new class extends mock<IPanelService>() implements IPanelService {
declare readonly _serviceBrand: undefined;
onDidPanelOpen = Event.None;
onDidPanelClose = Event.None;
getActivePanel() {
override onDidPanelOpen = Event.None;
override onDidPanelClose = Event.None;
override getActivePanel() {
return undefined;
}
});
services.set(IUriIdentityService, new class extends mock<IUriIdentityService>() {
get extUri() { return extUri; }
override get extUri() { return extUri; }
});
const instaService = new InstantiationService(services);
const rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(ExtHostContext.ExtHostDocuments, new class extends mock<ExtHostDocumentsShape>() {
$acceptModelChanged(): void {
override $acceptModelChanged(): void {
}
});
rpcProtocol.set(ExtHostContext.ExtHostDocumentsAndEditors, new class extends mock<ExtHostDocumentsAndEditorsShape>() {
$acceptDocumentsAndEditorsDelta(): void {
override $acceptDocumentsAndEditorsDelta(): void {
}
});

View File

@@ -29,15 +29,15 @@ suite('MainThreadHostTreeView', function () {
}
class MockExtHostTreeViewsShape extends mock<ExtHostTreeViewsShape>() {
async $getChildren(treeViewId: string, treeItemHandle?: string): Promise<ITreeItem[]> {
override async $getChildren(treeViewId: string, treeItemHandle?: string): Promise<ITreeItem[]> {
return [<CustomTreeItem>{ handle: 'testItem1', collapsibleState: TreeItemCollapsibleState.Expanded, customProp: customValue }];
}
async $hasResolve(): Promise<boolean> {
override async $hasResolve(): Promise<boolean> {
return false;
}
$setVisible(): void { }
override $setVisible(): void { }
}
let container: ViewContainer;

View File

@@ -55,52 +55,52 @@ suite('Editor - Range decorations', () => {
});
test('highlight range for the resource if it is an active editor', function () {
let range: IRange = { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 };
const range: IRange = new Range(1, 1, 1, 1);
testObject.highlightRange({ resource: model.uri, range });
let actuals = rangeHighlightDecorations(model);
const actuals = rangeHighlightDecorations(model);
assert.deepEqual([range], actuals);
assert.deepStrictEqual(actuals, [range]);
});
test('remove highlight range', function () {
testObject.highlightRange({ resource: model.uri, range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 } });
testObject.removeHighlightRange();
let actuals = rangeHighlightDecorations(model);
const actuals = rangeHighlightDecorations(model);
assert.deepEqual([], actuals);
assert.deepStrictEqual(actuals, []);
});
test('highlight range for the resource removes previous highlight', function () {
testObject.highlightRange({ resource: model.uri, range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 } });
let range: IRange = { startLineNumber: 2, startColumn: 2, endLineNumber: 4, endColumn: 3 };
const range: IRange = new Range(2, 2, 4, 3);
testObject.highlightRange({ resource: model.uri, range });
let actuals = rangeHighlightDecorations(model);
const actuals = rangeHighlightDecorations(model);
assert.deepEqual([range], actuals);
assert.deepStrictEqual(actuals, [range]);
});
test('highlight range for a new resource removes highlight of previous resource', function () {
testObject.highlightRange({ resource: model.uri, range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 } });
let anotherModel = prepareActiveEditor('anotherModel');
let range: IRange = { startLineNumber: 2, startColumn: 2, endLineNumber: 4, endColumn: 3 };
const anotherModel = prepareActiveEditor('anotherModel');
const range: IRange = new Range(2, 2, 4, 3);
testObject.highlightRange({ resource: anotherModel.uri, range });
let actuals = rangeHighlightDecorations(model);
assert.deepEqual([], actuals);
assert.deepStrictEqual(actuals, []);
actuals = rangeHighlightDecorations(anotherModel);
assert.deepEqual([range], actuals);
assert.deepStrictEqual(actuals, [range]);
});
test('highlight is removed on model change', function () {
testObject.highlightRange({ resource: model.uri, range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 } });
prepareActiveEditor('anotherModel');
let actuals = rangeHighlightDecorations(model);
assert.deepEqual([], actuals);
const actuals = rangeHighlightDecorations(model);
assert.deepStrictEqual(actuals, []);
});
test('highlight is removed on cursor position change', function () {
@@ -109,27 +109,27 @@ suite('Editor - Range decorations', () => {
position: new Position(2, 1)
});
let actuals = rangeHighlightDecorations(model);
assert.deepEqual([], actuals);
const actuals = rangeHighlightDecorations(model);
assert.deepStrictEqual(actuals, []);
});
test('range is not highlight if not active editor', function () {
let model = aModel(URI.file('some model'));
const model = aModel(URI.file('some model'));
testObject.highlightRange({ resource: model.uri, range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 } });
let actuals = rangeHighlightDecorations(model);
assert.deepEqual([], actuals);
const actuals = rangeHighlightDecorations(model);
assert.deepStrictEqual(actuals, []);
});
test('previous highlight is not removed if not active editor', function () {
let range: IRange = { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 };
const range = new Range(1, 1, 1, 1);
testObject.highlightRange({ resource: model.uri, range });
let model1 = aModel(URI.file('some model'));
const model1 = aModel(URI.file('some model'));
testObject.highlightRange({ resource: model1.uri, range: { startLineNumber: 2, startColumn: 1, endLineNumber: 2, endColumn: 1 } });
let actuals = rangeHighlightDecorations(model);
assert.deepEqual([range], actuals);
const actuals = rangeHighlightDecorations(model);
assert.deepStrictEqual(actuals, [range]);
});
function prepareActiveEditor(resource: string): TextModel {

View File

@@ -21,7 +21,7 @@ suite('Workbench parts', () => {
minimumHeight: number = 50;
maximumHeight: number = 50;
layout(width: number, height: number): void {
override layout(width: number, height: number): void {
throw new Error('Method not implemented.');
}
@@ -36,21 +36,21 @@ suite('Workbench parts', () => {
super('myPart', { hasTitle: true }, new TestThemeService(), new TestStorageService(), new TestLayoutService());
}
createTitleArea(parent: HTMLElement): HTMLElement {
override createTitleArea(parent: HTMLElement): HTMLElement {
assert.strictEqual(parent, this.expectedParent);
return super.createTitleArea(parent)!;
}
createContentArea(parent: HTMLElement): HTMLElement {
override createContentArea(parent: HTMLElement): HTMLElement {
assert.strictEqual(parent, this.expectedParent);
return super.createContentArea(parent)!;
}
getMemento(scope: StorageScope, target: StorageTarget) {
override getMemento(scope: StorageScope, target: StorageTarget) {
return super.getMemento(scope, target);
}
saveState(): void {
override saveState(): void {
return super.saveState();
}
}
@@ -61,7 +61,7 @@ suite('Workbench parts', () => {
super('myPart2', { hasTitle: true }, new TestThemeService(), new TestStorageService(), new TestLayoutService());
}
createTitleArea(parent: HTMLElement): HTMLElement {
override createTitleArea(parent: HTMLElement): HTMLElement {
const titleContainer = append(parent, $('div'));
const titleLabel = append(titleContainer, $('span'));
titleLabel.id = 'myPart.title';
@@ -70,7 +70,7 @@ suite('Workbench parts', () => {
return titleContainer;
}
createContentArea(parent: HTMLElement): HTMLElement {
override createContentArea(parent: HTMLElement): HTMLElement {
const contentContainer = append(parent, $('div'));
const contentSpan = append(contentContainer, $('span'));
contentSpan.id = 'myPart.content';
@@ -86,11 +86,11 @@ suite('Workbench parts', () => {
super('myPart2', { hasTitle: false }, new TestThemeService(), new TestStorageService(), new TestLayoutService());
}
createTitleArea(parent: HTMLElement): HTMLElement {
override createTitleArea(parent: HTMLElement): HTMLElement {
return null!;
}
createContentArea(parent: HTMLElement): HTMLElement {
override createContentArea(parent: HTMLElement): HTMLElement {
const contentContainer = append(parent, $('div'));
const contentSpan = append(contentContainer, $('span'));
contentSpan.id = 'myPart.content';

View File

@@ -18,7 +18,7 @@ suite('Breadcrumb Model', function () {
const workspaceService = new TestContextService(new Workspace('ffff', [new WorkspaceFolder({ uri: URI.parse('foo:/bar/baz/ws'), name: 'ws', index: 0 })]));
const configService = new class extends TestConfigurationService {
getValue(...args: any[]) {
override getValue(...args: any[]) {
if (args[0] === 'breadcrumbs.filePath') {
return 'on';
}
@@ -27,7 +27,7 @@ suite('Breadcrumb Model', function () {
}
return super.getValue(...args);
}
updateValue() {
override updateValue() {
return Promise.resolve();
}
};
@@ -37,14 +37,14 @@ suite('Breadcrumb Model', function () {
let model = new BreadcrumbsModel(URI.parse('foo:/bar/baz/ws/some/path/file.ts'), undefined, configService, workspaceService, new class extends mock<IOutlineService>() { });
let elements = model.getElements();
assert.equal(elements.length, 3);
assert.strictEqual(elements.length, 3);
let [one, two, three] = elements as FileElement[];
assert.equal(one.kind, FileKind.FOLDER);
assert.equal(two.kind, FileKind.FOLDER);
assert.equal(three.kind, FileKind.FILE);
assert.equal(one.uri.toString(), 'foo:/bar/baz/ws/some');
assert.equal(two.uri.toString(), 'foo:/bar/baz/ws/some/path');
assert.equal(three.uri.toString(), 'foo:/bar/baz/ws/some/path/file.ts');
assert.strictEqual(one.kind, FileKind.FOLDER);
assert.strictEqual(two.kind, FileKind.FOLDER);
assert.strictEqual(three.kind, FileKind.FILE);
assert.strictEqual(one.uri.toString(), 'foo:/bar/baz/ws/some');
assert.strictEqual(two.uri.toString(), 'foo:/bar/baz/ws/some/path');
assert.strictEqual(three.uri.toString(), 'foo:/bar/baz/ws/some/path/file.ts');
});
test('display uri matters for FileElement', function () {
@@ -52,14 +52,14 @@ suite('Breadcrumb Model', function () {
let model = new BreadcrumbsModel(URI.parse('foo:/bar/baz/ws/some/PATH/file.ts'), undefined, configService, workspaceService, new class extends mock<IOutlineService>() { });
let elements = model.getElements();
assert.equal(elements.length, 3);
assert.strictEqual(elements.length, 3);
let [one, two, three] = elements as FileElement[];
assert.equal(one.kind, FileKind.FOLDER);
assert.equal(two.kind, FileKind.FOLDER);
assert.equal(three.kind, FileKind.FILE);
assert.equal(one.uri.toString(), 'foo:/bar/baz/ws/some');
assert.equal(two.uri.toString(), 'foo:/bar/baz/ws/some/PATH');
assert.equal(three.uri.toString(), 'foo:/bar/baz/ws/some/PATH/file.ts');
assert.strictEqual(one.kind, FileKind.FOLDER);
assert.strictEqual(two.kind, FileKind.FOLDER);
assert.strictEqual(three.kind, FileKind.FILE);
assert.strictEqual(one.uri.toString(), 'foo:/bar/baz/ws/some');
assert.strictEqual(two.uri.toString(), 'foo:/bar/baz/ws/some/PATH');
assert.strictEqual(three.uri.toString(), 'foo:/bar/baz/ws/some/PATH/file.ts');
});
test('only uri, outside workspace', function () {
@@ -67,11 +67,11 @@ suite('Breadcrumb Model', function () {
let model = new BreadcrumbsModel(URI.parse('foo:/outside/file.ts'), undefined, configService, workspaceService, new class extends mock<IOutlineService>() { });
let elements = model.getElements();
assert.equal(elements.length, 2);
assert.strictEqual(elements.length, 2);
let [one, two] = elements as FileElement[];
assert.equal(one.kind, FileKind.FOLDER);
assert.equal(two.kind, FileKind.FILE);
assert.equal(one.uri.toString(), 'foo:/outside');
assert.equal(two.uri.toString(), 'foo:/outside/file.ts');
assert.strictEqual(one.kind, FileKind.FOLDER);
assert.strictEqual(two.kind, FileKind.FILE);
assert.strictEqual(one.uri.toString(), 'foo:/outside');
assert.strictEqual(two.uri.toString(), 'foo:/outside/file.ts');
});
});

View File

@@ -8,9 +8,16 @@ import { EditorResourceAccessor, SideBySideEditor, IEditorInputWithPreferredReso
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { URI } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { workbenchInstantiationService, TestServiceAccessor, TestEditorInput } from 'vs/workbench/test/browser/workbenchTestServices';
import { workbenchInstantiationService, TestServiceAccessor, TestEditorInput, registerTestDiffEditor, registerTestEditor, registerTestFileEditor, registerTestResourceEditor, TestFileEditorInput, createEditorPart } from 'vs/workbench/test/browser/workbenchTestServices';
import { Schemas } from 'vs/base/common/network';
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { toResource } from 'vs/base/test/common/utils';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { whenEditorClosed } from 'vs/workbench/browser/editor';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { EditorService } from 'vs/workbench/services/editor/browser/editorService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
suite('Workbench editor', () => {
@@ -21,16 +28,40 @@ suite('Workbench editor', () => {
}
}
const disposables = new DisposableStore();
const TEST_EDITOR_ID = 'MyTestEditorForEditors';
let instantiationService: IInstantiationService;
let accessor: TestServiceAccessor;
async function createServices(): Promise<TestServiceAccessor> {
const instantiationService = workbenchInstantiationService();
const part = await createEditorPart(instantiationService, disposables);
instantiationService.stub(IEditorGroupsService, part);
const editorService = instantiationService.createInstance(EditorService);
instantiationService.stub(IEditorService, editorService);
return instantiationService.createInstance(TestServiceAccessor);
}
setup(() => {
instantiationService = workbenchInstantiationService();
accessor = instantiationService.createInstance(TestServiceAccessor);
disposables.add(registerTestFileEditor());
disposables.add(registerTestDiffEditor());
disposables.add(registerTestResourceEditor());
disposables.add(registerTestEditor(TEST_EDITOR_ID, [new SyncDescriptor(TestFileEditorInput)]));
});
teardown(() => {
accessor.untitledTextEditorService.dispose();
disposables.clear();
});
test('EditorResourceAccessor', () => {
@@ -123,4 +154,48 @@ suite('Workbench editor', () => {
assert.strictEqual(EditorResourceAccessor.getCanonicalUri(fileWithPreferredResource)?.toString(), resource.toString());
assert.strictEqual(EditorResourceAccessor.getOriginalUri(fileWithPreferredResource)?.toString(), preferredResource.toString());
});
test('whenEditorClosed (single editor)', async function () {
return testWhenEditorClosed(false, false, toResource.call(this, '/path/index.txt'));
});
test('whenEditorClosed (multiple editor)', async function () {
return testWhenEditorClosed(false, false, toResource.call(this, '/path/index.txt'), toResource.call(this, '/test.html'));
});
test('whenEditorClosed (single editor, diff editor)', async function () {
return testWhenEditorClosed(true, false, toResource.call(this, '/path/index.txt'));
});
test('whenEditorClosed (multiple editor, diff editor)', async function () {
return testWhenEditorClosed(true, false, toResource.call(this, '/path/index.txt'), toResource.call(this, '/test.html'));
});
test('whenEditorClosed (single custom editor)', async function () {
return testWhenEditorClosed(false, true, toResource.call(this, '/path/index.txt'));
});
test('whenEditorClosed (multiple custom editor)', async function () {
return testWhenEditorClosed(false, true, toResource.call(this, '/path/index.txt'), toResource.call(this, '/test.html'));
});
async function testWhenEditorClosed(sideBySide: boolean, custom: boolean, ...resources: URI[]): Promise<void> {
const accessor = await createServices();
for (const resource of resources) {
if (custom) {
await accessor.editorService.openEditor(new TestFileEditorInput(resource, 'testTypeId'), { pinned: true });
} else if (sideBySide) {
await accessor.editorService.openEditor({ leftResource: resource, rightResource: resource, options: { pinned: true } });
} else {
await accessor.editorService.openEditor({ resource, options: { pinned: true } });
}
}
const closedPromise = accessor.instantitionService.invokeFunction(accessor => whenEditorClosed(accessor, resources));
accessor.editorGroupService.activeGroup.closeAllEditors();
await closedPromise;
}
});

View File

@@ -4,8 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { EditorGroup, ISerializedEditorGroup, EditorCloseEvent } from 'vs/workbench/common/editor/editorGroup';
import { Extensions as EditorExtensions, IEditorInputFactoryRegistry, EditorInput, IFileEditorInput, IEditorInputFactory, CloseDirection, EditorsOrder } from 'vs/workbench/common/editor';
import { EditorGroupModel, ISerializedEditorGroupModel, EditorCloseEvent } from 'vs/workbench/common/editor/editorGroupModel';
import { EditorExtensions, IEditorInputFactoryRegistry, EditorInput, IFileEditorInput, IEditorInputSerializer, CloseDirection, EditorsOrder } from 'vs/workbench/common/editor';
import { URI } from 'vs/base/common/uri';
import { TestLifecycleService, workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
@@ -23,7 +23,7 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { TestContextService, TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
suite('Workbench editor groups', () => {
suite('Workbench editor group model', () => {
function inst(): IInstantiationService {
let inst = new TestInstantiationService();
@@ -39,17 +39,17 @@ suite('Workbench editor groups', () => {
return inst;
}
function createGroup(serialized?: ISerializedEditorGroup): EditorGroup {
return inst().createInstance(EditorGroup, serialized);
function createEditorGroupModel(serialized?: ISerializedEditorGroupModel): EditorGroupModel {
return inst().createInstance(EditorGroupModel, serialized);
}
function closeAllEditors(group: EditorGroup): void {
function closeAllEditors(group: EditorGroupModel): void {
for (const editor of group.getEditors(EditorsOrder.SEQUENTIAL)) {
group.closeEditor(editor, false);
}
}
function closeEditors(group: EditorGroup, except: EditorInput, direction?: CloseDirection): void {
function closeEditors(group: EditorGroupModel, except: EditorInput, direction?: CloseDirection): void {
const index = group.indexOf(except);
if (index === -1) {
return; // not found
@@ -87,7 +87,7 @@ suite('Workbench editor groups', () => {
disposed: EditorInput[];
}
function groupListener(group: EditorGroup): GroupEvents {
function groupListener(group: EditorGroupModel): GroupEvents {
const groupEvents: GroupEvents = {
opened: [],
closed: [],
@@ -106,7 +106,7 @@ suite('Workbench editor groups', () => {
group.onDidChangeEditorPinned(e => group.isPinned(e) ? groupEvents.pinned.push(e) : groupEvents.unpinned.push(e));
group.onDidChangeEditorSticky(e => group.isSticky(e) ? groupEvents.sticky.push(e) : groupEvents.unsticky.push(e));
group.onDidMoveEditor(e => groupEvents.moved.push(e));
group.onDidDisposeEditor(e => groupEvents.disposed.push(e));
group.onWillDisposeEditor(e => groupEvents.disposed.push(e));
return groupEvents;
}
@@ -119,10 +119,10 @@ suite('Workbench editor groups', () => {
constructor(public id: string) {
super();
}
getTypeId() { return 'testEditorInputForGroups'; }
async resolve(): Promise<IEditorModel> { return null!; }
override get typeId() { return 'testEditorInputForGroups'; }
override async resolve(): Promise<IEditorModel> { return null!; }
matches(other: TestEditorInput): boolean {
override matches(other: TestEditorInput): boolean {
return other && this.id === other.id && other instanceof TestEditorInput;
}
@@ -142,10 +142,10 @@ suite('Workbench editor groups', () => {
constructor(public id: string) {
super();
}
getTypeId() { return 'testEditorInputForGroups-nonSerializable'; }
async resolve(): Promise<IEditorModel | null> { return null; }
override get typeId() { return 'testEditorInputForGroups-nonSerializable'; }
override async resolve(): Promise<IEditorModel | null> { return null; }
matches(other: NonSerializableTestEditorInput): boolean {
override matches(other: NonSerializableTestEditorInput): boolean {
return other && this.id === other.id && other instanceof NonSerializableTestEditorInput;
}
}
@@ -157,12 +157,12 @@ suite('Workbench editor groups', () => {
constructor(public id: string, public resource: URI) {
super();
}
getTypeId() { return 'testFileEditorInputForGroups'; }
async resolve(): Promise<IEditorModel | null> { return null; }
override get typeId() { return 'testFileEditorInputForGroups'; }
override async resolve(): Promise<IEditorModel | null> { return null; }
setPreferredName(name: string): void { }
setPreferredDescription(description: string): void { }
setPreferredResource(resource: URI): void { }
setEncoding(encoding: string) { }
async setEncoding(encoding: string) { }
getEncoding() { return undefined; }
setPreferredEncoding(encoding: string) { }
setForceOpenAsBinary(): void { }
@@ -170,7 +170,7 @@ suite('Workbench editor groups', () => {
setPreferredMode(mode: string) { }
isResolved(): boolean { return false; }
matches(other: TestFileEditorInput): boolean {
override matches(other: TestFileEditorInput): boolean {
return other && this.id === other.id && other instanceof TestFileEditorInput;
}
}
@@ -187,7 +187,7 @@ suite('Workbench editor groups', () => {
id: string;
}
class TestEditorInputFactory implements IEditorInputFactory {
class TestEditorInputSerializer implements IEditorInputSerializer {
static disableSerialize = false;
static disableDeserialize = false;
@@ -197,7 +197,7 @@ suite('Workbench editor groups', () => {
}
serialize(editorInput: EditorInput): string | undefined {
if (TestEditorInputFactory.disableSerialize) {
if (TestEditorInputSerializer.disableSerialize) {
return undefined;
}
@@ -210,7 +210,7 @@ suite('Workbench editor groups', () => {
}
deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput | undefined {
if (TestEditorInputFactory.disableDeserialize) {
if (TestEditorInputSerializer.disableDeserialize) {
return undefined;
}
@@ -223,10 +223,10 @@ suite('Workbench editor groups', () => {
const disposables = new DisposableStore();
setup(() => {
TestEditorInputFactory.disableSerialize = false;
TestEditorInputFactory.disableDeserialize = false;
TestEditorInputSerializer.disableSerialize = false;
TestEditorInputSerializer.disableDeserialize = false;
disposables.add(Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).registerEditorInputFactory('testEditorInputForGroups', TestEditorInputFactory));
disposables.add(Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).registerEditorInputSerializer('testEditorInputForGroups', TestEditorInputSerializer));
});
teardown(() => {
@@ -236,7 +236,7 @@ suite('Workbench editor groups', () => {
});
test('Clone Group', function () {
const group = createGroup();
const group = createEditorGroupModel();
const input1 = input() as TestEditorInput;
const input2 = input();
@@ -276,7 +276,7 @@ suite('Workbench editor groups', () => {
});
test('contains()', function () {
const group = createGroup();
const group = createEditorGroupModel();
const instantiationService = workbenchInstantiationService();
const input1 = input();
@@ -367,7 +367,7 @@ suite('Workbench editor groups', () => {
test('group serialization', function () {
inst().invokeFunction(accessor => Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).start(accessor));
const group = createGroup();
const group = createEditorGroupModel();
const input1 = input();
const input2 = input();
@@ -379,7 +379,7 @@ suite('Workbench editor groups', () => {
group.openEditor(input2, { pinned: true, active: true });
group.openEditor(input3, { pinned: false, active: true });
let deserialized = createGroup(group.serialize());
let deserialized = createEditorGroupModel(group.serialize());
assert.strictEqual(group.id, deserialized.id);
assert.strictEqual(deserialized.count, 3);
assert.strictEqual(deserialized.getEditors(EditorsOrder.SEQUENTIAL).length, 3);
@@ -390,19 +390,19 @@ suite('Workbench editor groups', () => {
assert.strictEqual(deserialized.isActive(input3), true);
// Case 2: inputs cannot be serialized
TestEditorInputFactory.disableSerialize = true;
TestEditorInputSerializer.disableSerialize = true;
deserialized = createGroup(group.serialize());
deserialized = createEditorGroupModel(group.serialize());
assert.strictEqual(group.id, deserialized.id);
assert.strictEqual(deserialized.count, 0);
assert.strictEqual(deserialized.getEditors(EditorsOrder.SEQUENTIAL).length, 0);
assert.strictEqual(deserialized.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 0);
// Case 3: inputs cannot be deserialized
TestEditorInputFactory.disableSerialize = false;
TestEditorInputFactory.disableDeserialize = true;
TestEditorInputSerializer.disableSerialize = false;
TestEditorInputSerializer.disableDeserialize = true;
deserialized = createGroup(group.serialize());
deserialized = createEditorGroupModel(group.serialize());
assert.strictEqual(group.id, deserialized.id);
assert.strictEqual(deserialized.count, 0);
assert.strictEqual(deserialized.getEditors(EditorsOrder.SEQUENTIAL).length, 0);
@@ -411,7 +411,7 @@ suite('Workbench editor groups', () => {
test('group serialization (sticky editor)', function () {
inst().invokeFunction(accessor => Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).start(accessor));
const group = createGroup();
const group = createEditorGroupModel();
const input1 = input();
const input2 = input();
@@ -426,7 +426,7 @@ suite('Workbench editor groups', () => {
group.stick(input2);
assert.ok(group.isSticky(input2));
let deserialized = createGroup(group.serialize());
let deserialized = createEditorGroupModel(group.serialize());
assert.strictEqual(group.id, deserialized.id);
assert.strictEqual(deserialized.count, 3);
@@ -443,9 +443,9 @@ suite('Workbench editor groups', () => {
assert.strictEqual(deserialized.isSticky(input3), false);
// Case 2: inputs cannot be serialized
TestEditorInputFactory.disableSerialize = true;
TestEditorInputSerializer.disableSerialize = true;
deserialized = createGroup(group.serialize());
deserialized = createEditorGroupModel(group.serialize());
assert.strictEqual(group.id, deserialized.id);
assert.strictEqual(deserialized.count, 0);
assert.strictEqual(deserialized.stickyCount, 0);
@@ -453,10 +453,10 @@ suite('Workbench editor groups', () => {
assert.strictEqual(deserialized.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 0);
// Case 3: inputs cannot be deserialized
TestEditorInputFactory.disableSerialize = false;
TestEditorInputFactory.disableDeserialize = true;
TestEditorInputSerializer.disableSerialize = false;
TestEditorInputSerializer.disableDeserialize = true;
deserialized = createGroup(group.serialize());
deserialized = createEditorGroupModel(group.serialize());
assert.strictEqual(group.id, deserialized.id);
assert.strictEqual(deserialized.count, 0);
assert.strictEqual(deserialized.stickyCount, 0);
@@ -465,7 +465,7 @@ suite('Workbench editor groups', () => {
});
test('One Editor', function () {
const group = createGroup();
const group = createEditorGroupModel();
const events = groupListener(group);
assert.strictEqual(group.count, 0);
@@ -576,7 +576,7 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - Pinned and Active', function () {
const group = createGroup();
const group = createEditorGroupModel();
const events = groupListener(group);
const input1 = input('1');
@@ -650,7 +650,7 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - Preview editor moves to the side of the active one', function () {
const group = createGroup();
const group = createEditorGroupModel();
const input1 = input();
const input2 = input();
@@ -679,7 +679,7 @@ suite('Workbench editor groups', () => {
inst.stub(IConfigurationService, config);
config.setUserConfiguration('workbench', { editor: { openPositioning: 'left' } });
const group: EditorGroup = inst.createInstance(EditorGroup, undefined);
const group: EditorGroupModel = inst.createInstance(EditorGroupModel, undefined);
const events = groupListener(group);
@@ -703,7 +703,7 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - Pinned and Not Active', function () {
const group = createGroup();
const group = createEditorGroupModel();
const input1 = input();
const input2 = input();
@@ -735,7 +735,7 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - Preview gets overwritten', function () {
const group = createGroup();
const group = createEditorGroupModel();
const events = groupListener(group);
const input1 = input();
@@ -768,7 +768,7 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - set active', function () {
const group = createGroup();
const group = createEditorGroupModel();
const events = groupListener(group);
const input1 = input();
@@ -803,7 +803,7 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - pin and unpin', function () {
const group = createGroup();
const group = createEditorGroupModel();
const events = groupListener(group);
const input1 = input();
@@ -852,7 +852,7 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - closing picks next from MRU list', function () {
const group = createGroup();
const group = createEditorGroupModel();
const events = groupListener(group);
const input1 = input();
@@ -911,7 +911,7 @@ suite('Workbench editor groups', () => {
config.setUserConfiguration('workbench', { editor: { focusRecentEditorAfterClose: false } });
inst.stub(IConfigurationService, config);
const group = inst.createInstance(EditorGroup, undefined);
const group = inst.createInstance(EditorGroupModel, undefined);
const events = groupListener(group);
const input1 = input();
@@ -959,7 +959,7 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - move editor', function () {
const group = createGroup();
const group = createEditorGroupModel();
const events = groupListener(group);
const input1 = input();
@@ -1021,8 +1021,8 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - move editor across groups', function () {
const group1 = createGroup();
const group2 = createGroup();
const group1 = createEditorGroupModel();
const group2 = createEditorGroupModel();
const g1_input1 = input();
const g1_input2 = input();
@@ -1043,8 +1043,8 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - move editor across groups (input already exists in group 1)', function () {
const group1 = createGroup();
const group2 = createGroup();
const group1 = createEditorGroupModel();
const group2 = createEditorGroupModel();
const g1_input1 = input();
const g1_input2 = input();
@@ -1067,7 +1067,7 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - Pinned & Non Active', function () {
const group = createGroup();
const group = createEditorGroupModel();
const input1 = input();
group.openEditor(input1);
@@ -1098,7 +1098,7 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - Close Others, Close Left, Close Right', function () {
const group = createGroup();
const group = createEditorGroupModel();
const input1 = input();
const input2 = input();
@@ -1153,7 +1153,7 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - real user example', function () {
const group = createGroup();
const group = createEditorGroupModel();
// [] -> /index.html/
const indexHtml = input('index.html');
@@ -1287,7 +1287,7 @@ suite('Workbench editor groups', () => {
inst.invokeFunction(accessor => Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).start(accessor));
let group = createGroup();
let group = createEditorGroupModel();
const input1 = input();
group.openEditor(input1);
@@ -1298,7 +1298,7 @@ suite('Workbench editor groups', () => {
assert.strictEqual(group.isActive(input1), true);
// Create model again - should load from storage
group = inst.createInstance(EditorGroup, group.serialize());
group = inst.createInstance(EditorGroupModel, group.serialize());
assert.strictEqual(group.count, 1);
assert.strictEqual(group.activeEditor!.matches(input1), true);
@@ -1321,7 +1321,7 @@ suite('Workbench editor groups', () => {
inst.invokeFunction(accessor => Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).start(accessor));
let group1 = createGroup();
let group1 = createEditorGroupModel();
const g1_input1 = input();
const g1_input2 = input();
@@ -1331,7 +1331,7 @@ suite('Workbench editor groups', () => {
group1.openEditor(g1_input2, { active: true, pinned: false });
group1.openEditor(g1_input3, { active: false, pinned: true });
let group2 = createGroup();
let group2 = createEditorGroupModel();
const g2_input1 = input();
const g2_input2 = input();
@@ -1357,8 +1357,8 @@ suite('Workbench editor groups', () => {
assert.strictEqual(group2.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE)[2].matches(g2_input2), true);
// Create model again - should load from storage
group1 = inst.createInstance(EditorGroup, group1.serialize());
group2 = inst.createInstance(EditorGroup, group2.serialize());
group1 = inst.createInstance(EditorGroupModel, group1.serialize());
group2 = inst.createInstance(EditorGroupModel, group2.serialize());
assert.strictEqual(group1.count, 3);
assert.strictEqual(group2.count, 3);
@@ -1391,7 +1391,7 @@ suite('Workbench editor groups', () => {
inst.invokeFunction(accessor => Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).start(accessor));
let group = createGroup();
let group = createEditorGroupModel();
const serializableInput1 = input();
const nonSerializableInput2 = input('3', true);
@@ -1410,7 +1410,7 @@ suite('Workbench editor groups', () => {
assert.strictEqual(group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE)[2].matches(serializableInput1), true);
// Create model again - should load from storage
group = inst.createInstance(EditorGroup, group.serialize());
group = inst.createInstance(EditorGroupModel, group.serialize());
assert.strictEqual(group.count, 2);
assert.strictEqual(group.activeEditor!.matches(serializableInput2), true);
@@ -1435,7 +1435,7 @@ suite('Workbench editor groups', () => {
inst.invokeFunction(accessor => Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).start(accessor));
let group = createGroup();
let group = createEditorGroupModel();
const serializableInput1 = input();
const nonSerializableInput2 = input('3', true);
@@ -1449,7 +1449,7 @@ suite('Workbench editor groups', () => {
assert.strictEqual(group.stickyCount, 1);
// Create model again - should load from storage
group = inst.createInstance(EditorGroup, group.serialize());
group = inst.createInstance(EditorGroupModel, group.serialize());
assert.strictEqual(group.count, 2);
assert.strictEqual(group.stickyCount, 0);
@@ -1470,8 +1470,8 @@ suite('Workbench editor groups', () => {
inst.invokeFunction(accessor => Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).start(accessor));
let group1 = createGroup();
let group2 = createGroup();
let group1 = createEditorGroupModel();
let group2 = createEditorGroupModel();
const serializableInput1 = input();
const serializableInput2 = input();
@@ -1483,8 +1483,8 @@ suite('Workbench editor groups', () => {
group2.openEditor(nonSerializableInput);
// Create model again - should load from storage
group1 = inst.createInstance(EditorGroup, group1.serialize());
group2 = inst.createInstance(EditorGroup, group2.serialize());
group1 = inst.createInstance(EditorGroupModel, group1.serialize());
group2 = inst.createInstance(EditorGroupModel, group2.serialize());
assert.strictEqual(group1.count, 2);
assert.strictEqual(group1.getEditors(EditorsOrder.SEQUENTIAL)[0].matches(serializableInput1), true);
@@ -1492,8 +1492,8 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - Editor Dispose', function () {
const group1 = createGroup();
const group2 = createGroup();
const group1 = createEditorGroupModel();
const group2 = createEditorGroupModel();
const group1Listener = groupListener(group1);
const group2Listener = groupListener(group2);
@@ -1523,7 +1523,7 @@ suite('Workbench editor groups', () => {
});
test('Preview tab does not have a stable position (https://github.com/microsoft/vscode/issues/8245)', function () {
const group1 = createGroup();
const group1 = createEditorGroupModel();
const input1 = input();
const input2 = input();
@@ -1538,8 +1538,8 @@ suite('Workbench editor groups', () => {
});
test('Multiple Editors - Editor Emits Dirty and Label Changed', function () {
const group1 = createGroup();
const group2 = createGroup();
const group1 = createEditorGroupModel();
const group2 = createEditorGroupModel();
const input1 = input();
const input2 = input();
@@ -1591,7 +1591,7 @@ suite('Workbench editor groups', () => {
});
test('Sticky Editors', function () {
const group = createGroup();
const group = createEditorGroupModel();
const input1 = input();
const input2 = input();

View File

@@ -13,8 +13,8 @@ suite('Workbench editor input', () => {
class MyEditorInput extends EditorInput {
readonly resource = undefined;
getTypeId(): string { return ''; }
resolve(): any { return null; }
override get typeId(): string { return 'myEditorInput'; }
override resolve(): any { return null; }
}
test('EditorInput', () => {
@@ -27,7 +27,7 @@ suite('Workbench editor input', () => {
assert(!input.matches(null));
assert(input.getName());
input.onDispose(() => {
input.onWillDispose(() => {
assert(true);
counter++;
});
@@ -41,13 +41,13 @@ suite('Workbench editor input', () => {
let counter = 0;
let input = new MyEditorInput();
input.onDispose(() => {
input.onWillDispose(() => {
assert(true);
counter++;
});
let otherInput = new MyEditorInput();
otherInput.onDispose(() => {
otherInput.onWillDispose(() => {
assert(true);
counter++;
});
@@ -72,7 +72,7 @@ suite('Workbench editor input', () => {
let otherInput = new MyEditorInput();
let diffInput = instantiationService.createInstance(DiffEditorInput, 'name', 'description', input, otherInput, undefined);
diffInput.onDispose(() => {
diffInput.onWillDispose(() => {
counter++;
assert(true);
});
@@ -83,7 +83,7 @@ suite('Workbench editor input', () => {
otherInput = new MyEditorInput();
let diffInput2 = instantiationService.createInstance(DiffEditorInput, 'name', 'description', input, otherInput, undefined);
diffInput2.onDispose(() => {
diffInput2.onWillDispose(() => {
counter++;
assert(true);
});

View File

@@ -31,11 +31,11 @@ suite('Workbench editor model', () => {
class MyEditorModel extends EditorModel { }
class MyTextEditorModel extends BaseTextEditorModel {
createTextEditorModel(value: ITextBufferFactory, resource?: URI, preferredMode?: string) {
override createTextEditorModel(value: ITextBufferFactory, resource?: URI, preferredMode?: string) {
return super.createTextEditorModel(value, resource, preferredMode);
}
isReadonly(): boolean {
override isReadonly(): boolean {
return false;
}
}
@@ -67,28 +67,26 @@ suite('Workbench editor model', () => {
const model = new MyEditorModel();
model.onDispose(() => {
model.onWillDispose(() => {
assert(true);
counter++;
});
const resolvedModel = await model.load();
assert(resolvedModel === model);
assert.strictEqual(resolvedModel.isDisposed(), false);
await model.resolve();
assert.strictEqual(model.isDisposed(), false);
assert.strictEqual(model.isResolved(), true);
model.dispose();
assert.strictEqual(counter, 1);
assert.strictEqual(resolvedModel.isDisposed(), true);
assert.strictEqual(model.isDisposed(), true);
});
test('BaseTextEditorModel', async () => {
let modelService = stubModelService(instantiationService);
const model = new MyTextEditorModel(modelService, modeService);
const resolvedModel = await model.load() as MyTextEditorModel;
await model.resolve();
assert(resolvedModel === model);
resolvedModel.createTextEditorModel(createTextBufferFactory('foo'), null!, 'text/plain');
model.createTextEditorModel(createTextBufferFactory('foo'), null!, 'text/plain');
assert.strictEqual(model.isResolved(), true);
model.dispose();
});

View File

@@ -5,17 +5,17 @@
import * as assert from 'assert';
import { EditorPane, EditorMemento } from 'vs/workbench/browser/parts/editor/editorPane';
import { EditorInput, EditorOptions, IEditorInputFactory, IEditorInputFactoryRegistry, Extensions as EditorExtensions } from 'vs/workbench/common/editor';
import { EditorInput, EditorOptions, IEditorInputSerializer, IEditorInputFactoryRegistry, EditorExtensions } from 'vs/workbench/common/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Registry } from 'vs/platform/registry/common/platform';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { workbenchInstantiationService, TestEditorGroupView, TestEditorGroupsService, registerTestResourceEditor } from 'vs/workbench/test/browser/workbenchTestServices';
import { workbenchInstantiationService, TestEditorGroupView, TestEditorGroupsService, registerTestResourceEditor, TestEditorInput } from 'vs/workbench/test/browser/workbenchTestServices';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import { URI } from 'vs/base/common/uri';
import { IEditorRegistry, Extensions, EditorDescriptor } from 'vs/workbench/browser/editor';
import { IEditorRegistry, EditorDescriptor } from 'vs/workbench/browser/editor';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IEditorModel } from 'vs/platform/editor/common/editor';
import { DisposableStore, dispose } from 'vs/base/common/lifecycle';
@@ -24,33 +24,33 @@ import { extUri } from 'vs/base/common/resources';
const NullThemeService = new TestThemeService();
let EditorRegistry: IEditorRegistry = Registry.as(Extensions.Editors);
let EditorRegistry: IEditorRegistry = Registry.as(EditorExtensions.Editors);
let EditorInputRegistry: IEditorInputFactoryRegistry = Registry.as(EditorExtensions.EditorInputFactories);
export class MyEditor extends EditorPane {
class TestEditor extends EditorPane {
constructor(@ITelemetryService telemetryService: ITelemetryService) {
super('MyEditor', NullTelemetryService, NullThemeService, new TestStorageService());
super('TestEditor', NullTelemetryService, NullThemeService, new TestStorageService());
}
getId(): string { return 'myEditor'; }
override getId(): string { return 'testEditor'; }
layout(): void { }
createEditor(): any { }
}
export class MyOtherEditor extends EditorPane {
export class OtherTestEditor extends EditorPane {
constructor(@ITelemetryService telemetryService: ITelemetryService) {
super('myOtherEditor', NullTelemetryService, NullThemeService, new TestStorageService());
super('testOtherEditor', NullTelemetryService, NullThemeService, new TestStorageService());
}
getId(): string { return 'myOtherEditor'; }
override getId(): string { return 'testOtherEditor'; }
layout(): void { }
createEditor(): any { }
}
class MyInputFactory implements IEditorInputFactory {
class TestInputSerializer implements IEditorInputSerializer {
canSerialize(editorInput: EditorInput): boolean {
return true;
@@ -65,42 +65,42 @@ class MyInputFactory implements IEditorInputFactory {
}
}
class MyInput extends EditorInput {
class TestInput extends EditorInput {
readonly resource = undefined;
getPreferredEditorId(ids: string[]) {
override getPreferredEditorId(ids: string[]) {
return ids[1];
}
getTypeId(): string {
return '';
override get typeId(): string {
return 'testInput';
}
resolve(): any {
override resolve(): any {
return null;
}
}
class MyOtherInput extends EditorInput {
class OtherTestInput extends EditorInput {
readonly resource = undefined;
getTypeId(): string {
return '';
override get typeId(): string {
return 'otherTestInput';
}
resolve(): any {
override resolve(): any {
return null;
}
}
class MyResourceEditorInput extends ResourceEditorInput { }
class TestResourceEditorInput extends ResourceEditorInput { }
suite('Workbench EditorPane', () => {
test('EditorPane API', async () => {
let e = new MyEditor(NullTelemetryService);
let input = new MyOtherInput();
let e = new TestEditor(NullTelemetryService);
let input = new OtherTestInput();
let options = new EditorOptions();
assert(!e.isVisible());
@@ -112,7 +112,7 @@ suite('Workbench EditorPane', () => {
e.setVisible(true, group);
assert(e.isVisible());
assert.strictEqual(e.group, group);
input.onDispose(() => {
input.onWillDispose(() => {
assert(false);
});
e.dispose();
@@ -124,26 +124,26 @@ suite('Workbench EditorPane', () => {
});
test('EditorDescriptor', () => {
let d = EditorDescriptor.create(MyEditor, 'id', 'name');
let d = EditorDescriptor.create(TestEditor, 'id', 'name');
assert.strictEqual(d.getId(), 'id');
assert.strictEqual(d.getName(), 'name');
});
test('Editor Registration', function () {
let d1 = EditorDescriptor.create(MyEditor, 'id1', 'name');
let d2 = EditorDescriptor.create(MyOtherEditor, 'id2', 'name');
let d1 = EditorDescriptor.create(TestEditor, 'id1', 'name');
let d2 = EditorDescriptor.create(OtherTestEditor, 'id2', 'name');
let oldEditorsCnt = EditorRegistry.getEditors().length;
let oldInputCnt = (<any>EditorRegistry).getEditorInputs().length;
const dispose1 = EditorRegistry.registerEditor(d1, [new SyncDescriptor(MyInput)]);
const dispose2 = EditorRegistry.registerEditor(d2, [new SyncDescriptor(MyInput), new SyncDescriptor(MyOtherInput)]);
const dispose1 = EditorRegistry.registerEditor(d1, [new SyncDescriptor(TestInput)]);
const dispose2 = EditorRegistry.registerEditor(d2, [new SyncDescriptor(TestInput), new SyncDescriptor(OtherTestInput)]);
assert.strictEqual(EditorRegistry.getEditors().length, oldEditorsCnt + 2);
assert.strictEqual((<any>EditorRegistry).getEditorInputs().length, oldInputCnt + 3);
assert.strictEqual(EditorRegistry.getEditor(new MyInput()), d2);
assert.strictEqual(EditorRegistry.getEditor(new MyOtherInput()), d2);
assert.strictEqual(EditorRegistry.getEditor(new TestInput()), d2);
assert.strictEqual(EditorRegistry.getEditor(new OtherTestInput()), d2);
assert.strictEqual(EditorRegistry.getEditorById('id1'), d1);
assert.strictEqual(EditorRegistry.getEditorById('id2'), d2);
@@ -153,17 +153,17 @@ suite('Workbench EditorPane', () => {
});
test('Editor Lookup favors specific class over superclass (match on specific class)', function () {
let d1 = EditorDescriptor.create(MyEditor, 'id1', 'name');
let d1 = EditorDescriptor.create(TestEditor, 'id1', 'name');
const disposables = new DisposableStore();
disposables.add(registerTestResourceEditor());
disposables.add(EditorRegistry.registerEditor(d1, [new SyncDescriptor(MyResourceEditorInput)]));
disposables.add(EditorRegistry.registerEditor(d1, [new SyncDescriptor(TestResourceEditorInput)]));
let inst = workbenchInstantiationService();
const editor = EditorRegistry.getEditor(inst.createInstance(MyResourceEditorInput, URI.file('/fake'), 'fake', '', undefined))!.instantiate(inst);
assert.strictEqual(editor.getId(), 'myEditor');
const editor = EditorRegistry.getEditor(inst.createInstance(TestResourceEditorInput, URI.file('/fake'), 'fake', '', undefined))!.instantiate(inst);
assert.strictEqual(editor.getId(), 'testEditor');
const otherEditor = EditorRegistry.getEditor(inst.createInstance(ResourceEditorInput, URI.file('/fake'), 'fake', '', undefined))!.instantiate(inst);
assert.strictEqual(otherEditor.getId(), 'workbench.editors.textResourceEditor');
@@ -177,20 +177,27 @@ suite('Workbench EditorPane', () => {
const disposables = new DisposableStore();
disposables.add(registerTestResourceEditor());
const editor = EditorRegistry.getEditor(inst.createInstance(MyResourceEditorInput, URI.file('/fake'), 'fake', '', undefined))!.instantiate(inst);
const editor = EditorRegistry.getEditor(inst.createInstance(TestResourceEditorInput, URI.file('/fake'), 'fake', '', undefined))!.instantiate(inst);
assert.strictEqual('workbench.editors.textResourceEditor', editor.getId());
disposables.dispose();
});
test('Editor Input Factory', function () {
test('Editor Input Serializer', function () {
const testInput = new TestEditorInput(URI.file('/fake'), 'testTypeId');
workbenchInstantiationService().invokeFunction(accessor => EditorInputRegistry.start(accessor));
const disposable = EditorInputRegistry.registerEditorInputFactory('myInputId', MyInputFactory);
const disposable = EditorInputRegistry.registerEditorInputSerializer(testInput.typeId, TestInputSerializer);
let factory = EditorInputRegistry.getEditorInputFactory('myInputId');
let factory = EditorInputRegistry.getEditorInputSerializer('testTypeId');
assert(factory);
factory = EditorInputRegistry.getEditorInputSerializer(testInput);
assert(factory);
// throws when registering serializer for same type
assert.throws(() => EditorInputRegistry.registerEditorInputSerializer(testInput.typeId, TestInputSerializer));
disposable.dispose();
});
@@ -304,10 +311,10 @@ suite('Workbench EditorPane', () => {
constructor(public resource: URI, private id = 'testEditorInputForMementoTest') {
super();
}
getTypeId() { return 'testEditorInputForMementoTest'; }
async resolve(): Promise<IEditorModel | null> { return null; }
override get typeId() { return 'testEditorInputForMementoTest'; }
override async resolve(): Promise<IEditorModel | null> { return null; }
matches(other: TestEditorInput): boolean {
override matches(other: TestEditorInput): boolean {
return other && this.id === other.id && other instanceof TestEditorInput;
}
}
@@ -342,10 +349,10 @@ suite('Workbench EditorPane', () => {
constructor(public resource: URI, private id = 'testEditorInputForMementoTest') {
super();
}
getTypeId() { return 'testEditorInputForMementoTest'; }
async resolve(): Promise<IEditorModel | null> { return null; }
override get typeId() { return 'testEditorInputForMementoTest'; }
override async resolve(): Promise<IEditorModel | null> { return null; }
matches(other: TestEditorInput): boolean {
override matches(other: TestEditorInput): boolean {
return other && this.id === other.id && other instanceof TestEditorInput;
}
}
@@ -386,9 +393,4 @@ suite('Workbench EditorPane', () => {
res = memento.loadEditorState(testGroup0, testInputB);
assert.ok(!res);
});
return {
MyEditor: MyEditor,
MyOtherEditor: MyOtherEditor
};
});

View File

@@ -46,9 +46,9 @@ suite('Resource text editors', () => {
const model = await input.resolve();
assert.ok(model);
assert.strictEqual(model.textEditorModel.getModeId(), 'resource-input-test');
assert.strictEqual(model.textEditorModel?.getModeId(), 'resource-input-test');
input.setMode('text');
assert.strictEqual(model.textEditorModel.getModeId(), PLAINTEXT_MODE_ID);
assert.strictEqual(model.textEditorModel?.getModeId(), PLAINTEXT_MODE_ID);
});
});

View File

@@ -16,7 +16,7 @@ suite('Viewlets', () => {
super('id', null!, null!, null!, null!, null!, null!, null!, null!, null!);
}
layout(dimension: any): void {
override layout(dimension: any): void {
throw new Error('Method not implemented.');
}

View File

@@ -9,15 +9,15 @@ import { basename } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { IEditorInputWithOptions, IEditorIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, IEditorInput, IEditorPane, IEditorCloseEvent, IEditorPartOptions, IRevertOptions, GroupIdentifier, EditorInput, EditorOptions, EditorsOrder, IFileEditorInput, IEditorInputFactoryRegistry, IEditorInputFactory, Extensions as EditorExtensions, ISaveOptions, IMoveResult, ITextEditorPane, ITextDiffEditorPane, IVisibleEditorPane, IEditorOpenContext, SideBySideEditorInput } from 'vs/workbench/common/editor';
import { IEditorOpeningEvent, EditorServiceImpl, IEditorGroupView, IEditorGroupsAccessor, IEditorGroupTitleHeight } from 'vs/workbench/browser/parts/editor/editor';
import { IEditorInputWithOptions, IEditorIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, IEditorInput, IEditorPane, IEditorCloseEvent, IEditorPartOptions, IRevertOptions, GroupIdentifier, EditorInput, EditorOptions, EditorsOrder, IFileEditorInput, IEditorInputFactoryRegistry, IEditorInputSerializer, EditorExtensions, ISaveOptions, IMoveResult, ITextEditorPane, ITextDiffEditorPane, IVisibleEditorPane, IEditorOpenContext, SideBySideEditorInput, IEditorMoveEvent, EditorExtensions as Extensions } from 'vs/workbench/common/editor';
import { EditorServiceImpl, IEditorGroupView, IEditorGroupsAccessor, IEditorGroupTitleHeight } from 'vs/workbench/browser/parts/editor/editor';
import { Event, Emitter } from 'vs/base/common/event';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { IWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/common/workingCopyBackup';
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { IWorkbenchLayoutService, Parts, Position as PartPosition } from 'vs/workbench/services/layout/browser/layoutService';
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { IEditorOptions, IResourceEditorInput, IEditorModel, ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { IEditorOptions, IResourceEditorInput, IEditorModel, ITextEditorOptions, IResourceEditorInputIdentifier } from 'vs/platform/editor/common/editor';
import { IUntitledTextEditorService, UntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { ILifecycleService, BeforeShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase, WillShutdownEvent } from 'vs/workbench/services/lifecycle/common/lifecycle';
@@ -42,7 +42,7 @@ import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions'
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { MockContextKeyService, MockKeybindingService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
import { ITextBufferFactory, DefaultEndOfLine, EndOfLinePreference, ITextSnapshot } from 'vs/editor/common/model';
import { Range } from 'vs/editor/common/core/range';
import { IRange, Range } from 'vs/editor/common/core/range';
import { IDialogService, IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, IFileDialogService, ConfirmResult } from 'vs/platform/dialogs/common/dialogs';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
@@ -50,11 +50,10 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations';
import { IDisposable, toDisposable, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, IFindGroupScope, EditorGroupLayout, ICloseEditorOptions, GroupOrientation, ICloseAllEditorsOptions, ICloseEditorsFilter } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IEditorReplacement, IGroupChangeEvent, IFindGroupScope, EditorGroupLayout, ICloseEditorOptions, GroupOrientation, ICloseAllEditorsOptions, ICloseEditorsFilter } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService, IOpenEditorOverrideHandler, ISaveEditorsOptions, IRevertAllEditorsOptions, IResourceEditorInputType, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE, IOpenEditorOverrideEntry } from 'vs/workbench/services/editor/common/editorService';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { IEditorRegistry, EditorDescriptor, Extensions } from 'vs/workbench/browser/editor';
import { EditorGroup } from 'vs/workbench/common/editor/editorGroup';
import { IEditorRegistry, EditorDescriptor } from 'vs/workbench/browser/editor';
import { Dimension, IDimension } from 'vs/base/browser/dom';
import { ILogService, NullLogService } from 'vs/platform/log/common/log';
import { ILabelService } from 'vs/platform/label/common/label';
@@ -63,18 +62,19 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { ViewletDescriptor, Viewlet } from 'vs/workbench/browser/viewlet';
import { IViewlet } from 'vs/workbench/common/viewlet';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { IProcessEnvironment, isLinux, isWindows } from 'vs/base/common/platform';
import { IProcessEnvironment, isLinux, isWindows, OperatingSystem } from 'vs/base/common/platform';
import { LabelService } from 'vs/workbench/services/label/common/labelService';
import { Part } from 'vs/workbench/browser/part';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IPanel } from 'vs/workbench/common/panel';
import { IBadge } from 'vs/workbench/services/activity/common/activity';
import { bufferToStream, VSBuffer, VSBufferReadable } from 'vs/base/common/buffer';
import { bufferToStream, VSBuffer, VSBufferReadable, VSBufferReadableStream } from 'vs/base/common/buffer';
import { Schemas } from 'vs/base/common/network';
import { IProductService } from 'vs/platform/product/common/productService';
import product from 'vs/platform/product/common/product';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { IWorkingCopyService, WorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { IWorkingCopyIdentifier } from 'vs/workbench/services/workingCopy/common/workingCopy';
import { IFilesConfigurationService, FilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { IAccessibilityService, AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
import { BrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService';
@@ -96,12 +96,12 @@ import { TestDialogService } from 'vs/platform/dialogs/test/common/testDialogSer
import { CodeEditorService } from 'vs/workbench/services/editor/browser/codeEditorService';
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IDiffEditor, IEditor } from 'vs/editor/common/editorCommon';
import { IChange, IDiffEditor, IEditor } from 'vs/editor/common/editorCommon';
import { IInputBox, IInputOptions, IPickOptions, IQuickInputButton, IQuickInputService, IQuickNavigateConfiguration, IQuickPick, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
import { QuickInputService } from 'vs/workbench/services/quickinput/browser/quickInputService';
import { IListService } from 'vs/platform/list/browser/listService';
import { win32, posix } from 'vs/base/common/path';
import { TestWorkingCopyService, TestContextService, TestStorageService, TestTextResourcePropertiesService, TestExtensionService } from 'vs/workbench/test/common/workbenchTestServices';
import { TestContextService, TestStorageService, TestTextResourcePropertiesService, TestExtensionService } from 'vs/workbench/test/common/workbenchTestServices';
import { IViewsService, IView, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
import { IPaneComposite } from 'vs/workbench/common/panecomposite';
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
@@ -113,9 +113,8 @@ import { EncodingOracle, IEncodingOverride } from 'vs/workbench/services/textfil
import { UTF16le, UTF16be, UTF8_with_bom } from 'vs/workbench/services/textfile/common/encoding';
import { ColorScheme } from 'vs/platform/theme/common/theme';
import { Iterable } from 'vs/base/common/iterator';
import { InMemoryBackupFileService } from 'vs/workbench/services/backup/common/backupFileService';
import { hash } from 'vs/base/common/hash';
import { BrowserBackupFileService } from 'vs/workbench/services/backup/browser/backupFileService';
import { InMemoryWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/common/workingCopyBackupService';
import { BrowserWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/browser/workingCopyBackupService';
import { FileService } from 'vs/platform/files/common/fileService';
import { TextResourceEditor } from 'vs/workbench/browser/parts/editor/textResourceEditor';
import { TestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
@@ -124,12 +123,23 @@ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorIn
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
import { SideBySideEditor } from 'vs/workbench/browser/parts/editor/sideBySideEditor';
import { IEnterWorkspaceResult, IRecent, IRecentlyOpened, IWorkspaceFolderCreationData, IWorkspaceIdentifier, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
import { IWorkspaceTrustService } from 'vs/platform/workspace/common/workspaceTrust';
import { TestWorkspaceTrustService } from 'vs/workbench/services/workspaces/test/common/testWorkspaceTrustService';
import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust';
import { TestWorkspaceTrustManagementService } from 'vs/workbench/services/workspaces/test/common/testWorkspaceTrustService';
import { ILocalTerminalService, IShellLaunchConfig, ITerminalChildProcess, ITerminalsLayoutInfo, ITerminalsLayoutInfoById } from 'vs/platform/terminal/common/terminal';
import { IProcessDetails, ISetTerminalLayoutInfoArgs } from 'vs/platform/terminal/common/terminalProcess';
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { isArray } from 'vs/base/common/types';
import { IShellLaunchConfigResolveOptions, ITerminalProfile, ITerminalProfileResolverService } from 'vs/workbench/contrib/terminal/common/terminal';
import { EditorOverrideService } from 'vs/workbench/services/editor/browser/editorOverrideService';
import { FILE_EDITOR_INPUT_ID } from 'vs/workbench/contrib/files/common/files';
import { IEditorOverrideService } from 'vs/workbench/services/editor/common/editorOverrideService';
import { IWorkingCopyEditorService, WorkingCopyEditorService } from 'vs/workbench/services/workingCopy/common/workingCopyEditorService';
import { IElevatedFileService } from 'vs/workbench/services/files/common/elevatedFileService';
import { BrowserElevatedFileService } from 'vs/workbench/services/files/browser/elevatedFileService';
import { TextDiffEditor } from 'vs/workbench/browser/parts/editor/textDiffEditor';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { IDiffComputationResult, IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { TextEdit, IInplaceReplaceSupportResult } from 'vs/editor/common/modes';
export function createFileEditorInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
return instantiationService.createInstance(FileEditorInput, resource, undefined, undefined, undefined, undefined, undefined);
@@ -137,6 +147,8 @@ export function createFileEditorInput(instantiationService: IInstantiationServic
Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).registerFileEditorInputFactory({
typeId: FILE_EDITOR_INPUT_ID,
createFileEditorInput: (resource, preferredResource, preferredName, preferredDescription, preferredEncoding, preferredMode, instantiationService): IFileEditorInput => {
return instantiationService.createInstance(FileEditorInput, resource, preferredResource, preferredName, preferredDescription, preferredEncoding, preferredMode);
},
@@ -148,14 +160,14 @@ Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).
export class TestTextResourceEditor extends TextResourceEditor {
protected createEditorControl(parent: HTMLElement, configuration: any): IEditor {
protected override createEditorControl(parent: HTMLElement, configuration: any): IEditor {
return this.instantiationService.createInstance(TestCodeEditor, parent, configuration, {});
}
}
export class TestTextFileEditor extends TextFileEditor {
protected createEditorControl(parent: HTMLElement, configuration: any): IEditor {
protected override createEditorControl(parent: HTMLElement, configuration: any): IEditor {
return this.instantiationService.createInstance(TestCodeEditor, parent, configuration, {});
}
}
@@ -175,7 +187,8 @@ export function workbenchInstantiationService(
): ITestInstantiationService {
const instantiationService = new TestInstantiationService(new ServiceCollection([ILifecycleService, new TestLifecycleService()]));
instantiationService.stub(IWorkingCopyService, disposables.add(new TestWorkingCopyService()));
instantiationService.stub(IEditorWorkerService, new TestEditorWorkerService());
instantiationService.stub(IWorkingCopyService, disposables.add(new WorkingCopyService()));
instantiationService.stub(IEnvironmentService, TestEnvironmentService);
instantiationService.stub(IWorkbenchEnvironmentService, TestEnvironmentService);
const contextKeyService = overrides?.contextKeyService ? overrides.contextKeyService(instantiationService) : instantiationService.createInstance(MockContextKeyService);
@@ -206,7 +219,7 @@ export function workbenchInstantiationService(
const fileService = new TestFileService();
instantiationService.stub(IFileService, fileService);
instantiationService.stub(IUriIdentityService, new UriIdentityService(fileService));
instantiationService.stub(IBackupFileService, new TestBackupFileService());
instantiationService.stub(IWorkingCopyBackupService, new TestWorkingCopyBackupService());
instantiationService.stub(ITelemetryService, NullTelemetryService);
instantiationService.stub(INotificationService, new TestNotificationService());
instantiationService.stub(IUntitledTextEditorService, disposables.add(instantiationService.createInstance(UntitledTextEditorService)));
@@ -215,6 +228,7 @@ export function workbenchInstantiationService(
instantiationService.stub(IKeybindingService, keybindingService);
instantiationService.stub(IDecorationsService, new TestDecorationsService());
instantiationService.stub(IExtensionService, new TestExtensionService());
instantiationService.stub(IWorkingCopyEditorService, disposables.add(instantiationService.createInstance(WorkingCopyEditorService)));
instantiationService.stub(IWorkingCopyFileService, disposables.add(instantiationService.createInstance(WorkingCopyFileService)));
instantiationService.stub(ITextFileService, overrides?.textFileService ? overrides.textFileService(instantiationService) : disposables.add(<ITextFileService>instantiationService.createInstance(TestTextFileService)));
instantiationService.stub(IHostService, <IHostService>instantiationService.createInstance(TestHostService));
@@ -225,14 +239,16 @@ export function workbenchInstantiationService(
instantiationService.stub(ILabelService, <ILabelService>disposables.add(instantiationService.createInstance(LabelService)));
const editorService = overrides?.editorService ? overrides.editorService(instantiationService) : new TestEditorService(editorGroupService);
instantiationService.stub(IEditorService, editorService);
instantiationService.stub(IEditorOverrideService, disposables.add(instantiationService.createInstance(EditorOverrideService)));
instantiationService.stub(ICodeEditorService, disposables.add(new CodeEditorService(editorService, themeService, configService)));
instantiationService.stub(IViewletService, new TestViewletService());
instantiationService.stub(IListService, new TestListService());
instantiationService.stub(IQuickInputService, disposables.add(new QuickInputService(configService, instantiationService, keybindingService, contextKeyService, themeService, accessibilityService, layoutService)));
instantiationService.stub(IWorkspacesService, new TestWorkspacesService());
instantiationService.stub(IWorkspaceTrustService, new TestWorkspaceTrustService());
instantiationService.stub(IWorkspaceTrustManagementService, new TestWorkspaceTrustManagementService());
instantiationService.stub(ITerminalInstanceService, new TestTerminalInstanceService());
instantiationService.stub(ILocalTerminalService, new TestLocalTerminalService());
instantiationService.stub(IElevatedFileService, new BrowserElevatedFileService());
return instantiationService;
}
@@ -254,12 +270,17 @@ export class TestServiceAccessor {
@ITextModelService public textModelResolverService: ITextModelService,
@IUntitledTextEditorService public untitledTextEditorService: UntitledTextEditorService,
@IConfigurationService public testConfigurationService: TestConfigurationService,
@IBackupFileService public backupFileService: TestBackupFileService,
@IWorkingCopyBackupService public workingCopyBackupService: TestWorkingCopyBackupService,
@IHostService public hostService: TestHostService,
@IQuickInputService public quickInputService: IQuickInputService,
@ILabelService public labelService: ILabelService,
@ILogService public logService: ILogService,
@IUriIdentityService public uriIdentityService: IUriIdentityService
@IUriIdentityService public uriIdentityService: IUriIdentityService,
@IInstantiationService public instantitionService: IInstantiationService,
@INotificationService public notificationService: INotificationService,
@IWorkingCopyEditorService public workingCopyEditorService: IWorkingCopyEditorService,
@IInstantiationService public instantiationService: IInstantiationService,
@IElevatedFileService public elevatedFileService: IElevatedFileService
) { }
}
@@ -268,7 +289,7 @@ export class TestTextFileService extends BrowserTextFileService {
private writeError: FileOperationError | undefined = undefined;
constructor(
@IFileService protected fileService: IFileService,
@IFileService fileService: IFileService,
@IUntitledTextEditorService untitledTextEditorService: IUntitledTextEditorService,
@ILifecycleService lifecycleService: ILifecycleService,
@IInstantiationService instantiationService: IInstantiationService,
@@ -285,7 +306,8 @@ export class TestTextFileService extends BrowserTextFileService {
@IWorkingCopyFileService workingCopyFileService: IWorkingCopyFileService,
@IUriIdentityService uriIdentityService: IUriIdentityService,
@IModeService modeService: IModeService,
@ILogService logService: ILogService
@ILogService logService: ILogService,
@IElevatedFileService elevatedFileService: IElevatedFileService
) {
super(
fileService,
@@ -304,7 +326,8 @@ export class TestTextFileService extends BrowserTextFileService {
workingCopyFileService,
uriIdentityService,
modeService,
logService
logService,
elevatedFileService
);
}
@@ -312,7 +335,7 @@ export class TestTextFileService extends BrowserTextFileService {
this.readStreamError = error;
}
async readStream(resource: URI, options?: IReadTextFileOptions): Promise<ITextFileStreamContent> {
override async readStream(resource: URI, options?: IReadTextFileOptions): Promise<ITextFileStreamContent> {
if (this.readStreamError) {
const error = this.readStreamError;
this.readStreamError = undefined;
@@ -337,7 +360,7 @@ export class TestTextFileService extends BrowserTextFileService {
this.writeError = error;
}
async write(resource: URI, value: string | ITextSnapshot, options?: IWriteTextFileOptions): Promise<IFileStatWithMetadata> {
override async write(resource: URI, value: string | ITextSnapshot, options?: IWriteTextFileOptions): Promise<IFileStatWithMetadata> {
if (this.writeError) {
const error = this.writeError;
this.writeError = undefined;
@@ -352,7 +375,7 @@ export class TestTextFileService extends BrowserTextFileService {
export class TestBrowserTextFileServiceWithEncodingOverrides extends BrowserTextFileService {
private _testEncoding: TestEncodingOracle | undefined;
get encoding(): TestEncodingOracle {
override get encoding(): TestEncodingOracle {
if (!this._testEncoding) {
this._testEncoding = this._register(this.instantiationService.createInstance(TestEncodingOracle));
}
@@ -363,7 +386,7 @@ export class TestBrowserTextFileServiceWithEncodingOverrides extends BrowserText
export class TestEncodingOracle extends EncodingOracle {
protected get encodingOverrides(): IEncodingOverride[] {
protected override get encodingOverrides(): IEncodingOverride[] {
return [
{ extension: 'utf16le', encoding: UTF16le },
{ extension: 'utf16be', encoding: UTF16be },
@@ -371,7 +394,7 @@ export class TestEncodingOracle extends EncodingOracle {
];
}
protected set encodingOverrides(overrides: IEncodingOverride[]) { }
protected override set encodingOverrides(overrides: IEncodingOverride[]) { }
}
class TestEnvironmentServiceWithArgs extends BrowserWorkbenchEnvironmentService {
@@ -443,7 +466,7 @@ export class TestHistoryService implements IHistoryService {
removeFromHistory(_input: IEditorInput | IResourceEditorInput): void { }
clear(): void { }
clearRecentlyOpened(): void { }
getHistory(): ReadonlyArray<IEditorInput | IResourceEditorInput> { return []; }
getHistory(): readonly (IEditorInput | IResourceEditorInput)[] { return []; }
openNextRecentlyUsedEditor(group?: GroupIdentifier): void { }
openPreviouslyUsedEditor(group?: GroupIdentifier): void { }
getLastActiveWorkspaceRoot(_schemeFilter: string): URI | undefined { return this.root; }
@@ -500,6 +523,8 @@ export class TestLayoutService implements IWorkbenchLayoutService {
layout(): void { }
isRestored(): boolean { return true; }
whenReady: Promise<void> = Promise.resolve(undefined);
whenRestored: Promise<void> = Promise.resolve(undefined);
hasFocus(_part: Parts): boolean { return false; }
focusPart(_part: Parts): void { }
hasWindowBorder(): boolean { return false; }
@@ -621,15 +646,17 @@ export class TestEditorGroupsService implements IEditorGroupsService {
onDidChangeEditorPartOptions = Event.None;
orientation = GroupOrientation.HORIZONTAL;
whenReady: Promise<void> = Promise.resolve(undefined);
whenRestored: Promise<void> = Promise.resolve(undefined);
willRestoreEditors = false;
hasRestorableState = false;
contentDimension = { width: 800, height: 600 };
get activeGroup(): IEditorGroup { return this.groups[0]; }
get count(): number { return this.groups.length; }
getGroups(_order?: GroupsOrder): ReadonlyArray<IEditorGroup> { return this.groups; }
isRestored(): boolean { return true; }
getGroups(_order?: GroupsOrder): readonly IEditorGroup[] { return this.groups; }
getGroup(identifier: number): IEditorGroup | undefined { return this.groups.find(group => group.id === identifier); }
getLabel(_identifier: number): string { return 'Group 1'; }
findGroup(_scope: IFindGroupScope, _source?: number | IEditorGroup, _wrap?: boolean): IEditorGroup { throw new Error('not implemented'); }
@@ -657,14 +684,13 @@ export class TestEditorGroupView implements IEditorGroupView {
constructor(public id: number) { }
get group(): EditorGroup { throw new Error('not implemented'); }
activeEditorPane!: IVisibleEditorPane;
activeEditor!: IEditorInput;
previewEditor!: IEditorInput;
count!: number;
stickyCount!: number;
disposed!: boolean;
editors: ReadonlyArray<IEditorInput> = [];
editors: readonly IEditorInput[] = [];
label!: string;
ariaLabel!: string;
index!: number;
@@ -684,22 +710,23 @@ export class TestEditorGroupView implements IEditorGroupView {
onDidGroupChange: Event<IGroupChangeEvent> = Event.None;
onWillCloseEditor: Event<IEditorCloseEvent> = Event.None;
onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
onWillOpenEditor: Event<IEditorOpeningEvent> = Event.None;
onDidOpenEditorFail: Event<IEditorInput> = Event.None;
onDidFocus: Event<void> = Event.None;
onDidChange: Event<{ width: number; height: number; }> = Event.None;
onWillMoveEditor: Event<IEditorMoveEvent> = Event.None;
getEditors(_order?: EditorsOrder): ReadonlyArray<IEditorInput> { return []; }
getEditors(_order?: EditorsOrder): readonly IEditorInput[] { return []; }
findEditors(_resource: URI): readonly IEditorInput[] { return []; }
getEditorByIndex(_index: number): IEditorInput { throw new Error('not implemented'); }
getIndexOfEditor(_editor: IEditorInput): number { return -1; }
openEditor(_editor: IEditorInput, _options?: IEditorOptions): Promise<IEditorPane> { throw new Error('not implemented'); }
openEditors(_editors: IEditorInputWithOptions[]): Promise<IEditorPane> { throw new Error('not implemented'); }
isOpened(_editor: IEditorInput | IResourceEditorInput): boolean { return false; }
isPinned(_editor: IEditorInput): boolean { return false; }
isSticky(_editor: IEditorInput): boolean { return false; }
isActive(_editor: IEditorInput): boolean { return false; }
moveEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: IMoveEditorOptions): void { }
copyEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: ICopyEditorOptions): void { }
contains(candidate: IEditorInput): boolean { return false; }
moveEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: IEditorOptions | ITextEditorOptions): void { }
copyEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: IEditorOptions | ITextEditorOptions): void { }
async closeEditor(_editor?: IEditorInput, options?: ICloseEditorOptions): Promise<void> { }
async closeEditors(_editors: IEditorInput[] | ICloseEditorsFilter, options?: ICloseEditorOptions): Promise<void> { }
async closeAllEditors(options?: ICloseAllEditorsOptions): Promise<void> { }
@@ -760,16 +787,16 @@ export class TestEditorService implements EditorServiceImpl {
public get activeEditor(): IEditorInput | undefined { return this._activeEditor; }
public set activeEditor(value: IEditorInput | undefined) { this._activeEditor = value; }
editors: ReadonlyArray<IEditorInput> = [];
mostRecentlyActiveEditors: ReadonlyArray<IEditorIdentifier> = [];
visibleEditorPanes: ReadonlyArray<IVisibleEditorPane> = [];
editors: readonly IEditorInput[] = [];
mostRecentlyActiveEditors: readonly IEditorIdentifier[] = [];
visibleEditorPanes: readonly IVisibleEditorPane[] = [];
visibleTextEditorControls = [];
visibleEditors: ReadonlyArray<IEditorInput> = [];
visibleEditors: readonly IEditorInput[] = [];
count = this.editors.length;
constructor(private editorGroupService?: IEditorGroupsService) { }
getEditors() { return []; }
findEditors() { return []; }
findEditors() { return [] as any; }
getEditorOverrides(resource: URI, options: IEditorOptions | undefined, group: IEditorGroup | undefined): [IOpenEditorOverrideHandler, IOpenEditorOverrideEntry][] { return []; }
overrideOpenEditor(_handler: IOpenEditorOverrideHandler): IDisposable { return toDisposable(() => undefined); }
openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined>;
@@ -786,14 +813,13 @@ export class TestEditorService implements EditorServiceImpl {
return [this.editorGroupService.activeGroup, editor as EditorInput, undefined];
}
openEditors(_editors: any, _group?: any): Promise<IEditorPane[]> { throw new Error('not implemented'); }
isOpen(_editor: IEditorInput | IResourceEditorInput): boolean { return false; }
isOpened(_editor: IResourceEditorInputIdentifier): boolean { return false; }
replaceEditors(_editors: any, _group: any) { return Promise.resolve(undefined); }
createEditorInput(_input: IResourceEditorInput | IUntitledTextResourceEditorInput | IResourceDiffEditorInput): EditorInput { throw new Error('not implemented'); }
save(editors: IEditorIdentifier[], options?: ISaveEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
saveAll(options?: ISaveEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
revert(editors: IEditorIdentifier[], options?: IRevertOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
revertAll(options?: IRevertAllEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
whenClosed(editors: IResourceEditorInput[], options?: { waitForSaved: boolean; }): Promise<void> { throw new Error('Method not implemented.'); }
}
export class TestFileService implements IFileService {
@@ -920,6 +946,10 @@ export class TestFileService implements IFileService {
return toDisposable(() => this.providers.delete(scheme));
}
getProvider(scheme: string) {
return this.providers.get(scheme);
}
activateProvider(_scheme: string): Promise<void> { throw new Error('not implemented'); }
canHandleResource(resource: URI): boolean { return resource.scheme === Schemas.file || this.providers.has(resource.scheme); }
listCapabilities() {
@@ -954,28 +984,37 @@ export class TestFileService implements IFileService {
async canDelete(resource: URI, options?: { useTrash?: boolean | undefined; recursive?: boolean | undefined; } | undefined): Promise<Error | true> { return true; }
}
export class TestBackupFileService extends InMemoryBackupFileService {
export class TestWorkingCopyBackupService extends InMemoryWorkingCopyBackupService {
constructor() {
super(resource => String(hash(resource.path)));
super();
}
parseBackupContent(textBufferFactory: ITextBufferFactory): string {
const textBuffer = textBufferFactory.create(DefaultEndOfLine.LF).textBuffer;
const lineCount = textBuffer.getLineCount();
const range = new Range(1, 1, lineCount, textBuffer.getLineLength(lineCount) + 1);
return textBuffer.getValueInRange(range, EndOfLinePreference.TextDefined);
}
}
export class InMemoryTestBackupFileService extends BrowserBackupFileService {
export function toUntypedWorkingCopyId(resource: URI): IWorkingCopyIdentifier {
return toTypedWorkingCopyId(resource, '');
}
readonly fileService: IFileService;
export function toTypedWorkingCopyId(resource: URI, typeId = 'testBackupTypeId'): IWorkingCopyIdentifier {
return { typeId, resource };
}
export class InMemoryTestWorkingCopyBackupService extends BrowserWorkingCopyBackupService {
override readonly fileService: IFileService;
private backupResourceJoiners: Function[];
private discardBackupJoiners: Function[];
discardedBackups: URI[];
discardedBackups: IWorkingCopyIdentifier[];
constructor() {
const environmentService = TestEnvironmentService;
@@ -1000,25 +1039,25 @@ export class InMemoryTestBackupFileService extends BrowserBackupFileService {
return new Promise(resolve => this.discardBackupJoiners.push(resolve));
}
async backup(resource: URI, content?: ITextSnapshot, versionId?: number, meta?: any, token?: CancellationToken): Promise<void> {
await super.backup(resource, content, versionId, meta, token);
override async backup(identifier: IWorkingCopyIdentifier, content?: VSBufferReadableStream | VSBufferReadable, versionId?: number, meta?: any, token?: CancellationToken): Promise<void> {
await super.backup(identifier, content, versionId, meta, token);
while (this.backupResourceJoiners.length) {
this.backupResourceJoiners.pop()!();
}
}
async discardBackup(resource: URI): Promise<void> {
await super.discardBackup(resource);
this.discardedBackups.push(resource);
override async discardBackup(identifier: IWorkingCopyIdentifier): Promise<void> {
await super.discardBackup(identifier);
this.discardedBackups.push(identifier);
while (this.discardBackupJoiners.length) {
this.discardBackupJoiners.pop()!();
}
}
async getBackupContents(resource: URI): Promise<string> {
const backupResource = this.toBackupResource(resource);
async getBackupContents(identifier: IWorkingCopyIdentifier): Promise<string> {
const backupResource = this.toBackupResource(identifier);
const fileContents = await this.fileService.readFile(backupResource);
@@ -1040,7 +1079,7 @@ export class TestLifecycleService implements ILifecycleService {
get onWillShutdown(): Event<WillShutdownEvent> { return this._onWillShutdown.event; }
private readonly _onShutdown = new Emitter<void>();
get onShutdown(): Event<void> { return this._onShutdown.event; }
get onDidShutdown(): Event<void> { return this._onShutdown.event; }
async when(): Promise<void> { }
@@ -1057,13 +1096,35 @@ export class TestLifecycleService implements ILifecycleService {
});
}
fireWillShutdown(event: BeforeShutdownEvent): void { this._onBeforeShutdown.fire(event); }
fireBeforeShutdown(event: BeforeShutdownEvent): void { this._onBeforeShutdown.fire(event); }
fireWillShutdown(event: WillShutdownEvent): void { this._onWillShutdown.fire(event); }
shutdown(): void {
this.fireShutdown();
}
}
export class TestBeforeShutdownEvent implements BeforeShutdownEvent {
value: boolean | Promise<boolean> | undefined;
reason = ShutdownReason.CLOSE;
veto(value: boolean | Promise<boolean>): void {
this.value = value;
}
}
export class TestWillShutdownEvent implements WillShutdownEvent {
value: Promise<void>[] = [];
reason = ShutdownReason.CLOSE;
join(promise: Promise<void>, id: string): void {
this.value.push(promise);
}
}
export class TestTextResourceConfigurationService implements ITextResourceConfigurationService {
declare readonly _serviceBrand: undefined;
@@ -1122,7 +1183,7 @@ export class RemoteFileSystemProvider implements IFileSystemProvider {
}
export class TestInMemoryFileSystemProvider extends InMemoryFileSystemProvider implements IFileSystemProviderWithFileReadStreamCapability {
readonly capabilities: FileSystemProviderCapabilities =
override readonly capabilities: FileSystemProviderCapabilities =
FileSystemProviderCapabilities.FileReadWrite
| FileSystemProviderCapabilities.PathCaseSensitive
| FileSystemProviderCapabilities.FileReadStream;
@@ -1188,34 +1249,34 @@ export class TestHostService implements IHostService {
export class TestFilesConfigurationService extends FilesConfigurationService {
onFilesConfigurationChange(configuration: any): void {
override onFilesConfigurationChange(configuration: any): void {
super.onFilesConfigurationChange(configuration);
}
}
export class TestReadonlyTextFileEditorModel extends TextFileEditorModel {
isReadonly(): boolean {
override isReadonly(): boolean {
return true;
}
}
export class TestEditorInput extends EditorInput {
constructor(public resource: URI, private typeId: string) {
constructor(public resource: URI, private readonly _typeId: string) {
super();
}
getTypeId(): string {
return this.typeId;
override get typeId(): string {
return this._typeId;
}
resolve(): Promise<IEditorModel | null> {
override resolve(): Promise<IEditorModel | null> {
return Promise.resolve(null);
}
}
export function registerTestEditor(id: string, inputs: SyncDescriptor<EditorInput>[], factoryInputId?: string): IDisposable {
export function registerTestEditor(id: string, inputs: SyncDescriptor<EditorInput>[], serializerInputId?: string): IDisposable {
class TestEditor extends EditorPane {
private _scopedContextKeyService: IContextKeyService;
@@ -1225,17 +1286,17 @@ export function registerTestEditor(id: string, inputs: SyncDescriptor<EditorInpu
this._scopedContextKeyService = new MockContextKeyService();
}
async setInput(input: EditorInput, options: EditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise<void> {
override async setInput(input: EditorInput, options: EditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise<void> {
super.setInput(input, options, context, token);
await input.resolve();
}
getId(): string { return id; }
override getId(): string { return id; }
layout(): void { }
createEditor(): void { }
get scopedContextKeyService() {
override get scopedContextKeyService() {
return this._scopedContextKeyService;
}
}
@@ -1244,13 +1305,13 @@ export function registerTestEditor(id: string, inputs: SyncDescriptor<EditorInpu
disposables.add(Registry.as<IEditorRegistry>(Extensions.Editors).registerEditor(EditorDescriptor.create(TestEditor, id, 'Test Editor Control'), inputs));
if (factoryInputId) {
if (serializerInputId) {
interface ISerializedTestInput {
resource: string;
}
class EditorsObserverTestEditorInputFactory implements IEditorInputFactory {
class EditorsObserverTestEditorInputSerializer implements IEditorInputSerializer {
canSerialize(editorInput: EditorInput): boolean {
return true;
@@ -1268,11 +1329,11 @@ export function registerTestEditor(id: string, inputs: SyncDescriptor<EditorInpu
deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput {
let testInput: ISerializedTestInput = JSON.parse(serializedEditorInput);
return new TestFileEditorInput(URI.parse(testInput.resource), factoryInputId!);
return new TestFileEditorInput(URI.parse(testInput.resource), serializerInputId!);
}
}
disposables.add(Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).registerEditorInputFactory(factoryInputId, EditorsObserverTestEditorInputFactory));
disposables.add(Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).registerEditorInputSerializer(serializerInputId, EditorsObserverTestEditorInputSerializer));
}
return disposables;
@@ -1328,6 +1389,23 @@ export function registerTestSideBySideEditor(): IDisposable {
return disposables;
}
export function registerTestDiffEditor(): IDisposable {
const disposables = new DisposableStore();
disposables.add(Registry.as<IEditorRegistry>(Extensions.Editors).registerEditor(
EditorDescriptor.create(
TextDiffEditor,
TextDiffEditor.ID,
'Text Diff Editor'
),
[
new SyncDescriptor(DiffEditorInput)
]
));
return disposables;
}
export class TestFileEditorInput extends EditorInput implements IFileEditorInput {
readonly preferredResource = this.resource;
@@ -1341,16 +1419,16 @@ export class TestFileEditorInput extends EditorInput implements IFileEditorInput
constructor(
public resource: URI,
private typeId: string
private _typeId: string
) {
super();
}
getTypeId() { return this.typeId; }
resolve(): Promise<IEditorModel | null> { return !this.fails ? Promise.resolve(null) : Promise.reject(new Error('fails')); }
matches(other: EditorInput): boolean { return !!(other?.resource && this.resource.toString() === other.resource.toString() && other instanceof TestFileEditorInput && other.getTypeId() === this.typeId); }
override get typeId() { return this._typeId; }
override resolve(): Promise<IEditorModel | null> { return !this.fails ? Promise.resolve(null) : Promise.reject(new Error('fails')); }
override matches(other: EditorInput): boolean { return !!(other?.resource && this.resource.toString() === other.resource.toString() && other instanceof TestFileEditorInput && other.typeId === this.typeId); }
setPreferredResource(resource: URI): void { }
setEncoding(encoding: string) { }
async setEncoding(encoding: string) { }
getEncoding() { return undefined; }
setPreferredName(name: string): void { }
setPreferredDescription(description: string): void { }
@@ -1361,40 +1439,40 @@ export class TestFileEditorInput extends EditorInput implements IFileEditorInput
setFailToOpen(): void {
this.fails = true;
}
async save(groupId: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
override async save(groupId: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
this.gotSaved = true;
this.dirty = false;
return this;
}
async saveAs(groupId: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
override async saveAs(groupId: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
this.gotSavedAs = true;
return this;
}
async revert(group: GroupIdentifier, options?: IRevertOptions): Promise<void> {
override async revert(group: GroupIdentifier, options?: IRevertOptions): Promise<void> {
this.gotReverted = true;
this.gotSaved = false;
this.gotSavedAs = false;
this.dirty = false;
}
setDirty(): void { this.dirty = true; }
isDirty(): boolean {
override isDirty(): boolean {
return this.dirty;
}
isReadonly(): boolean {
override isReadonly(): boolean {
return false;
}
isResolved(): boolean { return false; }
dispose(): void {
override dispose(): void {
super.dispose();
this.gotDisposed = true;
}
movedEditor: IMoveResult | undefined = undefined;
rename(): IMoveResult | undefined { return this.movedEditor; }
override rename(): IMoveResult | undefined { return this.movedEditor; }
}
export class TestEditorPart extends EditorPart {
saveState(): void {
override saveState(): void {
return super.saveState();
}
@@ -1411,11 +1489,13 @@ export class TestEditorPart extends EditorPart {
}
}
export function createEditorPart(instantiationService: IInstantiationService, disposables: DisposableStore): TestEditorPart {
export async function createEditorPart(instantiationService: IInstantiationService, disposables: DisposableStore): Promise<TestEditorPart> {
const part = disposables.add(instantiationService.createInstance(TestEditorPart));
part.create(document.createElement('div'));
part.layout(1080, 800);
await part.whenReady;
return part;
}
@@ -1449,11 +1529,11 @@ export class TestPathService implements IPathService {
export class TestTextFileEditorModelManager extends TextFileEditorModelManager {
add(resource: URI, model: TextFileEditorModel): void {
override add(resource: URI, model: TextFileEditorModel): void {
return super.add(resource, model);
}
remove(resource: URI): void {
override remove(resource: URI): void {
return super.remove(resource);
}
}
@@ -1504,6 +1584,18 @@ export class TestTerminalInstanceService implements ITerminalInstanceService {
createWindowsShellHelper(shellProcessId: number, xterm: any): any { throw new Error('Method not implemented.'); }
}
export class TestTerminalProfileResolverService implements ITerminalProfileResolverService {
_serviceBrand: undefined;
resolveIcon(shellLaunchConfig: IShellLaunchConfig): void { }
async resolveShellLaunchConfig(shellLaunchConfig: IShellLaunchConfig, options: IShellLaunchConfigResolveOptions): Promise<void> { }
async getDefaultProfile(options: IShellLaunchConfigResolveOptions): Promise<ITerminalProfile> { return { path: '/default', profileName: 'Default' }; }
async getDefaultShell(options: IShellLaunchConfigResolveOptions): Promise<string> { return '/default'; }
async getDefaultShellArgs(options: IShellLaunchConfigResolveOptions): Promise<string | string[]> { return []; }
async getShellEnvironment(): Promise<IProcessEnvironment> { return process.env; }
getSafeConfigValue(key: string, os: OperatingSystem): unknown | undefined { return undefined; }
getSafeConfigValueFullKey(key: string): unknown | undefined { return undefined; }
}
export class TestLocalTerminalService implements ILocalTerminalService {
declare readonly _serviceBrand: undefined;
@@ -1516,9 +1608,13 @@ export class TestLocalTerminalService implements ILocalTerminalService {
return new TestTerminalChildProcess(shouldPersist);
}
async attachToProcess(id: number): Promise<ITerminalChildProcess | undefined> { throw new Error('Method not implemented.'); }
async listProcesses(reduceGraceTime: boolean): Promise<IProcessDetails[]> { throw new Error('Method not implemented.'); }
async listProcesses(): Promise<IProcessDetails[]> { throw new Error('Method not implemented.'); }
getDefaultSystemShell(osOverride?: OperatingSystem): Promise<string> { throw new Error('Method not implemented.'); }
getShellEnvironment(): Promise<IProcessEnvironment> { throw new Error('Method not implemented.'); }
async setTerminalLayoutInfo(argsOrLayout?: ISetTerminalLayoutInfoArgs | ITerminalsLayoutInfoById) { throw new Error('Method not implemented.'); }
async getTerminalLayoutInfo(): Promise<ITerminalsLayoutInfo | undefined> { throw new Error('Method not implemented.'); }
async reduceConnectionGraceTime(): Promise<void> { throw new Error('Method not implemented.'); }
processBinary(id: number, data: string): Promise<void> { throw new Error('Method not implemented.'); }
}
class TestTerminalChildProcess implements ITerminalChildProcess {
@@ -1542,6 +1638,7 @@ class TestTerminalChildProcess implements ITerminalChildProcess {
async getInitialCwd(): Promise<string> { return ''; }
async getCwd(): Promise<string> { return ''; }
async getLatency(): Promise<number> { return 0; }
async processBinary(data: string): Promise<void> { }
}
export class TestQuickInputService implements IQuickInputService {
@@ -1575,3 +1672,18 @@ export class TestQuickInputService implements IQuickInputService {
back(): Promise<void> { throw new Error('not implemented.'); }
cancel(): Promise<void> { throw new Error('not implemented.'); }
}
export class TestEditorWorkerService implements IEditorWorkerService {
declare readonly _serviceBrand: undefined;
canComputeDiff(original: URI, modified: URI): boolean { return false; }
async computeDiff(original: URI, modified: URI, ignoreTrimWhitespace: boolean, maxComputationTime: number): Promise<IDiffComputationResult | null> { return null; }
canComputeDirtyDiff(original: URI, modified: URI): boolean { return false; }
async computeDirtyDiff(original: URI, modified: URI, ignoreTrimWhitespace: boolean): Promise<IChange[] | null> { return null; }
async computeMoreMinimalEdits(resource: URI, edits: TextEdit[] | null | undefined): Promise<TextEdit[] | undefined> { return undefined; }
canComputeWordRanges(resource: URI): boolean { return false; }
async computeWordRanges(resource: URI, range: IRange): Promise<{ [word: string]: IRange[]; } | null> { return null; }
canNavigateValueSet(resource: URI): boolean { return false; }
async navigateValueSet(resource: URI, range: IRange, up: boolean): Promise<IInplaceReplaceSupportResult | null> { return null; }
}

View File

@@ -38,6 +38,12 @@ suite('Notifications', () => {
assert.strictEqual(item1.equals(item4), false);
assert.strictEqual(item1.equals(item5), false);
let itemId1 = NotificationViewItem.create({ id: 'same', message: 'Info Message', severity: Severity.Info })!;
let itemId2 = NotificationViewItem.create({ id: 'same', message: 'Error Message', severity: Severity.Error })!;
assert.strictEqual(itemId1.equals(itemId2), true);
assert.strictEqual(itemId1.equals(item3), false);
// Progress
assert.strictEqual(item1.hasProgress, false);
assert.strictEqual(item6.hasProgress, true);

View File

@@ -8,19 +8,20 @@ import { basename, isEqual, isEqualOrParent } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceContextService, IWorkspace, WorkbenchState, IWorkspaceFolder, IWorkspaceFoldersChangeEvent, Workspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService, IWorkspace, WorkbenchState, IWorkspaceFolder, IWorkspaceFoldersChangeEvent, Workspace, IWorkspaceFoldersWillChangeEvent } from 'vs/platform/workspace/common/workspace';
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { ITextResourcePropertiesService } from 'vs/editor/common/services/textResourceConfigurationService';
import { isLinux, isMacintosh } from 'vs/base/common/platform';
import { InMemoryStorageService, WillSaveStateReason } from 'vs/platform/storage/common/storage';
import { WorkingCopyService, IWorkingCopy, IWorkingCopyBackup, WorkingCopyCapabilities } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { IWorkingCopy, IWorkingCopyBackup, WorkingCopyCapabilities } from 'vs/workbench/services/workingCopy/common/workingCopy';
import { NullExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IWorkingCopyFileService, IWorkingCopyFileOperationParticipant, WorkingCopyFileEvent, IDeleteOperation, ICopyOperation, IMoveOperation, IFileOperationUndoRedoInfo, ICreateFileOperation, ICreateOperation } from 'vs/workbench/services/workingCopy/common/workingCopyFileService';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { IFileStatWithMetadata } from 'vs/platform/files/common/files';
import { ISaveOptions, IRevertOptions } from 'vs/workbench/common/editor';
import { CancellationToken } from 'vs/base/common/cancellation';
import product from 'vs/platform/product/common/product';
export class TestTextResourcePropertiesService implements ITextResourcePropertiesService {
@@ -50,6 +51,9 @@ export class TestContextService implements IWorkspaceContextService {
private readonly _onDidChangeWorkspaceName: Emitter<void>;
get onDidChangeWorkspaceName(): Event<void> { return this._onDidChangeWorkspaceName.event; }
private readonly _onWillChangeWorkspaceFolders: Emitter<IWorkspaceFoldersWillChangeEvent>;
get onWillChangeWorkspaceFolders(): Event<IWorkspaceFoldersWillChangeEvent> { return this._onWillChangeWorkspaceFolders.event; }
private readonly _onDidChangeWorkspaceFolders: Emitter<IWorkspaceFoldersChangeEvent>;
get onDidChangeWorkspaceFolders(): Event<IWorkspaceFoldersChangeEvent> { return this._onDidChangeWorkspaceFolders.event; }
@@ -60,6 +64,7 @@ export class TestContextService implements IWorkspaceContextService {
this.workspace = workspace;
this.options = options || Object.create(null);
this._onDidChangeWorkspaceName = new Emitter<void>();
this._onWillChangeWorkspaceFolders = new Emitter<IWorkspaceFoldersWillChangeEvent>();
this._onDidChangeWorkspaceFolders = new Emitter<IWorkspaceFoldersChangeEvent>();
this._onDidChangeWorkbenchState = new Emitter<WorkbenchState>();
}
@@ -121,13 +126,11 @@ export class TestContextService implements IWorkspaceContextService {
export class TestStorageService extends InMemoryStorageService {
emitWillSaveState(reason: WillSaveStateReason): void {
override emitWillSaveState(reason: WillSaveStateReason): void {
super.emitWillSaveState(reason);
}
}
export class TestWorkingCopyService extends WorkingCopyService { }
export class TestWorkingCopy extends Disposable implements IWorkingCopy {
private readonly _onDidChangeDirty = this._register(new Emitter<void>());
@@ -136,16 +139,13 @@ export class TestWorkingCopy extends Disposable implements IWorkingCopy {
private readonly _onDidChangeContent = this._register(new Emitter<void>());
readonly onDidChangeContent = this._onDidChangeContent.event;
private readonly _onDispose = this._register(new Emitter<void>());
readonly onDispose = this._onDispose.event;
readonly capabilities = WorkingCopyCapabilities.None;
readonly name = basename(this.resource);
private dirty = false;
constructor(public readonly resource: URI, isDirty = false) {
constructor(public readonly resource: URI, isDirty = false, public readonly typeId = 'testWorkingCopyType') {
super();
this.dirty = isDirty;
@@ -177,12 +177,6 @@ export class TestWorkingCopy extends Disposable implements IWorkingCopy {
async backup(token: CancellationToken): Promise<IWorkingCopyBackup> {
return {};
}
dispose(): void {
this._onDispose.fire();
super.dispose();
}
}
export class TestWorkingCopyFileService implements IWorkingCopyFileService {
@@ -195,18 +189,18 @@ export class TestWorkingCopyFileService implements IWorkingCopyFileService {
addFileOperationParticipant(participant: IWorkingCopyFileOperationParticipant): IDisposable { return Disposable.None; }
async delete(operations: IDeleteOperation[], undoInfo?: IFileOperationUndoRedoInfo, token?: CancellationToken): Promise<void> { }
async delete(operations: IDeleteOperation[], token: CancellationToken, undoInfo?: IFileOperationUndoRedoInfo): Promise<void> { }
registerWorkingCopyProvider(provider: (resourceOrFolder: URI) => IWorkingCopy[]): IDisposable { return Disposable.None; }
getDirty(resource: URI): IWorkingCopy[] { return []; }
create(operations: ICreateFileOperation[], undoInfo?: IFileOperationUndoRedoInfo, token?: CancellationToken): Promise<IFileStatWithMetadata[]> { throw new Error('Method not implemented.'); }
createFolder(operations: ICreateOperation[], undoInfo?: IFileOperationUndoRedoInfo, token?: CancellationToken): Promise<IFileStatWithMetadata[]> { throw new Error('Method not implemented.'); }
create(operations: ICreateFileOperation[], token: CancellationToken, undoInfo?: IFileOperationUndoRedoInfo): Promise<IFileStatWithMetadata[]> { throw new Error('Method not implemented.'); }
createFolder(operations: ICreateOperation[], token: CancellationToken, undoInfo?: IFileOperationUndoRedoInfo): Promise<IFileStatWithMetadata[]> { throw new Error('Method not implemented.'); }
move(operations: IMoveOperation[], undoInfo?: IFileOperationUndoRedoInfo): Promise<IFileStatWithMetadata[]> { throw new Error('Method not implemented.'); }
move(operations: IMoveOperation[], token: CancellationToken, undoInfo?: IFileOperationUndoRedoInfo): Promise<IFileStatWithMetadata[]> { throw new Error('Method not implemented.'); }
copy(operations: ICopyOperation[], undoInfo?: IFileOperationUndoRedoInfo, token?: CancellationToken): Promise<IFileStatWithMetadata[]> { throw new Error('Method not implemented.'); }
copy(operations: ICopyOperation[], token: CancellationToken, undoInfo?: IFileOperationUndoRedoInfo): Promise<IFileStatWithMetadata[]> { throw new Error('Method not implemented.'); }
}
export function mock<T>(): Ctor<T> {
@@ -218,3 +212,5 @@ export interface Ctor<T> {
}
export class TestExtensionService extends NullExtensionService { }
export const TestProductService = { _serviceBrand: undefined, ...product };

View File

@@ -23,6 +23,7 @@ import { mock } from 'vs/base/test/common/mock';
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
import { TextSearchManager } from 'vs/workbench/services/search/common/textSearchManager';
import { NativeTextSearchManager } from 'vs/workbench/services/search/node/textSearchManager';
import { timeout } from 'vs/base/common/async';
let rpcProtocol: TestRPCProtocol;
let extHostSearch: NativeExtHostSearch;
@@ -83,7 +84,7 @@ suite('ExtHostSearch', () => {
const cancellation = new CancellationTokenSource();
const p = extHostSearch.$provideFileSearchResults(mockMainThreadSearch.lastHandle, 0, query, cancellation.token);
if (cancel) {
await new Promise(resolve => process.nextTick(resolve));
await timeout(0);
cancellation.cancel();
}
@@ -102,15 +103,11 @@ suite('ExtHostSearch', () => {
};
}
async function runTextSearch(query: ITextQuery, cancel = false): Promise<{ results: IFileMatch[], stats: ISearchCompleteStats }> {
async function runTextSearch(query: ITextQuery): Promise<{ results: IFileMatch[], stats: ISearchCompleteStats }> {
let stats: ISearchCompleteStats;
try {
const cancellation = new CancellationTokenSource();
const p = extHostSearch.$provideTextSearchResults(mockMainThreadSearch.lastHandle, 0, query, cancellation.token);
if (cancel) {
await new Promise(resolve => process.nextTick(resolve));
cancellation.cancel();
}
stats = await p;
} catch (err) {
@@ -151,7 +148,7 @@ suite('ExtHostSearch', () => {
this._pfs = mockPFS as any;
}
protected createTextSearchManager(query: ITextQuery, provider: vscode.TextSearchProvider): TextSearchManager {
protected override createTextSearchManager(query: ITextQuery, provider: vscode.TextSearchProvider): TextSearchManager {
return new NativeTextSearchManager(query, provider, this._pfs);
}
};
@@ -183,7 +180,7 @@ suite('ExtHostSearch', () => {
function compareURIs(actual: URI[], expected: URI[]) {
const sortAndStringify = (arr: URI[]) => arr.sort().map(u => u.toString());
assert.deepEqual(
assert.deepStrictEqual(
sortAndStringify(actual),
sortAndStringify(expected));
}
@@ -215,7 +212,7 @@ suite('ExtHostSearch', () => {
const { results, stats } = await runFileSearch(getSimpleQuery());
assert(!stats.limitHit);
assert.equal(results.length, 3);
assert.strictEqual(results.length, 3);
compareURIs(results, reportedResults);
});
@@ -223,12 +220,19 @@ suite('ExtHostSearch', () => {
let cancelRequested = false;
await registerTestFileSearchProvider({
provideFileSearchResults(query: vscode.FileSearchQuery, options: vscode.FileSearchOptions, token: vscode.CancellationToken): Promise<URI[]> {
return new Promise((resolve, reject) => {
token.onCancellationRequested(() => {
function onCancel() {
cancelRequested = true;
resolve([joinPath(options.folder, 'file1.ts')]); // or reject or nothing?
});
}
if (token.isCancellationRequested) {
onCancel();
} else {
token.onCancellationRequested(() => onCancel());
}
});
}
});
@@ -286,11 +290,11 @@ suite('ExtHostSearch', () => {
await registerTestFileSearchProvider({
provideFileSearchResults(query: vscode.FileSearchQuery, options: vscode.FileSearchOptions, token: vscode.CancellationToken): Promise<URI[]> {
if (options.folder.toString() === rootFolderA.toString()) {
assert.deepEqual(options.includes.sort(), ['*.ts', 'foo']);
assert.deepEqual(options.excludes.sort(), ['*.js', 'bar']);
assert.deepStrictEqual(options.includes.sort(), ['*.ts', 'foo']);
assert.deepStrictEqual(options.excludes.sort(), ['*.js', 'bar']);
} else {
assert.deepEqual(options.includes.sort(), ['*.ts']);
assert.deepEqual(options.excludes.sort(), ['*.js']);
assert.deepStrictEqual(options.includes.sort(), ['*.ts']);
assert.deepStrictEqual(options.excludes.sort(), ['*.js']);
}
return Promise.resolve(null!);
@@ -327,8 +331,8 @@ suite('ExtHostSearch', () => {
test('include/excludes resolved correctly', async () => {
await registerTestFileSearchProvider({
provideFileSearchResults(query: vscode.FileSearchQuery, options: vscode.FileSearchOptions, token: vscode.CancellationToken): Promise<URI[]> {
assert.deepEqual(options.includes.sort(), ['*.jsx', '*.ts']);
assert.deepEqual(options.excludes.sort(), []);
assert.deepStrictEqual(options.includes.sort(), ['*.jsx', '*.ts']);
assert.deepStrictEqual(options.excludes.sort(), []);
return Promise.resolve(null!);
}
@@ -492,7 +496,7 @@ suite('ExtHostSearch', () => {
const { results, stats } = await runFileSearch(query);
assert(stats.limitHit, 'Expected to return limitHit');
assert.equal(results.length, 1);
assert.strictEqual(results.length, 1);
compareURIs(results, reportedResults.slice(0, 1));
assert(wasCanceled, 'Expected to be canceled when hitting limit');
});
@@ -528,7 +532,7 @@ suite('ExtHostSearch', () => {
const { results, stats } = await runFileSearch(query);
assert(stats.limitHit, 'Expected to return limitHit');
assert.equal(results.length, 2);
assert.strictEqual(results.length, 2);
compareURIs(results, reportedResults.slice(0, 2));
assert(wasCanceled, 'Expected to be canceled when hitting limit');
});
@@ -563,7 +567,7 @@ suite('ExtHostSearch', () => {
const { results, stats } = await runFileSearch(query);
assert(!stats.limitHit, 'Expected not to return limitHit');
assert.equal(results.length, 2);
assert.strictEqual(results.length, 2);
compareURIs(results, reportedResults);
assert(!wasCanceled, 'Expected not to be canceled when just reaching limit');
});
@@ -601,8 +605,8 @@ suite('ExtHostSearch', () => {
};
const { results } = await runFileSearch(query);
assert.equal(results.length, 2); // Don't care which 2 we got
assert.equal(cancels, 2, 'Expected all invocations to be canceled when hitting limit');
assert.strictEqual(results.length, 2); // Don't care which 2 we got
assert.strictEqual(cancels, 2, 'Expected all invocations to be canceled when hitting limit');
});
test('works with non-file schemes', async () => {
@@ -718,7 +722,7 @@ suite('ExtHostSearch', () => {
lineNumber: r.lineNumber
});
return assert.deepEqual(
return assert.deepStrictEqual(
makeComparable(actualTextSearchResults),
makeComparable(expected));
}
@@ -756,8 +760,8 @@ suite('ExtHostSearch', () => {
test('all provider calls get global include/excludes', async () => {
await registerTestTextSearchProvider({
provideTextSearchResults(query: vscode.TextSearchQuery, options: vscode.TextSearchOptions, progress: vscode.Progress<vscode.TextSearchResult>, token: vscode.CancellationToken): Promise<vscode.TextSearchComplete> {
assert.equal(options.includes.length, 1);
assert.equal(options.excludes.length, 1);
assert.strictEqual(options.includes.length, 1);
assert.strictEqual(options.excludes.length, 1);
return Promise.resolve(null!);
}
});
@@ -787,11 +791,11 @@ suite('ExtHostSearch', () => {
await registerTestTextSearchProvider({
provideTextSearchResults(query: vscode.TextSearchQuery, options: vscode.TextSearchOptions, progress: vscode.Progress<vscode.TextSearchResult>, token: vscode.CancellationToken): Promise<vscode.TextSearchComplete> {
if (options.folder.toString() === rootFolderA.toString()) {
assert.deepEqual(options.includes.sort(), ['*.ts', 'foo']);
assert.deepEqual(options.excludes.sort(), ['*.js', 'bar']);
assert.deepStrictEqual(options.includes.sort(), ['*.ts', 'foo']);
assert.deepStrictEqual(options.excludes.sort(), ['*.js', 'bar']);
} else {
assert.deepEqual(options.includes.sort(), ['*.ts']);
assert.deepEqual(options.excludes.sort(), ['*.js']);
assert.deepStrictEqual(options.includes.sort(), ['*.ts']);
assert.deepStrictEqual(options.excludes.sort(), ['*.js']);
}
return Promise.resolve(null!);
@@ -828,8 +832,8 @@ suite('ExtHostSearch', () => {
test('include/excludes resolved correctly', async () => {
await registerTestTextSearchProvider({
provideTextSearchResults(query: vscode.TextSearchQuery, options: vscode.TextSearchOptions, progress: vscode.Progress<vscode.TextSearchResult>, token: vscode.CancellationToken): Promise<vscode.TextSearchComplete> {
assert.deepEqual(options.includes.sort(), ['*.jsx', '*.ts']);
assert.deepEqual(options.excludes.sort(), []);
assert.deepStrictEqual(options.includes.sort(), ['*.jsx', '*.ts']);
assert.deepStrictEqual(options.excludes.sort(), []);
return Promise.resolve(null!);
}
@@ -1184,8 +1188,8 @@ suite('ExtHostSearch', () => {
};
const { results } = await runTextSearch(query);
assert.equal(results.length, 2);
assert.equal(cancels, 2);
assert.strictEqual(results.length, 2);
assert.strictEqual(cancels, 2);
});
test('works with non-file schemes', async () => {

View File

@@ -28,13 +28,13 @@ suite('MainThreadWorkspace', () => {
test('simple', () => {
instantiationService.stub(ISearchService, {
fileSearch(query: IFileQuery) {
assert.equal(query.folderQueries.length, 1);
assert.equal(query.folderQueries[0].disregardIgnoreFiles, true);
assert.strictEqual(query.folderQueries.length, 1);
assert.strictEqual(query.folderQueries[0].disregardIgnoreFiles, true);
assert.deepEqual(query.includePattern, { 'foo': true });
assert.equal(query.maxResults, 10);
assert.strictEqual(query.maxResults, 10);
return Promise.resolve({ results: [] });
return Promise.resolve({ results: [], messages: [] });
}
});
@@ -52,11 +52,11 @@ suite('MainThreadWorkspace', () => {
instantiationService.stub(ISearchService, {
fileSearch(query: IFileQuery) {
assert.equal(query.folderQueries.length, 1);
assert.equal(query.folderQueries[0].disregardIgnoreFiles, true);
assert.deepEqual(query.folderQueries[0].excludePattern, { 'filesExclude': true });
assert.strictEqual(query.folderQueries.length, 1);
assert.strictEqual(query.folderQueries[0].disregardIgnoreFiles, true);
assert.deepStrictEqual(query.folderQueries[0].excludePattern, { 'filesExclude': true });
return Promise.resolve({ results: [] });
return Promise.resolve({ results: [], messages: [] });
}
});
@@ -74,10 +74,10 @@ suite('MainThreadWorkspace', () => {
instantiationService.stub(ISearchService, {
fileSearch(query: IFileQuery) {
assert.equal(query.folderQueries[0].excludePattern, undefined);
assert.deepEqual(query.excludePattern, undefined);
assert.strictEqual(query.folderQueries[0].excludePattern, undefined);
assert.deepStrictEqual(query.excludePattern, undefined);
return Promise.resolve({ results: [] });
return Promise.resolve({ results: [], messages: [] });
}
});
@@ -88,10 +88,10 @@ suite('MainThreadWorkspace', () => {
test('exclude string', () => {
instantiationService.stub(ISearchService, {
fileSearch(query: IFileQuery) {
assert.equal(query.folderQueries[0].excludePattern, undefined);
assert.strictEqual(query.folderQueries[0].excludePattern, undefined);
assert.deepEqual(query.excludePattern, { 'exclude/**': true });
return Promise.resolve({ results: [] });
return Promise.resolve({ results: [], messages: [] });
}
});

View File

@@ -84,10 +84,10 @@ suite('Color Registry', function () {
}
let undocumentedKeys = Object.keys(missing).map(k => `\`${k}\`: ${missing[k]}`);
assert.deepEqual(undocumentedKeys, [], 'Undocumented colors ids');
assert.deepStrictEqual(undocumentedKeys, [], 'Undocumented colors ids');
let superfluousKeys = Object.keys(colorsInDoc);
assert.deepEqual(superfluousKeys, [], 'Colors ids in doc that do not exist');
assert.deepStrictEqual(superfluousKeys, [], 'Colors ids in doc that do not exist');
});
});

View File

@@ -105,12 +105,12 @@ suite.skip('TextSearch performance (integration)', () => {
function onComplete(): void {
try {
const allEvents = telemetryService.events.map(e => JSON.stringify(e)).join('\n');
assert.equal(telemetryService.events.length, 3, 'Expected 3 telemetry events, got:\n' + allEvents);
assert.strictEqual(telemetryService.events.length, 3, 'Expected 3 telemetry events, got:\n' + allEvents);
const [firstRenderEvent, resultsShownEvent, resultsFinishedEvent] = telemetryService.events;
assert.equal(firstRenderEvent.name, 'searchResultsFirstRender');
assert.equal(resultsShownEvent.name, 'searchResultsShown');
assert.equal(resultsFinishedEvent.name, 'searchResultsFinished');
assert.strictEqual(firstRenderEvent.name, 'searchResultsFirstRender');
assert.strictEqual(resultsShownEvent.name, 'searchResultsShown');
assert.strictEqual(resultsFinishedEvent.name, 'searchResultsFinished');
telemetryService.events = [];

View File

@@ -30,8 +30,8 @@ import { IPathService } from 'vs/workbench/services/path/common/pathService';
import { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { NodeTestBackupFileService } from 'vs/workbench/services/backup/test/electron-browser/backupFileService.test';
import { IWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/common/workingCopyBackup';
import { NodeTestWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/test/electron-browser/workingCopyBackupService.test';
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices';
@@ -39,16 +39,18 @@ import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/ur
import { MouseInputEvent } from 'vs/base/parts/sandbox/common/electronTypes';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IOSProperties, IOSStatistics } from 'vs/platform/native/common/native';
import { homedir, release, tmpdir } from 'os';
import { homedir, release, tmpdir, hostname } from 'os';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { getUserDataPath } from 'vs/platform/environment/node/userDataPath';
import { INativeEnvironmentPaths } from 'vs/platform/environment/common/environmentService';
import product from 'vs/platform/product/common/product';
import { IElevatedFileService } from 'vs/workbench/services/files/common/elevatedFileService';
const args = parseArgs(process.argv, OPTIONS);
export const TestWorkbenchConfiguration: INativeWorkbenchConfiguration = {
windowId: 0,
machineId: 'testMachineId',
sessionId: 'testSessionId',
logLevel: LogLevel.Error,
mainPid: 0,
partsSplashPath: '',
@@ -57,19 +59,21 @@ export const TestWorkbenchConfiguration: INativeWorkbenchConfiguration = {
execPath: process.execPath,
perfMarks: [],
colorScheme: { dark: true, highContrast: false },
os: { release: release() },
...parseArgs(process.argv, OPTIONS)
os: { release: release(), hostname: hostname() },
product,
homeDir: homedir(),
tmpDir: tmpdir(),
userDataDir: getUserDataPath(args),
...args
};
export const TestEnvironmentPaths: INativeEnvironmentPaths = { homeDir: homedir(), tmpDir: tmpdir(), userDataDir: getUserDataPath(TestWorkbenchConfiguration) };
export const TestEnvironmentService = new NativeWorkbenchEnvironmentService(TestWorkbenchConfiguration, TestEnvironmentPaths, TestProductService);
export const TestEnvironmentService = new NativeWorkbenchEnvironmentService(TestWorkbenchConfiguration, TestProductService);
export class TestTextFileService extends NativeTextFileService {
private resolveTextContentError!: FileOperationError | null;
constructor(
@IFileService protected fileService: IFileService,
@IFileService fileService: IFileService,
@IUntitledTextEditorService untitledTextEditorService: IUntitledTextEditorService,
@ILifecycleService lifecycleService: ILifecycleService,
@IInstantiationService instantiationService: IInstantiationService,
@@ -87,7 +91,7 @@ export class TestTextFileService extends NativeTextFileService {
@ILogService logService: ILogService,
@IUriIdentityService uriIdentityService: IUriIdentityService,
@IModeService modeService: IModeService,
@INativeHostService nativeHostService: INativeHostService
@IElevatedFileService elevatedFileService: IElevatedFileService
) {
super(
fileService,
@@ -106,7 +110,7 @@ export class TestTextFileService extends NativeTextFileService {
workingCopyFileService,
uriIdentityService,
modeService,
nativeHostService,
elevatedFileService,
logService
);
}
@@ -115,7 +119,7 @@ export class TestTextFileService extends NativeTextFileService {
this.resolveTextContentError = error;
}
async readStream(resource: URI, options?: IReadTextFileOptions): Promise<ITextFileStreamContent> {
override async readStream(resource: URI, options?: IReadTextFileOptions): Promise<ITextFileStreamContent> {
if (this.resolveTextContentError) {
const error = this.resolveTextContentError;
this.resolveTextContentError = null;
@@ -140,7 +144,7 @@ export class TestTextFileService extends NativeTextFileService {
export class TestNativeTextFileServiceWithEncodingOverrides extends NativeTextFileService {
private _testEncoding: TestEncodingOracle | undefined;
get encoding(): TestEncodingOracle {
override get encoding(): TestEncodingOracle {
if (!this._testEncoding) {
this._testEncoding = this._register(this.instantiationService.createInstance(TestEncodingOracle));
}
@@ -271,7 +275,7 @@ export class TestServiceAccessor {
@IFileService public fileService: TestFileService,
@INativeHostService public nativeHostService: TestNativeHostService,
@IFileDialogService public fileDialogService: TestFileDialogService,
@IBackupFileService public backupFileService: NodeTestBackupFileService,
@IWorkingCopyBackupService public workingCopyBackupService: NodeTestWorkingCopyBackupService,
@IWorkingCopyService public workingCopyService: IWorkingCopyService,
@IEditorService public editorService: IEditorService
) {
@@ -280,8 +284,6 @@ export class TestServiceAccessor {
export class TestNativePathService extends TestPathService {
declare readonly _serviceBrand: undefined;
constructor() {
super(URI.file(homedir()));
}