Refresh master with initial release/0.24 snapshot (#332)

* Initial port of release/0.24 source code

* Fix additional headers

* Fix a typo in launch.json
This commit is contained in:
Karl Burtram
2017-12-15 15:38:57 -08:00
committed by GitHub
parent 271b3a0b82
commit 6ad0df0e3e
7118 changed files with 107999 additions and 56466 deletions

View File

@@ -6,10 +6,7 @@
'use strict';
import * as assert from 'assert';
import * as Platform from 'vs/platform/registry/common/platform';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { Separator } from 'vs/base/browser/ui/actionbar/actionbar';
import { Extensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actionRegistry';
import { prepareActions } from 'vs/workbench/browser/actions';
import { Action } from 'vs/base/common/actions';
@@ -22,26 +19,6 @@ class MyClass extends Action {
suite('Workbench Action Registry', () => {
test('Workbench Action Registration', function () {
let Registry = <IWorkbenchActionRegistry>Platform.Registry.as(Extensions.WorkbenchActions);
let d = new SyncActionDescriptor(MyClass, 'id', 'name');
let oldActions = Registry.getWorkbenchActions().slice(0);
let oldCount = Registry.getWorkbenchActions().length;
Registry.registerWorkbenchAction(d, 'My Alias', 'category');
Registry.registerWorkbenchAction(d, null);
assert.equal(Registry.getWorkbenchActions().length, 1 + oldCount);
assert.strictEqual(d, Registry.getWorkbenchAction('id'));
assert.deepEqual(Registry.getAlias(d.id), 'My Alias');
assert.equal(Registry.getCategory(d.id), 'category');
(<any>Registry).setWorkbenchActions(oldActions);
});
test('Workbench Action Bar prepareActions()', function () {
let a1 = new Separator();
let a2 = new Separator();
@@ -57,4 +34,4 @@ suite('Workbench Action Registry', () => {
assert(actions[1] === a5);
assert(actions[2] === a6);
});
});
});

View File

@@ -6,27 +6,29 @@
'use strict';
import * as assert from 'assert';
import { BaseEditor, EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { EditorInput, EditorOptions, Extensions, IEditorRegistry, IEditorInputFactory } from 'vs/workbench/common/editor';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { EditorInput, EditorOptions, IEditorInputFactory, IEditorInputFactoryRegistry, Extensions as EditorExtensions } from 'vs/workbench/common/editor';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import * as Platform 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 { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
import { workbenchInstantiationService } from 'vs/workbench/test/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';
const NullThemeService = new TestThemeService();
let EditorRegistry: IEditorRegistry = Platform.Registry.as(Extensions.Editors);
let EditorInputRegistry: IEditorInputFactoryRegistry = Platform.Registry.as(EditorExtensions.EditorInputFactories);
export class MyEditor extends BaseEditor {
constructor(id: string, @ITelemetryService telemetryService: ITelemetryService) {
super(id, NullTelemetryService, NullThemeService);
constructor( @ITelemetryService telemetryService: ITelemetryService) {
super('MyEditor', NullTelemetryService, NullThemeService);
}
getId(): string {
@@ -44,8 +46,8 @@ export class MyEditor extends BaseEditor {
export class MyOtherEditor extends BaseEditor {
constructor(id: string, @ITelemetryService telemetryService: ITelemetryService) {
super(id, NullTelemetryService, NullThemeService);
constructor( @ITelemetryService telemetryService: ITelemetryService) {
super('myOtherEditor', NullTelemetryService, NullThemeService);
}
getId(): string {
@@ -100,7 +102,7 @@ class MyResourceInput extends ResourceEditorInput { }
suite('Workbench BaseEditor', () => {
test('BaseEditor API', function (done) {
let e = new MyEditor('id', NullTelemetryService);
let e = new MyEditor(NullTelemetryService);
let input = new MyOtherInput();
let options = new EditorOptions();
@@ -127,14 +129,14 @@ suite('Workbench BaseEditor', () => {
});
test('EditorDescriptor', function () {
let d = new EditorDescriptor('id', 'name', 'vs/workbench/test/browser/parts/editor/baseEditor.test', 'MyClass');
let d = new EditorDescriptor(MyEditor, 'id', 'name');
assert.strictEqual(d.getId(), 'id');
assert.strictEqual(d.getName(), 'name');
});
test('Editor Registration', function () {
let d1 = new EditorDescriptor('id1', 'name', 'vs/workbench/test/browser/parts/editor/baseEditor.test', 'MyClass');
let d2 = new EditorDescriptor('id2', 'name', 'vs/workbench/test/browser/parts/editor/baseEditor.test', 'MyOtherClass');
let d1 = new EditorDescriptor(MyEditor, 'id1', 'name');
let d2 = new EditorDescriptor(MyOtherEditor, 'id2', 'name');
let oldEditorsCnt = EditorRegistry.getEditors().length;
let oldInputCnt = (<any>EditorRegistry).getEditorInputs().length;
@@ -153,9 +155,9 @@ suite('Workbench BaseEditor', () => {
assert(!EditorRegistry.getEditorById('id3'));
});
test('Editor Lookup favors specific class over superclass (match on specific class)', function (done) {
let d1 = new EditorDescriptor('id1', 'name', 'vs/workbench/test/browser/parts/editor/baseEditor.test', 'MyEditor');
let d2 = new EditorDescriptor('id2', 'name', 'vs/workbench/test/browser/parts/editor/baseEditor.test', 'MyOtherEditor');
test('Editor Lookup favors specific class over superclass (match on specific class)', function () {
let d1 = new EditorDescriptor(MyEditor, 'id1', 'name');
let d2 = new EditorDescriptor(MyOtherEditor, 'id2', 'name');
let oldEditors = EditorRegistry.getEditors();
(<any>EditorRegistry).setEditors([]);
@@ -165,19 +167,17 @@ suite('Workbench BaseEditor', () => {
let inst = new TestInstantiationService();
inst.createInstance(EditorRegistry.getEditor(inst.createInstance(MyResourceInput, 'fake', '', '', PLAINTEXT_MODE_ID, false)), 'id').then(editor => {
assert.strictEqual(editor.getId(), 'myEditor');
const editor = EditorRegistry.getEditor(inst.createInstance(MyResourceInput, 'fake', '', URI.file('/fake'))).instantiate(inst);
assert.strictEqual(editor.getId(), 'myEditor');
return inst.createInstance(EditorRegistry.getEditor(inst.createInstance(ResourceEditorInput, 'fake', '', '', PLAINTEXT_MODE_ID, false)), 'id').then(editor => {
assert.strictEqual(editor.getId(), 'myOtherEditor');
const otherEditor = EditorRegistry.getEditor(inst.createInstance(ResourceEditorInput, 'fake', '', URI.file('/fake'))).instantiate(inst);
assert.strictEqual(otherEditor.getId(), 'myOtherEditor');
(<any>EditorRegistry).setEditors(oldEditors);
});
}).done(() => done());
(<any>EditorRegistry).setEditors(oldEditors);
});
test('Editor Lookup favors specific class over superclass (match on super class)', function (done) {
let d1 = new EditorDescriptor('id1', 'name', 'vs/workbench/test/browser/parts/editor/baseEditor.test', 'MyOtherEditor');
test('Editor Lookup favors specific class over superclass (match on super class)', function () {
let d1 = new EditorDescriptor(MyOtherEditor, 'id1', 'name');
let oldEditors = EditorRegistry.getEditors();
(<any>EditorRegistry).setEditors([]);
@@ -186,18 +186,17 @@ suite('Workbench BaseEditor', () => {
let inst = new TestInstantiationService();
inst.createInstance(EditorRegistry.getEditor(inst.createInstance(MyResourceInput, 'fake', '', '', PLAINTEXT_MODE_ID, false)), 'id').then(editor => {
assert.strictEqual('myOtherEditor', editor.getId());
const editor = EditorRegistry.getEditor(inst.createInstance(MyResourceInput, 'fake', '', URI.file('/fake'))).instantiate(inst);
assert.strictEqual('myOtherEditor', editor.getId());
(<any>EditorRegistry).setEditors(oldEditors);
}).done(() => done());
(<any>EditorRegistry).setEditors(oldEditors);
});
test('Editor Input Factory', function () {
EditorRegistry.setInstantiationService(workbenchInstantiationService());
EditorRegistry.registerEditorInputFactory('myInputId', MyInputFactory);
EditorInputRegistry.setInstantiationService(workbenchInstantiationService());
EditorInputRegistry.registerEditorInputFactory('myInputId', MyInputFactory);
let factory = EditorRegistry.getEditorInputFactory('myInputId');
let factory = EditorInputRegistry.getEditorInputFactory('myInputId');
assert(factory);
});

View File

@@ -7,7 +7,7 @@
import * as assert from 'assert';
import { EditorStacksModel, EditorGroup, EditorCloseEvent } from 'vs/workbench/common/editor/editorStacksModel';
import { EditorInput, IFileEditorInput, IEditorIdentifier, IEditorGroup, IStacksModelChangeEvent, IEditorRegistry, Extensions as EditorExtensions, IEditorInputFactory, IEditorCloseEvent } from 'vs/workbench/common/editor';
import { Extensions as EditorExtensions, IEditorInputFactoryRegistry, EditorInput, IFileEditorInput, IEditorIdentifier, IEditorGroup, IStacksModelChangeEvent, IEditorInputFactory, IEditorCloseEvent } from 'vs/workbench/common/editor';
import URI from 'vs/base/common/uri';
import { TestStorageService, TestLifecycleService, TestContextService } from 'vs/workbench/test/workbenchTestServices';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
@@ -22,7 +22,6 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import 'vs/workbench/browser/parts/editor/baseEditor';
function create(): EditorStacksModel {
let inst = new TestInstantiationService();
@@ -202,7 +201,7 @@ class TestEditorInputFactory implements IEditorInputFactory {
}
}
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).registerEditorInputFactory('testEditorInput', TestEditorInputFactory);
(<IEditorInputFactoryRegistry>Registry.as(EditorExtensions.EditorInputFactories)).registerEditorInputFactory('testEditorInput', TestEditorInputFactory);
suite('Editor Stacks Model', () => {
@@ -1199,7 +1198,7 @@ suite('Editor Stacks Model', () => {
config.setUserConfiguration('workbench', { editor: { openPositioning: 'right' } });
inst.stub(IConfigurationService, config);
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).setInstantiationService(inst);
(<IEditorInputFactoryRegistry>Registry.as(EditorExtensions.EditorInputFactories)).setInstantiationService(inst);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel, true);
let group = model.openGroup('group');
@@ -1244,7 +1243,7 @@ suite('Editor Stacks Model', () => {
inst.stub(IConfigurationService, config);
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).setInstantiationService(inst);
(<IEditorInputFactoryRegistry>Registry.as(EditorExtensions.EditorInputFactories)).setInstantiationService(inst);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel, true);
@@ -1327,7 +1326,7 @@ suite('Editor Stacks Model', () => {
inst.stub(IConfigurationService, config);
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).setInstantiationService(inst);
(<IEditorInputFactoryRegistry>Registry.as(EditorExtensions.EditorInputFactories)).setInstantiationService(inst);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel, true);
@@ -1378,7 +1377,7 @@ suite('Editor Stacks Model', () => {
inst.stub(IConfigurationService, config);
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).setInstantiationService(inst);
(<IEditorInputFactoryRegistry>Registry.as(EditorExtensions.EditorInputFactories)).setInstantiationService(inst);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel, true);
@@ -1419,7 +1418,7 @@ suite('Editor Stacks Model', () => {
config.setUserConfiguration('workbench', { editor: { openPositioning: 'right' } });
inst.stub(IConfigurationService, config);
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).setInstantiationService(inst);
(<IEditorInputFactoryRegistry>Registry.as(EditorExtensions.EditorInputFactories)).setInstantiationService(inst);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel, false);

View File

@@ -11,7 +11,7 @@ import { Promise, TPromise } from 'vs/base/common/winjs.base';
import Event from 'vs/base/common/event';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { Registry } from 'vs/platform/registry/common/platform';
import { QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions as QuickOpenExtensions, QuickOpenAction } from 'vs/workbench/browser/quickopen';
import { QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions as QuickOpenExtensions, QuickOpenAction, QuickOpenHandler } from 'vs/workbench/browser/quickopen';
export class TestQuickOpenService implements IQuickOpenService {
public _serviceBrand: any;
@@ -61,11 +61,15 @@ export class TestQuickOpenService implements IQuickOpenService {
suite('Workbench QuickOpen', () => {
class TestHandler extends QuickOpenHandler {
}
test('QuickOpen Handler and Registry', () => {
let registry = (<IQuickOpenRegistry>Registry.as(QuickOpenExtensions.Quickopen));
let handler = new QuickOpenHandlerDescriptor(
'test',
'TestHandler',
TestHandler,
'testhandler',
',',
'Handler',
null

View File

@@ -7,13 +7,24 @@
import * as assert from 'assert';
import * as Platform from 'vs/platform/registry/common/platform';
import { ViewletDescriptor, Extensions } from 'vs/workbench/browser/viewlet';
import { ViewletDescriptor, Extensions, Viewlet } from 'vs/workbench/browser/viewlet';
import * as Types from 'vs/base/common/types';
suite('Workbench Viewlet', () => {
class TestViewlet extends Viewlet {
constructor() {
super('id', null, null);
}
public layout(dimension: any): void {
throw new Error('Method not implemented.');
}
}
test('ViewletDescriptor API', function () {
let d = new ViewletDescriptor('moduleId', 'ctorName', 'id', 'name', 'class', 5);
let d = new ViewletDescriptor(TestViewlet, 'id', 'name', 'class', 5);
assert.strictEqual(d.id, 'id');
assert.strictEqual(d.name, 'name');
assert.strictEqual(d.cssClass, 'class');
@@ -21,11 +32,11 @@ suite('Workbench Viewlet', () => {
});
test('Editor Aware ViewletDescriptor API', function () {
let d = new ViewletDescriptor('moduleId', 'ctorName', 'id', 'name', 'class', 5);
let d = new ViewletDescriptor(TestViewlet, 'id', 'name', 'class', 5);
assert.strictEqual(d.id, 'id');
assert.strictEqual(d.name, 'name');
d = new ViewletDescriptor('moduleId', 'ctorName', 'id', 'name', 'class', 5);
d = new ViewletDescriptor(TestViewlet, 'id', 'name', 'class', 5);
assert.strictEqual(d.id, 'id');
assert.strictEqual(d.name, 'name');
});
@@ -36,7 +47,7 @@ suite('Workbench Viewlet', () => {
assert(Types.isFunction(Platform.Registry.as(Extensions.Viewlets).getViewlets));
let oldCount = Platform.Registry.as(Extensions.Viewlets).getViewlets().length;
let d = new ViewletDescriptor('moduleId', 'ctorName', 'reg-test-id', 'name');
let d = new ViewletDescriptor(TestViewlet, 'reg-test-id', 'name');
Platform.Registry.as(Extensions.Viewlets).registerViewlet(d);
assert(d === Platform.Registry.as(Extensions.Viewlets).getViewlet('reg-test-id'));

View File

@@ -9,12 +9,13 @@ import * as assert from 'assert';
import URI from 'vs/base/common/uri';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration';
import { MainThreadConfigurationShape } from 'vs/workbench/api/node/extHost.protocol';
import { MainThreadConfigurationShape, IConfigurationInitData } from 'vs/workbench/api/node/extHost.protocol';
import { TPromise } from 'vs/base/common/winjs.base';
import { ConfigurationTarget, ConfigurationEditingErrorCode, ConfigurationEditingError } from 'vs/workbench/services/configuration/common/configurationEditing';
import { ConfigurationModel } from 'vs/platform/configuration/common/configuration';
import { ConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
import { TestThreadService } from './testThreadService';
import { mock } from 'vs/workbench/test/electron-browser/api/mock';
import { IWorkspaceFolder, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
suite('ExtHostConfiguration', function () {
@@ -30,12 +31,17 @@ suite('ExtHostConfiguration', function () {
if (!shape) {
shape = new class extends mock<MainThreadConfigurationShape>() { };
}
return new ExtHostConfiguration(shape, new ExtHostWorkspace(new TestThreadService(), null), {
return new ExtHostConfiguration(shape, new ExtHostWorkspace(new TestThreadService(), null), createConfigurationData(contents));
}
function createConfigurationData(contents: any): IConfigurationInitData {
return {
defaults: new ConfigurationModel(contents),
user: new ConfigurationModel(contents),
workspace: new ConfigurationModel(),
folders: Object.create(null)
});
folders: Object.create(null),
configurationScopes: []
};
}
test('getConfiguration fails regression test 1.7.1 -> 1.8 #15552', function () {
@@ -101,7 +107,8 @@ suite('ExtHostConfiguration', function () {
}
}, ['editor.wordWrap']),
workspace: new ConfigurationModel({}, []),
folders: Object.create(null)
folders: Object.create(null),
configurationScopes: []
}
);
@@ -131,7 +138,7 @@ suite('ExtHostConfiguration', function () {
new class extends mock<MainThreadConfigurationShape>() { },
new ExtHostWorkspace(new TestThreadService(), {
'id': 'foo',
'roots': [URI.file('foo')],
'folders': [aWorkspaceFolder(URI.file('foo'), 0)],
'name': 'foo'
}),
{
@@ -146,7 +153,8 @@ suite('ExtHostConfiguration', function () {
}
}, ['editor.wordWrap']),
workspace,
folders
folders,
configurationScopes: []
}
);
@@ -203,7 +211,7 @@ suite('ExtHostConfiguration', function () {
new class extends mock<MainThreadConfigurationShape>() { },
new ExtHostWorkspace(new TestThreadService(), {
'id': 'foo',
'roots': [firstRoot, secondRoot],
'folders': [aWorkspaceFolder(firstRoot, 0), aWorkspaceFolder(secondRoot, 1)],
'name': 'foo'
}),
{
@@ -219,7 +227,8 @@ suite('ExtHostConfiguration', function () {
}
}, ['editor.wordWrap']),
workspace,
folders
folders,
configurationScopes: []
}
);
@@ -393,7 +402,7 @@ suite('ExtHostConfiguration', function () {
const shape = new class extends mock<MainThreadConfigurationShape>() {
$updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): TPromise<any> {
return TPromise.wrapError(new ConfigurationEditingError('Unknown Key', ConfigurationEditingErrorCode.ERROR_UNKNOWN_KEY)); // something !== OK
return TPromise.wrapError(new Error('Unknown Key')); // something !== OK
}
};
@@ -402,4 +411,76 @@ suite('ExtHostConfiguration', function () {
.update('', true, false)
.then(() => assert.ok(false), err => { /* expecting rejection */ });
});
test('configuration change event', (done) => {
const workspaceFolder = aWorkspaceFolder(URI.file('folder1'), 0);
const testObject = new ExtHostConfiguration(
new class extends mock<MainThreadConfigurationShape>() { },
new ExtHostWorkspace(new TestThreadService(), {
'id': 'foo',
'folders': [workspaceFolder],
'name': 'foo'
}),
createConfigurationData({
'farboo': {
'config': false,
'updatedconfig': false
}
})
);
const newConfigData = createConfigurationData({
'farboo': {
'config': false,
'updatedconfig': true,
'newConfig': true,
}
});
const changedConfigurationByResource = Object.create({});
changedConfigurationByResource[workspaceFolder.uri.toString()] = new ConfigurationModel({
'farboo': {
'newConfig': true,
}
}, ['farboo.newConfig']);
const configEventData = {
changedConfiguration: new ConfigurationModel({
'farboo': {
'updatedConfig': true,
}
}, ['farboo.updatedConfig']),
changedConfigurationByResource
};
testObject.onDidChangeConfiguration(e => {
assert.deepEqual(testObject.getConfiguration().get('farboo'), {
'config': false,
'updatedconfig': true,
'newConfig': true,
});
assert.ok(e.affectsConfiguration('farboo'));
assert.ok(e.affectsConfiguration('farboo', workspaceFolder.uri));
assert.ok(e.affectsConfiguration('farboo', URI.file('any')));
assert.ok(e.affectsConfiguration('farboo.updatedConfig'));
assert.ok(e.affectsConfiguration('farboo.updatedConfig', workspaceFolder.uri));
assert.ok(e.affectsConfiguration('farboo.updatedConfig', URI.file('any')));
assert.ok(e.affectsConfiguration('farboo.newConfig'));
assert.ok(e.affectsConfiguration('farboo.newConfig', workspaceFolder.uri));
assert.ok(!e.affectsConfiguration('farboo.newConfig', URI.file('any')));
assert.ok(!e.affectsConfiguration('farboo.config'));
assert.ok(!e.affectsConfiguration('farboo.config', workspaceFolder.uri));
assert.ok(!e.affectsConfiguration('farboo.config', URI.file('any')));
done();
});
testObject.$acceptConfigurationChanged(newConfigData, configEventData);
});
function aWorkspaceFolder(uri: URI, index: number, name: string = ''): IWorkspaceFolder {
return new WorkspaceFolder({ uri, name, index });
}
});

View File

@@ -10,10 +10,9 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors';
import { TextDocumentSaveReason, TextEdit, Position, EndOfLine } from 'vs/workbench/api/node/extHostTypes';
import { MainThreadWorkspaceShape } from 'vs/workbench/api/node/extHost.protocol';
import { MainThreadEditorsShape, IWorkspaceResourceEdit } from 'vs/workbench/api/node/extHost.protocol';
import { ExtHostDocumentSaveParticipant } from 'vs/workbench/api/node/extHostDocumentSaveParticipant';
import { OneGetThreadService } from './testThreadService';
import { IResourceEdit } from 'vs/editor/common/services/bulkEdit';
import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
import * as vscode from 'vscode';
import { mock } from 'vs/workbench/test/electron-browser/api/mock';
@@ -21,7 +20,7 @@ import { mock } from 'vs/workbench/test/electron-browser/api/mock';
suite('ExtHostDocumentSaveParticipant', () => {
let resource = URI.parse('foo:bar');
let workspace = new class extends mock<MainThreadWorkspaceShape>() { };
let mainThreadEditors = new class extends mock<MainThreadEditorsShape>() { };
let documents: ExtHostDocuments;
setup(() => {
@@ -40,12 +39,12 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
test('no listeners, no problem', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace);
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors);
return participant.$participateInSave(resource, SaveReason.EXPLICIT).then(() => assert.ok(true));
});
test('event delivery', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace);
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors);
let event: vscode.TextDocumentWillSaveEvent;
let sub = participant.onWillSaveTextDocumentEvent(function (e) {
@@ -62,7 +61,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
test('event delivery, immutable', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace);
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors);
let event: vscode.TextDocumentWillSaveEvent;
let sub = participant.onWillSaveTextDocumentEvent(function (e) {
@@ -78,7 +77,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
test('event delivery, bad listener', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace);
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors);
let sub = participant.onWillSaveTextDocumentEvent(function (e) {
throw new Error('💀');
@@ -93,7 +92,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
test('event delivery, bad listener doesn\'t prevent more events', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace);
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors);
let sub1 = participant.onWillSaveTextDocumentEvent(function (e) {
throw new Error('💀');
@@ -112,7 +111,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
test('event delivery, in subscriber order', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace);
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors);
let counter = 0;
let sub1 = participant.onWillSaveTextDocumentEvent(function (event) {
@@ -130,7 +129,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
test('event delivery, ignore bad listeners', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace, { timeout: 5, errors: 1 });
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors, { timeout: 5, errors: 1 });
let callCount = 0;
let sub = participant.onWillSaveTextDocumentEvent(function (event) {
@@ -151,7 +150,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
test('event delivery, overall timeout', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace, { timeout: 20, errors: 5 });
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors, { timeout: 20, errors: 5 });
let callCount = 0;
let sub1 = participant.onWillSaveTextDocumentEvent(function (event) {
@@ -179,7 +178,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
test('event delivery, waitUntil', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace);
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors);
let sub = participant.onWillSaveTextDocumentEvent(function (event) {
@@ -195,7 +194,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
test('event delivery, waitUntil must be called sync', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace);
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors);
let sub = participant.onWillSaveTextDocumentEvent(function (event) {
@@ -218,7 +217,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
test('event delivery, waitUntil will timeout', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace, { timeout: 5, errors: 3 });
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors, { timeout: 5, errors: 3 });
let sub = participant.onWillSaveTextDocumentEvent(function (event) {
event.waitUntil(TPromise.timeout(15));
@@ -233,7 +232,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
});
test('event delivery, waitUntil failure handling', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, workspace);
const participant = new ExtHostDocumentSaveParticipant(documents, mainThreadEditors);
let sub1 = participant.onWillSaveTextDocumentEvent(function (e) {
e.waitUntil(TPromise.wrapError(new Error('dddd')));
@@ -253,9 +252,9 @@ suite('ExtHostDocumentSaveParticipant', () => {
test('event delivery, pushEdits sync', () => {
let edits: IResourceEdit[];
const participant = new ExtHostDocumentSaveParticipant(documents, new class extends mock<MainThreadWorkspaceShape>() {
$applyWorkspaceEdit(_edits) {
let edits: IWorkspaceResourceEdit[];
const participant = new ExtHostDocumentSaveParticipant(documents, new class extends mock<MainThreadEditorsShape>() {
$tryApplyWorkspaceEdit(_edits: IWorkspaceResourceEdit[]) {
edits = _edits;
return TPromise.as(true);
}
@@ -269,15 +268,16 @@ suite('ExtHostDocumentSaveParticipant', () => {
return participant.$participateInSave(resource, SaveReason.EXPLICIT).then(() => {
sub.dispose();
assert.equal(edits.length, 2);
assert.equal(edits.length, 1);
assert.equal(edits[0].edits.length, 2);
});
});
test('event delivery, concurrent change', () => {
let edits: IResourceEdit[];
const participant = new ExtHostDocumentSaveParticipant(documents, new class extends mock<MainThreadWorkspaceShape>() {
$applyWorkspaceEdit(_edits) {
let edits: IWorkspaceResourceEdit[];
const participant = new ExtHostDocumentSaveParticipant(documents, new class extends mock<MainThreadEditorsShape>() {
$tryApplyWorkspaceEdit(_edits: IWorkspaceResourceEdit[]) {
edits = _edits;
return TPromise.as(true);
}
@@ -310,20 +310,23 @@ suite('ExtHostDocumentSaveParticipant', () => {
test('event delivery, two listeners -> two document states', () => {
const participant = new ExtHostDocumentSaveParticipant(documents, new class extends mock<MainThreadWorkspaceShape>() {
$applyWorkspaceEdit(_edits: IResourceEdit[]) {
const participant = new ExtHostDocumentSaveParticipant(documents, new class extends mock<MainThreadEditorsShape>() {
$tryApplyWorkspaceEdit(_edits: IWorkspaceResourceEdit[]) {
for (const { resource, newText, range } of _edits) {
documents.$acceptModelChanged(resource.toString(), {
changes: [{
range,
rangeLength: undefined,
text: newText
}],
eol: undefined,
versionId: documents.getDocumentData(resource).version + 1
}, true);
for (const { resource, edits } of _edits) {
for (const { newText, range } of edits) {
documents.$acceptModelChanged(resource.toString(), {
changes: [{
range,
rangeLength: undefined,
text: newText
}],
eol: undefined,
versionId: documents.getDocumentData(resource).version + 1
}, true);
}
}
return TPromise.as(true);
}
});

View File

@@ -811,7 +811,11 @@ suite('ExtHostLanguageFeatures', function () {
disposables.push(extHost.registerSignatureHelpProvider(defaultSelector, <vscode.SignatureHelpProvider>{
provideSignatureHelp(): vscode.SignatureHelp {
return new types.SignatureHelp();
return {
signatures: [],
activeParameter: 0,
activeSignature: 0
};
}
}, []));

View File

@@ -61,9 +61,11 @@ suite('ExtHostTextEditorOptions', () => {
$tryShowEditor: undefined,
$tryHideEditor: undefined,
$trySetDecorations: undefined,
$trySetDecorationsFast: undefined,
$tryRevealRange: undefined,
$trySetSelections: undefined,
$tryApplyEdits: undefined,
$tryApplyWorkspaceEdit: undefined,
$tryInsertSnippet: undefined,
$getDiffInformation: undefined
};

View File

@@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import { TPromise } from 'vs/base/common/winjs.base';
import * as extHostTypes from 'vs/workbench/api/node/extHostTypes';
import { MainContext, MainThreadEditorsShape, IWorkspaceResourceEdit } from 'vs/workbench/api/node/extHost.protocol';
import URI from 'vs/base/common/uri';
import { mock } from 'vs/workbench/test/electron-browser/api/mock';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors';
import { OneGetThreadService, TestThreadService } from 'vs/workbench/test/electron-browser/api/testThreadService';
import { ExtHostEditors } from 'vs/workbench/api/node/extHostTextEditors';
suite('ExtHostTextEditors.applyWorkspaceEdit', () => {
const resource = URI.parse('foo:bar');
let editors: ExtHostEditors;
let workspaceResourceEdits: IWorkspaceResourceEdit[];
setup(() => {
workspaceResourceEdits = null;
let threadService = new TestThreadService();
threadService.setTestInstance(MainContext.MainThreadEditors, new class extends mock<MainThreadEditorsShape>() {
$tryApplyWorkspaceEdit(_workspaceResourceEdits: IWorkspaceResourceEdit[]): TPromise<boolean> {
workspaceResourceEdits = _workspaceResourceEdits;
return TPromise.as(true);
}
});
const documentsAndEditors = new ExtHostDocumentsAndEditors(OneGetThreadService(null));
documentsAndEditors.$acceptDocumentsAndEditorsDelta({
addedDocuments: [{
isDirty: false,
modeId: 'foo',
url: resource,
versionId: 1337,
lines: ['foo'],
EOL: '\n',
}]
});
editors = new ExtHostEditors(threadService, documentsAndEditors);
});
test('uses version id if document available', () => {
let edit = new extHostTypes.WorkspaceEdit();
edit.replace(resource, new extHostTypes.Range(0, 0, 0, 0), 'hello');
return editors.applyWorkspaceEdit(edit).then((result) => {
assert.equal(workspaceResourceEdits.length, 1);
assert.equal(workspaceResourceEdits[0].modelVersionId, 1337);
});
});
test('does not use version id if document is not available', () => {
let edit = new extHostTypes.WorkspaceEdit();
edit.replace(URI.parse('foo:bar2'), new extHostTypes.Range(0, 0, 0, 0), 'hello');
return editors.applyWorkspaceEdit(edit).then((result) => {
assert.equal(workspaceResourceEdits.length, 1);
assert.ok(typeof workspaceResourceEdits[0].modelVersionId === 'undefined');
});
});
});

View File

@@ -7,169 +7,34 @@
import * as assert from 'assert';
import URI from 'vs/base/common/uri';
import { basename } from 'path';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { TestThreadService } from './testThreadService';
import { normalize } from 'vs/base/common/paths';
import { IWorkspaceFolderData } from 'vs/platform/workspace/common/workspace';
suite('ExtHostWorkspace', function () {
function assertAsRelativePath(workspace: ExtHostWorkspace, input: string, expected: string, includeWorkspace?: boolean) {
const actual = workspace.getRelativePath(input, includeWorkspace);
if (actual === expected) {
assert.ok(true);
} else {
assert.equal(actual, normalize(expected, true));
}
}
test('asRelativePath', function () {
const ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', roots: [URI.file('/Coding/Applications/NewsWoWBot')], name: 'Test' });
// const ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', folders: [aWorkspaceFolderData(URI.file('/Coding/Applications/NewsWoWBot'), 0)], name: 'Test' });
assert.equal(ws.getRelativePath('/Coding/Applications/NewsWoWBot/bernd/das/brot'), 'bernd/das/brot');
assert.equal(ws.getRelativePath('/Apps/DartPubCache/hosted/pub.dartlang.org/convert-2.0.1/lib/src/hex.dart'),
'/Apps/DartPubCache/hosted/pub.dartlang.org/convert-2.0.1/lib/src/hex.dart');
// assertAsRelativePath(ws, '/Coding/Applications/NewsWoWBot/bernd/das/brot', 'bernd/das/brot');
// assertAsRelativePath(ws, '/Apps/DartPubCache/hosted/pub.dartlang.org/convert-2.0.1/lib/src/hex.dart',
// '/Apps/DartPubCache/hosted/pub.dartlang.org/convert-2.0.1/lib/src/hex.dart');
assert.equal(ws.getRelativePath(''), '');
assert.equal(ws.getRelativePath('/foo/bar'), '/foo/bar');
assert.equal(ws.getRelativePath('in/out'), 'in/out');
// assertAsRelativePath(ws, '', '');
// assertAsRelativePath(ws, '/foo/bar', '/foo/bar');
// assertAsRelativePath(ws, 'in/out', 'in/out');
});
test('asRelativePath, same paths, #11402', function () {
const root = '/home/aeschli/workspaces/samples/docker';
const input = '/home/aeschli/workspaces/samples/docker';
const ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', roots: [URI.file(root)], name: 'Test' });
assert.equal(ws.getRelativePath(input), input);
const input2 = '/home/aeschli/workspaces/samples/docker/a.file';
assert.equal(ws.getRelativePath(input2), 'a.file');
});
test('asRelativePath, no workspace', function () {
const ws = new ExtHostWorkspace(new TestThreadService(), null);
assert.equal(ws.getRelativePath(''), '');
assert.equal(ws.getRelativePath('/foo/bar'), '/foo/bar');
});
test('asRelativePath, multiple folders', function () {
const ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', roots: [URI.file('/Coding/One'), URI.file('/Coding/Two')], name: 'Test' });
assert.equal(ws.getRelativePath('/Coding/One/file.txt'), 'One/file.txt');
assert.equal(ws.getRelativePath('/Coding/Two/files/out.txt'), 'Two/files/out.txt');
assert.equal(ws.getRelativePath('/Coding/Two2/files/out.txt'), '/Coding/Two2/files/out.txt');
});
test('slightly inconsistent behaviour of asRelativePath and getWorkspaceFolder, #31553', function () {
const mrws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', roots: [URI.file('/Coding/One'), URI.file('/Coding/Two')], name: 'Test' });
assert.equal(mrws.getRelativePath('/Coding/One/file.txt'), 'One/file.txt');
assert.equal(mrws.getRelativePath('/Coding/One/file.txt', true), 'One/file.txt');
assert.equal(mrws.getRelativePath('/Coding/One/file.txt', false), 'file.txt');
assert.equal(mrws.getRelativePath('/Coding/Two/files/out.txt'), 'Two/files/out.txt');
assert.equal(mrws.getRelativePath('/Coding/Two/files/out.txt', true), 'Two/files/out.txt');
assert.equal(mrws.getRelativePath('/Coding/Two/files/out.txt', false), 'files/out.txt');
assert.equal(mrws.getRelativePath('/Coding/Two2/files/out.txt'), '/Coding/Two2/files/out.txt');
assert.equal(mrws.getRelativePath('/Coding/Two2/files/out.txt', true), '/Coding/Two2/files/out.txt');
assert.equal(mrws.getRelativePath('/Coding/Two2/files/out.txt', false), '/Coding/Two2/files/out.txt');
const srws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', roots: [URI.file('/Coding/One')], name: 'Test' });
assert.equal(srws.getRelativePath('/Coding/One/file.txt'), 'file.txt');
assert.equal(srws.getRelativePath('/Coding/One/file.txt', false), 'file.txt');
assert.equal(srws.getRelativePath('/Coding/One/file.txt', true), 'One/file.txt');
assert.equal(srws.getRelativePath('/Coding/Two2/files/out.txt'), '/Coding/Two2/files/out.txt');
assert.equal(srws.getRelativePath('/Coding/Two2/files/out.txt', true), '/Coding/Two2/files/out.txt');
assert.equal(srws.getRelativePath('/Coding/Two2/files/out.txt', false), '/Coding/Two2/files/out.txt');
});
test('getPath, legacy', function () {
let ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', name: 'Test', roots: [] });
assert.equal(ws.getPath(), undefined);
ws = new ExtHostWorkspace(new TestThreadService(), null);
assert.equal(ws.getPath(), undefined);
ws = new ExtHostWorkspace(new TestThreadService(), undefined);
assert.equal(ws.getPath(), undefined);
ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', name: 'Test', roots: [URI.file('Folder'), URI.file('Another/Folder')] });
assert.equal(ws.getPath().replace(/\\/g, '/'), '/Folder');
ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', name: 'Test', roots: [URI.file('/Folder')] });
assert.equal(ws.getPath().replace(/\\/g, '/'), '/Folder');
});
test('WorkspaceFolder has name and index', function () {
const ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', roots: [URI.file('/Coding/One'), URI.file('/Coding/Two')], name: 'Test' });
const [one, two] = ws.getWorkspaceFolders();
assert.equal(one.name, 'One');
assert.equal(one.index, 0);
assert.equal(two.name, 'Two');
assert.equal(two.index, 1);
});
test('getContainingWorkspaceFolder', function () {
const ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', name: 'Test', roots: [URI.file('/Coding/One'), URI.file('/Coding/Two'), URI.file('/Coding/Two/Nested')] });
let folder = ws.getWorkspaceFolder(URI.file('/foo/bar'));
assert.equal(folder, undefined);
folder = ws.getWorkspaceFolder(URI.file('/Coding/One/file/path.txt'));
assert.equal(folder.name, 'One');
folder = ws.getWorkspaceFolder(URI.file('/Coding/Two/file/path.txt'));
assert.equal(folder.name, 'Two');
folder = ws.getWorkspaceFolder(URI.file('/Coding/Two/Nest'));
assert.equal(folder.name, 'Two');
folder = ws.getWorkspaceFolder(URI.file('/Coding/Two/Nested/file'));
assert.equal(folder.name, 'Nested');
folder = ws.getWorkspaceFolder(URI.file('/Coding/Two/Nested/f'));
assert.equal(folder.name, 'Nested');
folder = ws.getWorkspaceFolder(URI.file('/Coding/Two/Nested'));
assert.equal(folder.name, 'Two');
folder = ws.getWorkspaceFolder(URI.file('/Coding/Two/Nested/'));
assert.equal(folder.name, 'Two');
folder = ws.getWorkspaceFolder(URI.file('/Coding/Two'));
assert.equal(folder, undefined);
});
test('Multiroot change event should have a delta, #29641', function () {
let ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', name: 'Test', roots: [] });
let sub = ws.onDidChangeWorkspace(e => {
assert.deepEqual(e.added, []);
assert.deepEqual(e.removed, []);
});
ws.$acceptWorkspaceData({ id: 'foo', name: 'Test', roots: [] });
sub.dispose();
sub = ws.onDidChangeWorkspace(e => {
assert.deepEqual(e.removed, []);
assert.equal(e.added.length, 1);
assert.equal(e.added[0].uri.toString(), 'foo:bar');
});
ws.$acceptWorkspaceData({ id: 'foo', name: 'Test', roots: [URI.parse('foo:bar')] });
sub.dispose();
sub = ws.onDidChangeWorkspace(e => {
assert.deepEqual(e.removed, []);
assert.equal(e.added.length, 1);
assert.equal(e.added[0].uri.toString(), 'foo:bar2');
});
ws.$acceptWorkspaceData({ id: 'foo', name: 'Test', roots: [URI.parse('foo:bar'), URI.parse('foo:bar2')] });
sub.dispose();
sub = ws.onDidChangeWorkspace(e => {
assert.equal(e.removed.length, 2);
assert.equal(e.removed[0].uri.toString(), 'foo:bar');
assert.equal(e.removed[1].uri.toString(), 'foo:bar2');
assert.equal(e.added.length, 1);
assert.equal(e.added[0].uri.toString(), 'foo:bar3');
});
ws.$acceptWorkspaceData({ id: 'foo', name: 'Test', roots: [URI.parse('foo:bar3')] });
sub.dispose();
});
test('Multiroot change event is immutable', function () {
assert.equal(1, 1);
});
});

View File

@@ -10,16 +10,14 @@ import * as sinon from 'sinon';
import URI from 'vs/base/common/uri';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions, IConfigurationRegistry, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { MainThreadConfiguration } from 'vs/workbench/api/electron-browser/mainThreadConfiguration';
import { ConfigurationTarget, IConfigurationEditingService } from 'vs/workbench/services/configuration/common/configurationEditing';
import { ConfigurationEditingService } from 'vs/workbench/services/configuration/node/configurationEditingService';
import { OneGetThreadService } from './testThreadService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { WorkspaceService } from 'vs/workbench/services/configuration/node/configurationService';
suite('ExtHostConfiguration', function () {
suite('MainThreadConfiguration', function () {
let instantiationService: TestInstantiationService;
let target: sinon.SinonSpy;
@@ -47,182 +45,183 @@ suite('ExtHostConfiguration', function () {
});
setup(() => {
instantiationService = new TestInstantiationService();
instantiationService.stub(IConfigurationService, new TestConfigurationService());
target = sinon.spy();
instantiationService.stub(IConfigurationEditingService, ConfigurationEditingService);
instantiationService.stub(IConfigurationEditingService, 'writeConfiguration', target);
instantiationService = new TestInstantiationService();
instantiationService.stub(IConfigurationService, WorkspaceService);
instantiationService.stub(IConfigurationService, 'onDidUpdateConfiguration', sinon.mock());
instantiationService.stub(IConfigurationService, 'onDidChangeConfiguration', sinon.mock());
instantiationService.stub(IConfigurationService, 'updateValue', target);
});
test('update resource configuration without configuration target defaults to workspace in multi root workspace when no resource is provided', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => true });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.WORKSPACE });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$updateConfigurationOption(null, 'extHostConfiguration.resource', 'value', null);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('update resource configuration without configuration target defaults to workspace in folder workspace when resource is provider', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => false });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.FOLDER });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$updateConfigurationOption(null, 'extHostConfiguration.resource', 'value', URI.file('abc'));
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('update resource configuration without configuration target defaults to workspace in folder workspace when no resource is provider', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => false });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.FOLDER });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$updateConfigurationOption(null, 'extHostConfiguration.resource', 'value', null);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('update window configuration without configuration target defaults to workspace in multi root workspace when no resource is provided', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => true });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.WORKSPACE });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$updateConfigurationOption(null, 'extHostConfiguration.window', 'value', null);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('update window configuration without configuration target defaults to workspace in multi root workspace when resource is provided', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => true });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.WORKSPACE });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$updateConfigurationOption(null, 'extHostConfiguration.window', 'value', URI.file('abc'));
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('update window configuration without configuration target defaults to workspace in folder workspace when resource is provider', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => false });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.FOLDER });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$updateConfigurationOption(null, 'extHostConfiguration.window', 'value', URI.file('abc'));
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('update window configuration without configuration target defaults to workspace in folder workspace when no resource is provider', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => false });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.FOLDER });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$updateConfigurationOption(null, 'extHostConfiguration.window', 'value', null);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('update resource configuration without configuration target defaults to folder', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => true });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.WORKSPACE });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$updateConfigurationOption(null, 'extHostConfiguration.resource', 'value', URI.file('abc'));
assert.equal(ConfigurationTarget.FOLDER, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE_FOLDER, target.args[0][3]);
});
test('update configuration with user configuration target', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => false });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.FOLDER });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$updateConfigurationOption(ConfigurationTarget.USER, 'extHostConfiguration.window', 'value', URI.file('abc'));
assert.equal(ConfigurationTarget.USER, target.args[0][0]);
assert.equal(ConfigurationTarget.USER, target.args[0][3]);
});
test('update configuration with workspace configuration target', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => false });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.FOLDER });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$updateConfigurationOption(ConfigurationTarget.WORKSPACE, 'extHostConfiguration.window', 'value', URI.file('abc'));
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('update configuration with folder configuration target', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => false });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.FOLDER });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$updateConfigurationOption(ConfigurationTarget.FOLDER, 'extHostConfiguration.window', 'value', URI.file('abc'));
testObject.$updateConfigurationOption(ConfigurationTarget.WORKSPACE_FOLDER, 'extHostConfiguration.window', 'value', URI.file('abc'));
assert.equal(ConfigurationTarget.FOLDER, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE_FOLDER, target.args[0][3]);
});
test('remove resource configuration without configuration target defaults to workspace in multi root workspace when no resource is provided', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => true });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.WORKSPACE });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$removeConfigurationOption(null, 'extHostConfiguration.resource', null);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('remove resource configuration without configuration target defaults to workspace in folder workspace when resource is provider', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => false });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.FOLDER });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$removeConfigurationOption(null, 'extHostConfiguration.resource', URI.file('abc'));
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('remove resource configuration without configuration target defaults to workspace in folder workspace when no resource is provider', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => false });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.FOLDER });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$removeConfigurationOption(null, 'extHostConfiguration.resource', null);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('remove window configuration without configuration target defaults to workspace in multi root workspace when no resource is provided', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => true });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.WORKSPACE });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$removeConfigurationOption(null, 'extHostConfiguration.window', null);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('remove window configuration without configuration target defaults to workspace in multi root workspace when resource is provided', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => true });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.WORKSPACE });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$removeConfigurationOption(null, 'extHostConfiguration.window', URI.file('abc'));
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('remove window configuration without configuration target defaults to workspace in folder workspace when resource is provider', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => false });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.FOLDER });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$removeConfigurationOption(null, 'extHostConfiguration.window', URI.file('abc'));
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('remove window configuration without configuration target defaults to workspace in folder workspace when no resource is provider', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => false });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.FOLDER });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$removeConfigurationOption(null, 'extHostConfiguration.window', null);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE, target.args[0][3]);
});
test('remove configuration without configuration target defaults to folder', function () {
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ hasMultiFolderWorkspace: () => true });
instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{ getWorkbenchState: () => WorkbenchState.WORKSPACE });
const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null));
testObject.$removeConfigurationOption(null, 'extHostConfiguration.resource', URI.file('abc'));
assert.equal(ConfigurationTarget.FOLDER, target.args[0][0]);
assert.equal(ConfigurationTarget.WORKSPACE_FOLDER, target.args[0][3]);
});
});

View File

@@ -49,7 +49,7 @@ suite('MainThreadDocumentsAndEditors', () => {
};
const editorGroupService = new class extends mock<IEditorGroupService>() {
onEditorsChanged = Event.None;
onEditorsMoved = Event.None;
onEditorGroupMoved = Event.None;
};
documentAndEditor = new MainThreadDocumentsAndEditors(

View File

@@ -0,0 +1,112 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import { MainThreadDocumentsAndEditors } from 'vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors';
import { OneGetThreadService, TestThreadService } from './testThreadService';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { MockCodeEditorService } from 'vs/editor/test/common/mocks/mockCodeEditorService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ExtHostDocumentsAndEditorsShape, IWorkspaceResourceEdit, ExtHostContext, ExtHostDocumentsShape } from 'vs/workbench/api/node/extHost.protocol';
import { mock } from 'vs/workbench/test/electron-browser/api/mock';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import Event from 'vs/base/common/event';
import { MainThreadEditors } from 'vs/workbench/api/electron-browser/mainThreadEditors';
import URI from 'vs/base/common/uri';
import { Range } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import { IModelService } from 'vs/editor/common/services/modelService';
import { EditOperation } from 'vs/editor/common/core/editOperation';
suite('MainThreadEditors', () => {
const resource = URI.parse('foo:bar');
let modelService: IModelService;
let editors: MainThreadEditors;
setup(() => {
const configService = new TestConfigurationService();
modelService = new ModelServiceImpl(null, configService);
const codeEditorService = new MockCodeEditorService();
const textFileService = new class extends mock<ITextFileService>() {
isDirty() { return false; };
models = <any>{
onModelSaved: Event.None,
onModelReverted: Event.None,
onModelDirty: Event.None,
};
};
const workbenchEditorService = <IWorkbenchEditorService>{
getVisibleEditors() { return []; },
getActiveEditor() { return undefined; }
};
const editorGroupService = new class extends mock<IEditorGroupService>() {
onEditorsChanged = Event.None;
onEditorGroupMoved = Event.None;
};
const testThreadService = new TestThreadService(true);
testThreadService.setTestInstance(ExtHostContext.ExtHostDocuments, new class extends mock<ExtHostDocumentsShape>() {
$acceptModelChanged(): void {
}
});
testThreadService.setTestInstance(ExtHostContext.ExtHostDocumentsAndEditors, new class extends mock<ExtHostDocumentsAndEditorsShape>() {
$acceptDocumentsAndEditorsDelta(): void {
}
});
const documentAndEditor = new MainThreadDocumentsAndEditors(
testThreadService,
modelService,
textFileService,
workbenchEditorService,
codeEditorService,
null,
null,
null,
null,
editorGroupService,
null
);
editors = new MainThreadEditors(
documentAndEditor,
OneGetThreadService(null),
codeEditorService,
workbenchEditorService,
editorGroupService,
null,
null,
null,
modelService
);
});
test(`applyWorkspaceEdit returns false if model is changed by user`, () => {
let model = modelService.createModel('something', null, resource);
let workspaceResourceEdit: IWorkspaceResourceEdit = {
resource: resource,
modelVersionId: model.getVersionId(),
edits: [{
newText: 'asdfg',
range: new Range(1, 1, 1, 1)
}]
};
// Act as if the user edited the model
model.applyEdits([EditOperation.insert(new Position(0, 0), 'something')]);
return editors.$tryApplyWorkspaceEdit([workspaceResourceEdit]).then((result) => {
assert.equal(result, false);
});
});
});

View File

@@ -7,7 +7,7 @@
import * as assert from 'assert';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { FinalNewLineParticipant } from 'vs/workbench/api/electron-browser/mainThreadSaveParticipant';
import { FinalNewLineParticipant, TrimFinalNewLinesParticipant } from 'vs/workbench/api/electron-browser/mainThreadSaveParticipant';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { workbenchInstantiationService, TestTextFileService } from 'vs/workbench/test/workbenchTestServices';
import { toResource } from 'vs/base/test/common/utils';
@@ -72,4 +72,44 @@ suite('MainThreadSaveParticipant', function () {
done();
});
});
test('trim final new lines', function (done) {
const model: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(this, '/path/trim_final_new_line.txt'), 'utf8');
model.load().then(() => {
const configService = new TestConfigurationService();
configService.setUserConfiguration('files', { 'trimFinalNewlines': true });
const participant = new TrimFinalNewLinesParticipant(configService, undefined);
const textContent = 'Trim New Line';
const eol = `${model.textEditorModel.getEOL()}`;
// No new line removal if last line is not new line
let lineContent = `${textContent}`;
model.textEditorModel.setValue(lineContent);
participant.participate(model, { reason: SaveReason.EXPLICIT });
assert.equal(model.getValue(), lineContent);
// No new line removal if last line is single new line
lineContent = `${textContent}${eol}`;
model.textEditorModel.setValue(lineContent);
participant.participate(model, { reason: SaveReason.EXPLICIT });
assert.equal(model.getValue(), lineContent);
// Remove new line (single line with two new lines)
lineContent = `${textContent}${eol}${eol}`;
model.textEditorModel.setValue(lineContent);
participant.participate(model, { reason: SaveReason.EXPLICIT });
assert.equal(model.getValue(), `${textContent}${eol}`);
// Remove new lines (multiple lines with multiple new lines)
lineContent = `${textContent}${eol}${textContent}${eol}${eol}${eol}`;
model.textEditorModel.setValue(lineContent);
participant.participate(model, { reason: SaveReason.EXPLICIT });
assert.equal(model.getValue(), `${textContent}${eol}${textContent}${eol}`);
done();
});
});
});

View File

@@ -76,8 +76,8 @@ export abstract class AbstractTestThreadService {
}
export class TestThreadService extends AbstractTestThreadService implements IThreadService {
constructor() {
super(false);
constructor(isMainProcess: boolean = false) {
super(isMainProcess);
}
private _callCountValue: number = 0;

View File

@@ -7,16 +7,17 @@
import 'vs/workbench/parts/search/browser/search.contribution'; // load contributions
import * as assert from 'assert';
import { IWorkspaceContextService, LegacyWorkspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { createSyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ISearchService } from 'vs/platform/search/common/search';
import { ITelemetryService, ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry';
import { IExperimentService, IExperiments } from 'vs/platform/telemetry/common/experiments';
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import * as minimist from 'minimist';
import * as path from 'path';
import { QuickOpenHandler, IQuickOpenRegistry, Extensions } from 'vs/workbench/browser/quickopen';
import { IQuickOpenRegistry, Extensions } from 'vs/workbench/browser/quickopen';
import { Registry } from 'vs/platform/registry/common/platform';
import { SearchService } from 'vs/workbench/services/search/node/searchService';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
@@ -29,6 +30,7 @@ import { SimpleConfigurationService } from 'vs/editor/standalone/browser/simpleS
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { IModelService } from 'vs/editor/common/services/modelService';
import { testWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
namespace Timer {
export interface ITimerEvent {
@@ -56,7 +58,7 @@ suite('QuickOpen performance (integration)', () => {
test('Measure', () => {
if (process.env['VSCODE_PID']) {
return; // TODO@Christoph find out why test fails when run from within VS Code
return void 0; // TODO@Christoph find out why test fails when run from within VS Code
}
const n = 3;
@@ -66,12 +68,14 @@ suite('QuickOpen performance (integration)', () => {
const testWorkspacePath = testWorkspaceArg ? path.resolve(testWorkspaceArg) : __dirname;
const telemetryService = new TestTelemetryService();
const experimentService = new TestExperimentService();
const configurationService = new SimpleConfigurationService();
const instantiationService = new InstantiationService(new ServiceCollection(
[ITelemetryService, telemetryService],
[IExperimentService, experimentService],
[IConfigurationService, configurationService],
[IModelService, new ModelServiceImpl(null, configurationService)],
[IWorkspaceContextService, new TestContextService(new LegacyWorkspace(URI.file(testWorkspacePath)))],
[IWorkspaceContextService, new TestContextService(testWorkspace(URI.file(testWorkspacePath)))],
[IWorkbenchEditorService, new TestEditorService()],
[IEditorGroupService, new TestEditorGroupService()],
[IEnvironmentService, TestEnvironmentService],
@@ -84,35 +88,33 @@ suite('QuickOpen performance (integration)', () => {
assert.ok(descriptor);
function measure() {
return instantiationService.createInstance(descriptor)
.then((handler: QuickOpenHandler) => {
handler.onOpen();
return handler.getResults('a').then(result => {
const uncachedEvent = popEvent();
assert.strictEqual(uncachedEvent.data.symbols.fromCache, false, 'symbols.fromCache');
assert.strictEqual(uncachedEvent.data.files.fromCache, true, 'files.fromCache');
if (testWorkspaceArg) {
assert.ok(!!uncachedEvent.data.files.joined, 'files.joined');
}
return uncachedEvent;
}).then(uncachedEvent => {
return handler.getResults('ab').then(result => {
const cachedEvent = popEvent();
assert.strictEqual(uncachedEvent.data.symbols.fromCache, false, 'symbols.fromCache');
assert.ok(cachedEvent.data.files.fromCache, 'filesFromCache');
handler.onClose(false);
return [uncachedEvent, cachedEvent];
});
});
const handler = descriptor.instantiate(instantiationService);
handler.onOpen();
return handler.getResults('a').then(result => {
const uncachedEvent = popEvent();
assert.strictEqual(uncachedEvent.data.symbols.fromCache, false, 'symbols.fromCache');
assert.strictEqual(uncachedEvent.data.files.fromCache, true, 'files.fromCache');
if (testWorkspaceArg) {
assert.ok(!!uncachedEvent.data.files.joined, 'files.joined');
}
return uncachedEvent;
}).then(uncachedEvent => {
return handler.getResults('ab').then(result => {
const cachedEvent = popEvent();
assert.strictEqual(uncachedEvent.data.symbols.fromCache, false, 'symbols.fromCache');
assert.ok(cachedEvent.data.files.fromCache, 'filesFromCache');
handler.onClose(false);
return [uncachedEvent, cachedEvent];
});
});
}
function popEvent() {
const events = telemetryService.events;
const events = telemetryService.events
.filter(event => event.name === 'openAnything');
assert.strictEqual(events.length, 1);
const event = events[0];
events.length = 0;
assert.strictEqual(event.name, 'openAnything');
telemetryService.events.length = 0;
return event;
}
@@ -177,3 +179,12 @@ class TestTelemetryService implements ITelemetryService {
});
}
};
class TestExperimentService implements IExperimentService {
_serviceBrand: any;
getExperiments(): IExperiments {
return {};
}
}

View File

@@ -8,7 +8,7 @@
import 'vs/workbench/parts/search/browser/search.contribution'; // load contributions
import * as assert from 'assert';
import * as fs from 'fs';
import { IWorkspaceContextService, LegacyWorkspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { createSyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ISearchService, IQueryOptions } from 'vs/platform/search/common/search';
@@ -33,6 +33,7 @@ import { SearchModel } from 'vs/workbench/parts/search/common/searchModel';
import { QueryBuilder } from 'vs/workbench/parts/search/common/queryBuilder';
import Event, * as event from 'vs/base/common/event';
import { testWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
declare var __dirname: string;
@@ -61,7 +62,7 @@ suite('TextSearch performance (integration)', () => {
[ITelemetryService, telemetryService],
[IConfigurationService, configurationService],
[IModelService, new ModelServiceImpl(null, configurationService)],
[IWorkspaceContextService, new TestContextService(new LegacyWorkspace(URI.file(testWorkspacePath)))],
[IWorkspaceContextService, new TestContextService(testWorkspace(URI.file(testWorkspacePath)))],
[IWorkbenchEditorService, new TestEditorService()],
[IEditorGroupService, new TestEditorGroupService()],
[IEnvironmentService, TestEnvironmentService],

View File

@@ -15,7 +15,7 @@ import URI from 'vs/base/common/uri';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { StorageService, InMemoryLocalStorage } from 'vs/platform/storage/common/storageService';
import { IEditorGroup, ConfirmResult } from 'vs/workbench/common/editor';
import { IEditorGroup, ConfirmResult, IEditorOpeningEvent } from 'vs/workbench/common/editor';
import Event, { Emitter } from 'vs/base/common/event';
import Severity from 'vs/base/common/severity';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
@@ -24,17 +24,17 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { IEditorInput, IEditorOptions, Position, Direction, IEditor, IResourceInput, ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { IEditorInput, IEditorOptions, Position, Direction, IEditor, IResourceInput } from 'vs/platform/editor/common/editor';
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IMessageService, IConfirmation } from 'vs/platform/message/common/message';
import { ILegacyWorkspace, IWorkspaceContextService, IWorkspace as IWorkbenchWorkspace } from 'vs/platform/workspace/common/workspace';
import { IMessageService, IConfirmation, IConfirmationResult, IChoiceService } from 'vs/platform/message/common/message';
import { IWorkspaceContextService, IWorkspace as IWorkbenchWorkspace, WorkbenchState, IWorkspaceFolder, IWorkspaceFoldersChangeEvent } from 'vs/platform/workspace/common/workspace';
import { ILifecycleService, ShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { EditorStacksModel } from 'vs/workbench/common/editor/editorStacksModel';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { IEditorGroupService, GroupArrangement, GroupOrientation, ITabOptions, IMoveOptions } from 'vs/workbench/services/group/common/groupService';
import { IEditorGroupService, GroupArrangement, GroupOrientation, IEditorTabOptions, IMoveOptions } from 'vs/workbench/services/group/common/groupService';
import { TextFileService } from 'vs/workbench/services/textfile/common/textFileService';
import { FileOperationEvent, IFileService, IResolveContentOptions, FileOperationError, IFileStat, IResolveFileResult, IImportResult, FileChangesEvent, IResolveFileOptions, IContent, IUpdateContentOptions, IStreamContent } from 'vs/platform/files/common/files';
import { FileOperationEvent, IFileService, IResolveContentOptions, FileOperationError, IFileStat, IResolveFileResult, IImportResult, FileChangesEvent, IResolveFileOptions, IContent, IUpdateContentOptions, IStreamContent, ICreateFileOptions } from 'vs/platform/files/common/files';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
@@ -44,9 +44,9 @@ import { EnvironmentService } from 'vs/platform/environment/node/environmentServ
import { IModeService } from 'vs/editor/common/services/modeService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { IWindowsService, IWindowService, INativeOpenDialogOptions } from 'vs/platform/windows/common/windows';
import { IWindowsService, IWindowService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult } from 'vs/platform/windows/common/windows';
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
import { RawTextSource, IRawTextSource } from 'vs/editor/common/model/textSource';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
@@ -54,8 +54,12 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
import { isLinux } from 'vs/base/common/platform';
import { generateUuid } from 'vs/base/common/uuid';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces';
import { IRecentlyOpened } from 'vs/platform/history/common/history';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
import { IPosition } from 'vs/editor/common/core/position';
import { ICommandAction } from 'vs/platform/actions/common/actions';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
return instantiationService.createInstance(FileEditorInput, resource, void 0);
@@ -71,49 +75,51 @@ export class TestContextService implements IWorkspaceContextService {
private options: any;
private _onDidChangeWorkspaceName: Emitter<void>;
private _onDidChangeWorkspaceRoots: Emitter<void>;
private _onDidChangeWorkspaceFolders: Emitter<IWorkspaceFoldersChangeEvent>;
private _onDidChangeWorkbenchState: Emitter<WorkbenchState>;
constructor(workspace: any = TestWorkspace, options: any = null) {
this.workspace = workspace;
this.id = generateUuid();
this.options = options || Object.create(null);
this._onDidChangeWorkspaceRoots = new Emitter<void>();
this._onDidChangeWorkspaceFolders = new Emitter<IWorkspaceFoldersChangeEvent>();
this._onDidChangeWorkbenchState = new Emitter<WorkbenchState>();
}
public get onDidChangeWorkspaceName(): Event<void> {
return this._onDidChangeWorkspaceName.event;
}
public get onDidChangeWorkspaceRoots(): Event<void> {
return this._onDidChangeWorkspaceRoots.event;
public get onDidChangeWorkspaceFolders(): Event<IWorkspaceFoldersChangeEvent> {
return this._onDidChangeWorkspaceFolders.event;
}
public getFolders(): URI[] {
return this.workspace ? this.workspace.roots : [];
public get onDidChangeWorkbenchState(): Event<WorkbenchState> {
return this._onDidChangeWorkbenchState.event;
}
public hasWorkspace(): boolean {
return !!this.workspace;
public getFolders(): IWorkspaceFolder[] {
return this.workspace ? this.workspace.folders : [];
}
public hasFolderWorkspace(): boolean {
return this.workspace && !this.workspace.configuration;
}
public getWorkbenchState(): WorkbenchState {
if (this.workspace.configuration) {
return WorkbenchState.WORKSPACE;
}
public hasMultiFolderWorkspace(): boolean {
return this.workspace && !!this.workspace.configuration;
}
if (this.workspace.folders.length) {
return WorkbenchState.FOLDER;
}
public getLegacyWorkspace(): ILegacyWorkspace {
return this.workspace ? { resource: this.workspace.roots[0] } : void 0;
return WorkbenchState.EMPTY;
}
public getWorkspace(): IWorkbenchWorkspace {
return this.workspace;
}
public getRoot(resource: URI): URI {
return this.isInsideWorkspace(resource) ? this.workspace.roots[0] : null;
public getWorkspaceFolder(resource: URI): IWorkspaceFolder {
return this.isInsideWorkspace(resource) ? this.workspace.folders[0] : null;
}
public setWorkspace(workspace: any): void {
@@ -130,7 +136,7 @@ export class TestContextService implements IWorkspaceContextService {
public isInsideWorkspace(resource: URI): boolean {
if (resource && this.workspace) {
return paths.isEqualOrParent(resource.fsPath, this.workspace.roots[0].fsPath, !isLinux /* ignorecase */);
return paths.isEqualOrParent(resource.fsPath, this.workspace.folders[0].uri.fsPath, !isLinux /* ignorecase */);
}
return false;
@@ -139,6 +145,19 @@ export class TestContextService implements IWorkspaceContextService {
public toResource(workspaceRelativePath: string): URI {
return URI.file(paths.join('C:\\', workspaceRelativePath));
}
public isCurrentWorkspace(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): boolean {
return isSingleFolderWorkspaceIdentifier(workspaceIdentifier) && this.pathEquals(this.workspace.folders[0].uri.fsPath, workspaceIdentifier);
}
private pathEquals(path1: string, path2: string): boolean {
if (!isLinux) {
path1 = path1.toLowerCase();
path2 = path2.toLowerCase();
}
return path1 === path2;
}
}
export class TestTextFileService extends TextFileService {
@@ -207,8 +226,8 @@ export class TestTextFileService extends TextFileService {
return this.confirmResult;
}
public onConfigurationChange(configuration: any): void {
super.onConfigurationChange(configuration);
public onFilesConfigurationChange(configuration: any): void {
super.onFilesConfigurationChange(configuration);
}
protected cleanupBackupsBeforeShutdown(): TPromise<void> {
@@ -220,7 +239,9 @@ export class TestTextFileService extends TextFileService {
export function workbenchInstantiationService(): IInstantiationService {
let instantiationService = new TestInstantiationService(new ServiceCollection([ILifecycleService, new TestLifecycleService()]));
instantiationService.stub(IWorkspaceContextService, new TestContextService(TestWorkspace));
instantiationService.stub(IConfigurationService, new TestConfigurationService());
const configService = new TestConfigurationService();
instantiationService.stub(IConfigurationService, configService);
instantiationService.stub(ITextResourceConfigurationService, new TestTextResourceConfigurationService(configService));
instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
instantiationService.stub(IStorageService, new TestStorageService());
instantiationService.stub(IWorkbenchEditorService, new TestEditorService());
@@ -239,6 +260,12 @@ export function workbenchInstantiationService(): IInstantiationService {
instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
instantiationService.stub(IEnvironmentService, TestEnvironmentService);
instantiationService.stub(IThemeService, new TestThemeService());
instantiationService.stub(IHashService, new TestHashService());
instantiationService.stub(IChoiceService, {
choose: (severity, message, options, cancelId): TPromise<number> => {
return TPromise.as(cancelId);
}
});
return instantiationService;
}
@@ -253,15 +280,15 @@ export class TestHistoryService implements IHistoryService {
public reopenLastClosedEditor(): void {
}
public add(input: IEditorInput, options?: ITextEditorOptions): void {
}
public forward(acrossEditors?: boolean): void {
}
public back(acrossEditors?: boolean): void {
}
public last(): void {
}
public remove(input: IEditorInput | IResourceInput): void {
}
@@ -272,12 +299,17 @@ export class TestHistoryService implements IHistoryService {
return [];
}
public getLastActiveWorkspaceRoot(): URI {
public getLastActiveWorkspaceRoot(schemeFilter?: string): URI {
return this.root;
}
public getLastActiveFile(): URI {
return void 0;
}
}
export class TestMessageService implements IMessageService {
public _serviceBrand: any;
private counter: number;
@@ -300,9 +332,13 @@ export class TestMessageService implements IMessageService {
// No-op
}
public confirm(confirmation: IConfirmation): boolean {
public confirmSync(confirmation: IConfirmation): boolean {
return false;
}
public confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
return TPromise.as({ confirmed: false });
}
}
export class TestPartService implements IPartService {
@@ -382,6 +418,10 @@ export class TestPartService implements IPartService {
return 0;
}
public getPanelPosition() {
return 0;
}
public addClass(clazz: string): void { }
public removeClass(clazz: string): void { }
public getWorkbenchElementId(): string { return ''; }
@@ -430,17 +470,19 @@ export class TestEditorGroupService implements IEditorGroupService {
private stacksModel: EditorStacksModel;
private _onEditorsChanged: Emitter<void>;
private _onEditorOpening: Emitter<IEditorOpeningEvent>;
private _onEditorOpenFail: Emitter<IEditorInput>;
private _onEditorsMoved: Emitter<void>;
private _onGroupOrientationChanged: Emitter<void>;
private _onTabOptionsChanged: Emitter<ITabOptions>;
private _onTabOptionsChanged: Emitter<IEditorTabOptions>;
constructor(callback?: (method: string) => void) {
this._onEditorsMoved = new Emitter<void>();
this._onEditorsChanged = new Emitter<void>();
this._onEditorOpening = new Emitter<IEditorOpeningEvent>();
this._onGroupOrientationChanged = new Emitter<void>();
this._onEditorOpenFail = new Emitter<IEditorInput>();
this._onTabOptionsChanged = new Emitter<ITabOptions>();
this._onTabOptionsChanged = new Emitter<IEditorTabOptions>();
let services = new ServiceCollection();
@@ -464,11 +506,15 @@ export class TestEditorGroupService implements IEditorGroupService {
return this._onEditorsChanged.event;
}
public get onEditorOpening(): Event<IEditorOpeningEvent> {
return this._onEditorOpening.event;
}
public get onEditorOpenFail(): Event<IEditorInput> {
return this._onEditorOpenFail.event;
}
public get onEditorsMoved(): Event<void> {
public get onEditorGroupMoved(): Event<void> {
return this._onEditorsMoved.event;
}
@@ -476,7 +522,7 @@ export class TestEditorGroupService implements IEditorGroupService {
return this._onGroupOrientationChanged.event;
}
public get onTabOptionsChanged(): Event<ITabOptions> {
public get onTabOptionsChanged(): Event<IEditorTabOptions> {
return this._onTabOptionsChanged.event;
}
@@ -533,9 +579,13 @@ export class TestEditorGroupService implements IEditorGroupService {
return this.stacksModel;
}
public getTabOptions(): ITabOptions {
public getTabOptions(): IEditorTabOptions {
return {};
}
public invokeWithinEditorContext<T>(fn: (accessor: ServicesAccessor) => T): T {
return fn(null);
}
}
export class TestEditorService implements IWorkbenchEditorService {
@@ -735,7 +785,7 @@ export class TestFileService implements IFileService {
return TPromise.as(null);
}
createFile(resource: URI, content?: string): TPromise<IFileStat> {
createFile(resource: URI, content?: string, options?: ICreateFileOptions): TPromise<IFileStat> {
return TPromise.as(null);
}
@@ -858,6 +908,10 @@ export class TestWindowService implements IWindowService {
return TPromise.as(void 0);
}
pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
return TPromise.as(void 0);
}
reloadWindow(): TPromise<void> {
return TPromise.as(void 0);
}
@@ -874,15 +928,11 @@ export class TestWindowService implements IWindowService {
return TPromise.as(void 0);
}
openWorkspace(): TPromise<void> {
createAndEnterWorkspace(folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
return TPromise.as(void 0);
}
createAndOpenWorkspace(folders?: string[], path?: string): TPromise<void> {
return TPromise.as(void 0);
}
saveAndOpenWorkspace(path: string): TPromise<void> {
saveAndEnterWorkspace(path: string): TPromise<IEnterWorkspaceResult> {
return TPromise.as(void 0);
}
@@ -930,10 +980,14 @@ export class TestWindowService implements IWindowService {
return TPromise.as(void 0);
}
showMessageBox(options: Electron.ShowMessageBoxOptions): number {
showMessageBoxSync(options: Electron.MessageBoxOptions): number {
return 0;
}
showMessageBox(options: Electron.MessageBoxOptions): Promise<IMessageBoxResult> {
return TPromise.as(void 0);
}
showSaveDialog(options: Electron.SaveDialogOptions, callback?: (fileName: string) => void): string {
return void 0;
}
@@ -941,6 +995,10 @@ export class TestWindowService implements IWindowService {
showOpenDialog(options: Electron.OpenDialogOptions, callback?: (fileNames: string[]) => void): string[] {
return void 0;
}
updateTouchBar(items: ICommandAction[][]): Promise<void> {
return TPromise.as(void 0);
}
}
export class TestLifecycleService implements ILifecycleService {
@@ -1002,6 +1060,10 @@ export class TestWindowsService implements IWindowsService {
return TPromise.as(void 0);
}
pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
return TPromise.as(void 0);
}
reloadWindow(windowId: number): TPromise<void> {
return TPromise.as(void 0);
}
@@ -1018,15 +1080,11 @@ export class TestWindowsService implements IWindowsService {
return TPromise.as(void 0);
}
openWorkspace(windowId: number): TPromise<void> {
createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
return TPromise.as(void 0);
}
createAndOpenWorkspace(windowId: number, folders?: string[], path?: string): TPromise<void> {
return TPromise.as(void 0);
}
saveAndOpenWorkspace(windowId: number, path: string): TPromise<void> {
saveAndEnterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult> {
return TPromise.as(void 0);
}
@@ -1127,6 +1185,30 @@ export class TestWindowsService implements IWindowsService {
return TPromise.as(void 0);
}
showPreviousWindowTab(): Promise<void> {
return TPromise.as(void 0);
}
showNextWindowTab(): Promise<void> {
return TPromise.as(void 0);
}
moveWindowTabToNewWindow(): Promise<void> {
return TPromise.as(void 0);
}
mergeAllWindowTabs(): Promise<void> {
return TPromise.as(void 0);
}
toggleWindowTabsBar(): Promise<void> {
return TPromise.as(void 0);
}
updateTouchBar(windowId: number, items: ICommandAction[][]): Promise<void> {
return TPromise.as(void 0);
}
// This needs to be handled from browser process to prevent
// foreground ordering issues on Windows
openExternal(url: string): TPromise<boolean> {
@@ -1139,3 +1221,33 @@ export class TestWindowsService implements IWindowsService {
}
}
export class TestTextResourceConfigurationService implements ITextResourceConfigurationService {
_serviceBrand: any;
constructor(private configurationService = new TestConfigurationService()) {
}
public onDidChangeConfiguration() {
return { dispose() { } };
}
public getConfiguration(resource: URI, section?: string): any;
public getConfiguration(resource: URI, position?: IPosition, section?: string): any;
public getConfiguration(resource: any, position?: any, section?: any): any;
public getConfiguration(resource: any, position?: any, section?: any): any {
return this.configurationService.getConfiguration(section, { resource });
}
}
export class TestHashService implements IHashService {
_serviceBrand: any;
createSHA1(content: string): string {
return content;
}
}
export function getRandomTestPath(tmpdir: string, ...segments: string[]): string {
return paths.join(tmpdir, ...segments, generateUuid());
}