mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-15 10:58:31 -05:00
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:
@@ -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 });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}, []));
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user