mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-07 17:23:56 -05:00
Merge from vscode 2e5312cd61ff99c570299ecc122c52584265eda2
This commit is contained in:
committed by
Anthony Dresser
parent
3603f55d97
commit
7f1d8fc32f
@@ -70,6 +70,11 @@ function assertRejects(fn: () => Promise<any>, message: string = 'Expected rejec
|
||||
return fn().then(() => assert.ok(false, message), _err => assert.ok(true));
|
||||
}
|
||||
|
||||
function isLocation(value: vscode.Location | vscode.LocationLink): value is vscode.Location {
|
||||
const candidate = value as vscode.Location;
|
||||
return candidate && candidate.uri instanceof URI && candidate.range instanceof types.Range;
|
||||
}
|
||||
|
||||
suite('ExtHostLanguageFeatureCommands', function () {
|
||||
|
||||
suiteSetup(() => {
|
||||
@@ -268,6 +273,34 @@ suite('ExtHostLanguageFeatureCommands', function () {
|
||||
});
|
||||
});
|
||||
|
||||
test('Definition Link', () => {
|
||||
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
|
||||
provideDefinition(doc: any): (vscode.Location | vscode.LocationLink)[] {
|
||||
return [
|
||||
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
|
||||
{ targetUri: doc.uri, targetRange: new types.Range(0, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
|
||||
];
|
||||
}
|
||||
}));
|
||||
|
||||
return rpcProtocol.sync().then(() => {
|
||||
return commands.executeCommand<(vscode.Location | vscode.LocationLink)[]>('vscode.executeDefinitionProvider', model.uri, new types.Position(0, 0)).then(values => {
|
||||
assert.equal(values.length, 2);
|
||||
for (let v of values) {
|
||||
if (isLocation(v)) {
|
||||
assert.ok(v.uri instanceof URI);
|
||||
assert.ok(v.range instanceof types.Range);
|
||||
} else {
|
||||
assert.ok(v.targetUri instanceof URI);
|
||||
assert.ok(v.targetRange instanceof types.Range);
|
||||
assert.ok(v.targetSelectionRange instanceof types.Range);
|
||||
assert.ok(v.originSelectionRange instanceof types.Range);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// --- declaration
|
||||
|
||||
test('Declaration, back and forth', function () {
|
||||
@@ -298,6 +331,34 @@ suite('ExtHostLanguageFeatureCommands', function () {
|
||||
});
|
||||
});
|
||||
|
||||
test('Declaration Link', () => {
|
||||
disposables.push(extHost.registerDeclarationProvider(nullExtensionDescription, defaultSelector, <vscode.DeclarationProvider>{
|
||||
provideDeclaration(doc: any): (vscode.Location | vscode.LocationLink)[] {
|
||||
return [
|
||||
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
|
||||
{ targetUri: doc.uri, targetRange: new types.Range(0, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
|
||||
];
|
||||
}
|
||||
}));
|
||||
|
||||
return rpcProtocol.sync().then(() => {
|
||||
return commands.executeCommand<(vscode.Location | vscode.LocationLink)[]>('vscode.executeDeclarationProvider', model.uri, new types.Position(0, 0)).then(values => {
|
||||
assert.equal(values.length, 2);
|
||||
for (let v of values) {
|
||||
if (isLocation(v)) {
|
||||
assert.ok(v.uri instanceof URI);
|
||||
assert.ok(v.range instanceof types.Range);
|
||||
} else {
|
||||
assert.ok(v.targetUri instanceof URI);
|
||||
assert.ok(v.targetRange instanceof types.Range);
|
||||
assert.ok(v.targetSelectionRange instanceof types.Range);
|
||||
assert.ok(v.originSelectionRange instanceof types.Range);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// --- type definition
|
||||
|
||||
test('Type Definition, invalid arguments', function () {
|
||||
@@ -339,6 +400,103 @@ suite('ExtHostLanguageFeatureCommands', function () {
|
||||
});
|
||||
});
|
||||
|
||||
test('Type Definition Link', () => {
|
||||
disposables.push(extHost.registerTypeDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.TypeDefinitionProvider>{
|
||||
provideTypeDefinition(doc: any): (vscode.Location | vscode.LocationLink)[] {
|
||||
return [
|
||||
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
|
||||
{ targetUri: doc.uri, targetRange: new types.Range(0, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
|
||||
];
|
||||
}
|
||||
}));
|
||||
|
||||
return rpcProtocol.sync().then(() => {
|
||||
return commands.executeCommand<(vscode.Location | vscode.LocationLink)[]>('vscode.executeTypeDefinitionProvider', model.uri, new types.Position(0, 0)).then(values => {
|
||||
assert.equal(values.length, 2);
|
||||
for (let v of values) {
|
||||
if (isLocation(v)) {
|
||||
assert.ok(v.uri instanceof URI);
|
||||
assert.ok(v.range instanceof types.Range);
|
||||
} else {
|
||||
assert.ok(v.targetUri instanceof URI);
|
||||
assert.ok(v.targetRange instanceof types.Range);
|
||||
assert.ok(v.targetSelectionRange instanceof types.Range);
|
||||
assert.ok(v.originSelectionRange instanceof types.Range);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// --- implementation
|
||||
|
||||
test('Implementation, invalid arguments', function () {
|
||||
const promises = [
|
||||
assertRejects(() => commands.executeCommand('vscode.executeImplementationProvider')),
|
||||
assertRejects(() => commands.executeCommand('vscode.executeImplementationProvider', null)),
|
||||
assertRejects(() => commands.executeCommand('vscode.executeImplementationProvider', undefined)),
|
||||
assertRejects(() => commands.executeCommand('vscode.executeImplementationProvider', true, false))
|
||||
];
|
||||
|
||||
return Promise.all(promises);
|
||||
});
|
||||
|
||||
test('Implementation, back and forth', function () {
|
||||
|
||||
disposables.push(extHost.registerImplementationProvider(nullExtensionDescription, defaultSelector, <vscode.ImplementationProvider>{
|
||||
provideImplementation(doc: any): any {
|
||||
return new types.Location(doc.uri, new types.Range(0, 0, 0, 0));
|
||||
}
|
||||
}));
|
||||
disposables.push(extHost.registerImplementationProvider(nullExtensionDescription, defaultSelector, <vscode.ImplementationProvider>{
|
||||
provideImplementation(doc: any): any {
|
||||
return [
|
||||
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
|
||||
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
|
||||
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
|
||||
];
|
||||
}
|
||||
}));
|
||||
|
||||
return rpcProtocol.sync().then(() => {
|
||||
return commands.executeCommand<vscode.Location[]>('vscode.executeImplementationProvider', model.uri, new types.Position(0, 0)).then(values => {
|
||||
assert.equal(values.length, 4);
|
||||
for (const v of values) {
|
||||
assert.ok(v.uri instanceof URI);
|
||||
assert.ok(v.range instanceof types.Range);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('Implementation Definition Link', () => {
|
||||
disposables.push(extHost.registerImplementationProvider(nullExtensionDescription, defaultSelector, <vscode.ImplementationProvider>{
|
||||
provideImplementation(doc: any): (vscode.Location | vscode.LocationLink)[] {
|
||||
return [
|
||||
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
|
||||
{ targetUri: doc.uri, targetRange: new types.Range(0, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
|
||||
];
|
||||
}
|
||||
}));
|
||||
|
||||
return rpcProtocol.sync().then(() => {
|
||||
return commands.executeCommand<(vscode.Location | vscode.LocationLink)[]>('vscode.executeImplementationProvider', model.uri, new types.Position(0, 0)).then(values => {
|
||||
assert.equal(values.length, 2);
|
||||
for (let v of values) {
|
||||
if (isLocation(v)) {
|
||||
assert.ok(v.uri instanceof URI);
|
||||
assert.ok(v.range instanceof types.Range);
|
||||
} else {
|
||||
assert.ok(v.targetUri instanceof URI);
|
||||
assert.ok(v.targetRange instanceof types.Range);
|
||||
assert.ok(v.targetSelectionRange instanceof types.Range);
|
||||
assert.ok(v.originSelectionRange instanceof types.Range);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// --- references
|
||||
|
||||
test('reference search, back and forth', function () {
|
||||
@@ -585,6 +743,33 @@ suite('ExtHostLanguageFeatureCommands', function () {
|
||||
assert.equal(b.commitCharacters, undefined);
|
||||
});
|
||||
|
||||
test('vscode.executeCompletionItemProvider returns the wrong CompletionItemKinds in insiders #95715', async function () {
|
||||
disposables.push(extHost.registerCompletionItemProvider(nullExtensionDescription, defaultSelector, <vscode.CompletionItemProvider>{
|
||||
provideCompletionItems(): any {
|
||||
return [
|
||||
new types.CompletionItem('My Method', types.CompletionItemKind.Method),
|
||||
new types.CompletionItem('My Property', types.CompletionItemKind.Property),
|
||||
];
|
||||
}
|
||||
}, []));
|
||||
|
||||
await rpcProtocol.sync();
|
||||
|
||||
let list = await commands.executeCommand<vscode.CompletionList>(
|
||||
'vscode.executeCompletionItemProvider',
|
||||
model.uri,
|
||||
new types.Position(0, 4),
|
||||
undefined
|
||||
);
|
||||
|
||||
assert.ok(list instanceof types.CompletionList);
|
||||
assert.equal(list.items.length, 2);
|
||||
|
||||
const [a, b] = list.items;
|
||||
assert.equal(a.kind, types.CompletionItemKind.Method);
|
||||
assert.equal(b.kind, types.CompletionItemKind.Property);
|
||||
});
|
||||
|
||||
// --- signatureHelp
|
||||
|
||||
test('Parameter Hints, back and forth', async () => {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,437 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { TestRPCProtocol } from 'vs/workbench/test/browser/api/testRPCProtocol';
|
||||
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
|
||||
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
import { ExtHostNotebookConcatDocument } from 'vs/workbench/api/common/extHostNotebookConcatDocument';
|
||||
import { ExtHostNotebookDocument, ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { CellKind, CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { Position, Location, Range } from 'vs/workbench/api/common/extHostTypes';
|
||||
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
|
||||
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import * as vscode from 'vscode';
|
||||
import { mock } from 'vs/workbench/test/common/workbenchTestServices';
|
||||
import { MainContext, MainThreadCommandsShape, MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
|
||||
|
||||
suite('NotebookConcatDocument', function () {
|
||||
|
||||
let rpcProtocol: TestRPCProtocol;
|
||||
let notebook: ExtHostNotebookDocument;
|
||||
let extHostDocumentsAndEditors: ExtHostDocumentsAndEditors;
|
||||
let extHostDocuments: ExtHostDocuments;
|
||||
let extHostNotebooks: ExtHostNotebookController;
|
||||
const notebookUri = URI.parse('test:///notebook.file');
|
||||
const disposables = new DisposableStore();
|
||||
|
||||
setup(async function () {
|
||||
disposables.clear();
|
||||
|
||||
rpcProtocol = new TestRPCProtocol();
|
||||
rpcProtocol.set(MainContext.MainThreadCommands, new class extends mock<MainThreadCommandsShape>() {
|
||||
$registerCommand() { }
|
||||
});
|
||||
rpcProtocol.set(MainContext.MainThreadNotebook, new class extends mock<MainThreadNotebookShape>() {
|
||||
async $registerNotebookProvider() { }
|
||||
async $unregisterNotebookProvider() { }
|
||||
async $createNotebookDocument() { }
|
||||
});
|
||||
extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
|
||||
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
|
||||
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors);
|
||||
let reg = extHostNotebooks.registerNotebookProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookProvider>() {
|
||||
async resolveNotebook() { }
|
||||
});
|
||||
await extHostNotebooks.$resolveNotebook('test', notebookUri);
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
versionId: 0,
|
||||
changes: [[0, 0, [{
|
||||
handle: 0,
|
||||
uri: CellUri.generate(notebookUri, 0),
|
||||
source: ['### Heading'],
|
||||
language: 'markdown',
|
||||
cellKind: CellKind.Markdown,
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
await extHostNotebooks.$updateActiveEditor('test', notebookUri);
|
||||
|
||||
notebook = extHostNotebooks.activeNotebookDocument!;
|
||||
|
||||
disposables.add(reg);
|
||||
disposables.add(notebook);
|
||||
disposables.add(extHostDocuments);
|
||||
});
|
||||
|
||||
test('empty', function () {
|
||||
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, undefined);
|
||||
assert.equal(doc.getText(), '');
|
||||
assert.equal(doc.version, 0);
|
||||
|
||||
// assert.equal(doc.locationAt(new Position(0, 0)), undefined);
|
||||
// assert.equal(doc.positionAt(SOME_FAKE_LOCATION?), undefined);
|
||||
});
|
||||
|
||||
|
||||
function assertLocation(doc: vscode.NotebookConcatTextDocument, pos: Position, expected: Location, reverse = true) {
|
||||
const actual = doc.locationAt(pos);
|
||||
assert.equal(actual.uri.toString(), expected.uri.toString());
|
||||
assert.equal(actual.range.isEqual(expected.range), true);
|
||||
|
||||
if (reverse) {
|
||||
// reverse - offset
|
||||
const offset = doc.offsetAt(pos);
|
||||
assert.equal(doc.positionAt(offset).isEqual(pos), true);
|
||||
|
||||
// reverse - pos
|
||||
const actualPosition = doc.positionAt(actual);
|
||||
assert.equal(actualPosition.isEqual(pos), true);
|
||||
}
|
||||
}
|
||||
|
||||
function assertLines(doc: vscode.NotebookConcatTextDocument, ...lines: string[]) {
|
||||
let actual = doc.getText().split(/\r\n|\n|\r/);
|
||||
assert.deepStrictEqual(actual, lines);
|
||||
}
|
||||
|
||||
test('location, position mapping', function () {
|
||||
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
versionId: notebook.versionId + 1,
|
||||
changes: [[0, 0, [{
|
||||
handle: 1,
|
||||
uri: CellUri.generate(notebook.uri, 1),
|
||||
source: ['Hello', 'World', 'Hello World!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}, {
|
||||
handle: 2,
|
||||
uri: CellUri.generate(notebook.uri, 2),
|
||||
source: ['Hallo', 'Welt', 'Hallo Welt!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
|
||||
|
||||
assert.equal(notebook.cells.length, 1 + 2); // markdown and code
|
||||
|
||||
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, undefined);
|
||||
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
|
||||
|
||||
assertLocation(doc, new Position(0, 0), new Location(notebook.cells[0].uri, new Position(0, 0)));
|
||||
assertLocation(doc, new Position(4, 0), new Location(notebook.cells[1].uri, new Position(1, 0)));
|
||||
assertLocation(doc, new Position(4, 3), new Location(notebook.cells[1].uri, new Position(1, 3)));
|
||||
assertLocation(doc, new Position(5, 11), new Location(notebook.cells[1].uri, new Position(2, 11)));
|
||||
assertLocation(doc, new Position(5, 12), new Location(notebook.cells[1].uri, new Position(2, 11)), false); // don't check identity because position will be clamped
|
||||
});
|
||||
|
||||
|
||||
test('location, position mapping, cell changes', function () {
|
||||
|
||||
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, undefined);
|
||||
|
||||
// UPDATE 1
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
versionId: notebook.versionId + 1,
|
||||
changes: [[0, 0, [{
|
||||
handle: 1,
|
||||
uri: CellUri.generate(notebook.uri, 1),
|
||||
source: ['Hello', 'World', 'Hello World!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
assert.equal(notebook.cells.length, 1 + 1);
|
||||
assert.equal(doc.version, 1);
|
||||
assertLines(doc, 'Hello', 'World', 'Hello World!');
|
||||
|
||||
assertLocation(doc, new Position(0, 0), new Location(notebook.cells[0].uri, new Position(0, 0)));
|
||||
assertLocation(doc, new Position(2, 2), new Location(notebook.cells[0].uri, new Position(2, 2)));
|
||||
assertLocation(doc, new Position(4, 0), new Location(notebook.cells[0].uri, new Position(2, 12)), false); // clamped
|
||||
|
||||
|
||||
// UPDATE 2
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
versionId: notebook.versionId + 1,
|
||||
changes: [[1, 0, [{
|
||||
handle: 2,
|
||||
uri: CellUri.generate(notebook.uri, 2),
|
||||
source: ['Hallo', 'Welt', 'Hallo Welt!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
|
||||
assert.equal(notebook.cells.length, 1 + 2);
|
||||
assert.equal(doc.version, 2);
|
||||
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
|
||||
assertLocation(doc, new Position(0, 0), new Location(notebook.cells[0].uri, new Position(0, 0)));
|
||||
assertLocation(doc, new Position(4, 0), new Location(notebook.cells[1].uri, new Position(1, 0)));
|
||||
assertLocation(doc, new Position(4, 3), new Location(notebook.cells[1].uri, new Position(1, 3)));
|
||||
assertLocation(doc, new Position(5, 11), new Location(notebook.cells[1].uri, new Position(2, 11)));
|
||||
assertLocation(doc, new Position(5, 12), new Location(notebook.cells[1].uri, new Position(2, 11)), false); // don't check identity because position will be clamped
|
||||
|
||||
// UPDATE 3 (remove cell #2 again)
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
versionId: notebook.versionId + 1,
|
||||
changes: [[1, 1, []]]
|
||||
});
|
||||
assert.equal(notebook.cells.length, 1 + 1);
|
||||
assert.equal(doc.version, 3);
|
||||
assertLines(doc, 'Hello', 'World', 'Hello World!');
|
||||
assertLocation(doc, new Position(0, 0), new Location(notebook.cells[0].uri, new Position(0, 0)));
|
||||
assertLocation(doc, new Position(2, 2), new Location(notebook.cells[0].uri, new Position(2, 2)));
|
||||
assertLocation(doc, new Position(4, 0), new Location(notebook.cells[0].uri, new Position(2, 12)), false); // clamped
|
||||
});
|
||||
|
||||
test('location, position mapping, cell-document changes', function () {
|
||||
|
||||
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, undefined);
|
||||
|
||||
// UPDATE 1
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
versionId: notebook.versionId + 1,
|
||||
changes: [[0, 0, [{
|
||||
handle: 1,
|
||||
uri: CellUri.generate(notebook.uri, 1),
|
||||
source: ['Hello', 'World', 'Hello World!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}, {
|
||||
handle: 2,
|
||||
uri: CellUri.generate(notebook.uri, 2),
|
||||
source: ['Hallo', 'Welt', 'Hallo Welt!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
assert.equal(notebook.cells.length, 1 + 2);
|
||||
assert.equal(doc.version, 1);
|
||||
|
||||
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
|
||||
assertLocation(doc, new Position(0, 0), new Location(notebook.cells[0].uri, new Position(0, 0)));
|
||||
assertLocation(doc, new Position(2, 2), new Location(notebook.cells[0].uri, new Position(2, 2)));
|
||||
assertLocation(doc, new Position(2, 12), new Location(notebook.cells[0].uri, new Position(2, 12)));
|
||||
assertLocation(doc, new Position(4, 0), new Location(notebook.cells[1].uri, new Position(1, 0)));
|
||||
assertLocation(doc, new Position(4, 3), new Location(notebook.cells[1].uri, new Position(1, 3)));
|
||||
|
||||
// offset math
|
||||
let cell1End = doc.offsetAt(new Position(2, 12));
|
||||
assert.equal(doc.positionAt(cell1End).isEqual(new Position(2, 12)), true);
|
||||
|
||||
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({
|
||||
addedDocuments: [{
|
||||
uri: notebook.cells[0].uri,
|
||||
versionId: 1,
|
||||
lines: ['Hello', 'World', 'Hello World!'],
|
||||
EOL: '\n',
|
||||
modeId: '',
|
||||
isDirty: false
|
||||
}]
|
||||
});
|
||||
|
||||
extHostDocuments.$acceptModelChanged(notebook.cells[0].uri, {
|
||||
versionId: 0,
|
||||
eol: '\n',
|
||||
changes: [{
|
||||
range: { startLineNumber: 3, startColumn: 1, endLineNumber: 3, endColumn: 6 },
|
||||
rangeLength: 6,
|
||||
rangeOffset: 12,
|
||||
text: 'Hi'
|
||||
}]
|
||||
}, false);
|
||||
assertLines(doc, 'Hello', 'World', 'Hi World!', 'Hallo', 'Welt', 'Hallo Welt!');
|
||||
assertLocation(doc, new Position(2, 12), new Location(notebook.cells[0].uri, new Position(2, 9)), false);
|
||||
|
||||
assert.equal(doc.positionAt(cell1End).isEqual(new Position(3, 2)), true);
|
||||
|
||||
});
|
||||
|
||||
test('selector', function () {
|
||||
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
versionId: notebook.versionId + 1,
|
||||
changes: [[0, 0, [{
|
||||
handle: 1,
|
||||
uri: CellUri.generate(notebook.uri, 1),
|
||||
source: ['fooLang-document'],
|
||||
language: 'fooLang',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}, {
|
||||
handle: 2,
|
||||
uri: CellUri.generate(notebook.uri, 2),
|
||||
source: ['barLang-document'],
|
||||
language: 'barLang',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
|
||||
const mixedDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, undefined);
|
||||
const fooLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, 'fooLang');
|
||||
const barLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, 'barLang');
|
||||
|
||||
assertLines(mixedDoc, 'fooLang-document', 'barLang-document');
|
||||
assertLines(fooLangDoc, 'fooLang-document');
|
||||
assertLines(barLangDoc, 'barLang-document');
|
||||
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
versionId: notebook.versionId + 1,
|
||||
changes: [[2, 0, [{
|
||||
handle: 3,
|
||||
uri: CellUri.generate(notebook.uri, 3),
|
||||
source: ['barLang-document2'],
|
||||
language: 'barLang',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
|
||||
assertLines(mixedDoc, 'fooLang-document', 'barLang-document', 'barLang-document2');
|
||||
assertLines(fooLangDoc, 'fooLang-document');
|
||||
assertLines(barLangDoc, 'barLang-document', 'barLang-document2');
|
||||
});
|
||||
|
||||
function assertOffsetAtPosition(doc: vscode.NotebookConcatTextDocument, offset: number, expected: { line: number, character: number }, reverse = true) {
|
||||
const actual = doc.positionAt(offset);
|
||||
|
||||
assert.equal(actual.line, expected.line);
|
||||
assert.equal(actual.character, expected.character);
|
||||
|
||||
if (reverse) {
|
||||
const actualOffset = doc.offsetAt(actual);
|
||||
assert.equal(actualOffset, offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
test('offsetAt(position) <-> positionAt(offset)', function () {
|
||||
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
versionId: notebook.versionId + 1,
|
||||
changes: [[0, 0, [{
|
||||
handle: 1,
|
||||
uri: CellUri.generate(notebook.uri, 1),
|
||||
source: ['Hello', 'World', 'Hello World!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}, {
|
||||
handle: 2,
|
||||
uri: CellUri.generate(notebook.uri, 2),
|
||||
source: ['Hallo', 'Welt', 'Hallo Welt!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
|
||||
assert.equal(notebook.cells.length, 1 + 2); // markdown and code
|
||||
|
||||
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, undefined);
|
||||
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
|
||||
|
||||
assertOffsetAtPosition(doc, 0, { line: 0, character: 0 });
|
||||
assertOffsetAtPosition(doc, 1, { line: 0, character: 1 });
|
||||
assertOffsetAtPosition(doc, 9, { line: 1, character: 3 });
|
||||
assertOffsetAtPosition(doc, 32, { line: 4, character: 1 });
|
||||
assertOffsetAtPosition(doc, 47, { line: 5, character: 11 });
|
||||
});
|
||||
|
||||
|
||||
function assertLocationAtPosition(doc: vscode.NotebookConcatTextDocument, pos: { line: number, character: number }, expected: { uri: URI, line: number, character: number }, reverse = true) {
|
||||
|
||||
const actual = doc.locationAt(new Position(pos.line, pos.character));
|
||||
assert.equal(actual.uri.toString(), expected.uri.toString());
|
||||
assert.equal(actual.range.start.line, expected.line);
|
||||
assert.equal(actual.range.end.line, expected.line);
|
||||
assert.equal(actual.range.start.character, expected.character);
|
||||
assert.equal(actual.range.end.character, expected.character);
|
||||
|
||||
if (reverse) {
|
||||
const actualPos = doc.positionAt(actual);
|
||||
assert.equal(actualPos.line, pos.line);
|
||||
assert.equal(actualPos.character, pos.character);
|
||||
}
|
||||
}
|
||||
|
||||
test('locationAt(position) <-> positionAt(location)', function () {
|
||||
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
versionId: notebook.versionId + 1,
|
||||
changes: [[0, 0, [{
|
||||
handle: 1,
|
||||
uri: CellUri.generate(notebook.uri, 1),
|
||||
source: ['Hello', 'World', 'Hello World!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}, {
|
||||
handle: 2,
|
||||
uri: CellUri.generate(notebook.uri, 2),
|
||||
source: ['Hallo', 'Welt', 'Hallo Welt!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
|
||||
assert.equal(notebook.cells.length, 1 + 2); // markdown and code
|
||||
|
||||
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, undefined);
|
||||
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
|
||||
|
||||
assertLocationAtPosition(doc, { line: 0, character: 0 }, { uri: notebook.cells[0].uri, line: 0, character: 0 });
|
||||
assertLocationAtPosition(doc, { line: 2, character: 0 }, { uri: notebook.cells[0].uri, line: 2, character: 0 });
|
||||
assertLocationAtPosition(doc, { line: 2, character: 12 }, { uri: notebook.cells[0].uri, line: 2, character: 12 });
|
||||
assertLocationAtPosition(doc, { line: 3, character: 0 }, { uri: notebook.cells[1].uri, line: 0, character: 0 });
|
||||
assertLocationAtPosition(doc, { line: 5, character: 0 }, { uri: notebook.cells[1].uri, line: 2, character: 0 });
|
||||
assertLocationAtPosition(doc, { line: 5, character: 11 }, { uri: notebook.cells[1].uri, line: 2, character: 11 });
|
||||
});
|
||||
|
||||
test('getText(range)', function () {
|
||||
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
versionId: notebook.versionId + 1,
|
||||
changes: [[0, 0, [{
|
||||
handle: 1,
|
||||
uri: CellUri.generate(notebook.uri, 1),
|
||||
source: ['Hello', 'World', 'Hello World!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}, {
|
||||
handle: 2,
|
||||
uri: CellUri.generate(notebook.uri, 2),
|
||||
source: ['Hallo', 'Welt', 'Hallo Welt!'],
|
||||
language: 'test',
|
||||
cellKind: CellKind.Code,
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
|
||||
assert.equal(notebook.cells.length, 1 + 2); // markdown and code
|
||||
|
||||
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook, undefined);
|
||||
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
|
||||
|
||||
assert.equal(doc.getText(new Range(0, 0, 0, 0)), '');
|
||||
assert.equal(doc.getText(new Range(0, 0, 1, 0)), 'Hello\n');
|
||||
assert.equal(doc.getText(new Range(2, 0, 4, 0)), 'Hello World!\nHallo\n');
|
||||
});
|
||||
});
|
||||
@@ -20,6 +20,7 @@ import { ExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
|
||||
import { ITextQueryBuilderOptions } from 'vs/workbench/contrib/search/common/queryBuilder';
|
||||
import { IPatternInfo } from 'vs/workbench/services/search/common/search';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
||||
function createExtHostWorkspace(mainContext: IMainContext, data: IWorkspaceData, logService: ILogService): ExtHostWorkspace {
|
||||
const result = new ExtHostWorkspace(
|
||||
@@ -552,14 +553,17 @@ suite('ExtHostWorkspace', function () {
|
||||
});
|
||||
|
||||
test('`vscode.workspace.getWorkspaceFolder(file)` don\'t return workspace folder when file open from command line. #36221', function () {
|
||||
let ws = createExtHostWorkspace(new TestRPCProtocol(), {
|
||||
id: 'foo', name: 'Test', folders: [
|
||||
aWorkspaceFolderData(URI.file('c:/Users/marek/Desktop/vsc_test/'), 0)
|
||||
]
|
||||
}, new NullLogService());
|
||||
if (isWindows) {
|
||||
|
||||
assert.ok(ws.getWorkspaceFolder(URI.file('c:/Users/marek/Desktop/vsc_test/a.txt')));
|
||||
assert.ok(ws.getWorkspaceFolder(URI.file('C:/Users/marek/Desktop/vsc_test/b.txt')));
|
||||
let ws = createExtHostWorkspace(new TestRPCProtocol(), {
|
||||
id: 'foo', name: 'Test', folders: [
|
||||
aWorkspaceFolderData(URI.file('c:/Users/marek/Desktop/vsc_test/'), 0)
|
||||
]
|
||||
}, new NullLogService());
|
||||
|
||||
assert.ok(ws.getWorkspaceFolder(URI.file('c:/Users/marek/Desktop/vsc_test/a.txt')));
|
||||
assert.ok(ws.getWorkspaceFolder(URI.file('C:/Users/marek/Desktop/vsc_test/b.txt')));
|
||||
}
|
||||
});
|
||||
|
||||
function aWorkspaceFolderData(uri: URI, index: number, name: string = ''): IWorkspaceFolderData {
|
||||
|
||||
@@ -1,628 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { ContributableViewsModel, IViewState } from 'vs/workbench/browser/parts/views/views';
|
||||
import { IViewsRegistry, IViewDescriptor, IViewContainersRegistry, Extensions as ViewContainerExtensions, IViewDescriptorService, ViewContainerLocation, ViewContainer } from 'vs/workbench/common/views';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { move } from 'vs/base/common/arrays';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
|
||||
import sinon = require('sinon');
|
||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { ViewDescriptorService } from 'vs/workbench/services/views/browser/viewDescriptorService';
|
||||
import { assertIsDefined } from 'vs/base/common/types';
|
||||
|
||||
const container = Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry).registerViewContainer({ id: 'test', name: 'test', ctorDescriptor: new SyncDescriptor(<any>{}) }, ViewContainerLocation.Sidebar);
|
||||
const ViewsRegistry = Registry.as<IViewsRegistry>(ViewContainerExtensions.ViewsRegistry);
|
||||
|
||||
class ViewDescriptorSequence {
|
||||
|
||||
readonly elements: IViewDescriptor[];
|
||||
private disposables: IDisposable[] = [];
|
||||
|
||||
constructor(model: ContributableViewsModel) {
|
||||
this.elements = [...model.visibleViewDescriptors];
|
||||
model.onDidAdd(added => added.forEach(({ viewDescriptor, index }) => this.elements.splice(index, 0, viewDescriptor)), null, this.disposables);
|
||||
model.onDidRemove(removed => removed.sort((a, b) => b.index - a.index).forEach(({ index }) => this.elements.splice(index, 1)), null, this.disposables);
|
||||
model.onDidMove(({ from, to }) => move(this.elements, from.index, to.index), null, this.disposables);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.disposables = dispose(this.disposables);
|
||||
}
|
||||
}
|
||||
|
||||
suite('ContributableViewsModel', () => {
|
||||
|
||||
let viewDescriptorService: IViewDescriptorService;
|
||||
let contextKeyService: IContextKeyService;
|
||||
|
||||
setup(() => {
|
||||
const instantiationService: TestInstantiationService = <TestInstantiationService>workbenchInstantiationService();
|
||||
contextKeyService = instantiationService.createInstance(ContextKeyService);
|
||||
instantiationService.stub(IContextKeyService, contextKeyService);
|
||||
viewDescriptorService = instantiationService.createInstance(ViewDescriptorService);
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
ViewsRegistry.deregisterViews(ViewsRegistry.getViews(container), container);
|
||||
});
|
||||
|
||||
test('empty model', function () {
|
||||
const model = new ContributableViewsModel(container, viewDescriptorService);
|
||||
assert.equal(model.visibleViewDescriptors.length, 0);
|
||||
});
|
||||
|
||||
test('register/unregister', () => {
|
||||
const model = new ContributableViewsModel(container, viewDescriptorService);
|
||||
const seq = new ViewDescriptorSequence(model);
|
||||
|
||||
assert.equal(model.visibleViewDescriptors.length, 0);
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
const viewDescriptor: IViewDescriptor = {
|
||||
id: 'view1',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1'
|
||||
};
|
||||
|
||||
ViewsRegistry.registerViews([viewDescriptor], container);
|
||||
|
||||
assert.equal(model.visibleViewDescriptors.length, 1);
|
||||
assert.equal(seq.elements.length, 1);
|
||||
assert.deepEqual(model.visibleViewDescriptors[0], viewDescriptor);
|
||||
assert.deepEqual(seq.elements[0], viewDescriptor);
|
||||
|
||||
ViewsRegistry.deregisterViews([viewDescriptor], container);
|
||||
|
||||
assert.equal(model.visibleViewDescriptors.length, 0);
|
||||
assert.equal(seq.elements.length, 0);
|
||||
});
|
||||
|
||||
test('when contexts', async function () {
|
||||
const model = new ContributableViewsModel(container, viewDescriptorService);
|
||||
const seq = new ViewDescriptorSequence(model);
|
||||
|
||||
assert.equal(model.visibleViewDescriptors.length, 0);
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
const viewDescriptor: IViewDescriptor = {
|
||||
id: 'view1',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1',
|
||||
when: ContextKeyExpr.equals('showview1', true)
|
||||
};
|
||||
|
||||
ViewsRegistry.registerViews([viewDescriptor], container);
|
||||
assert.equal(model.visibleViewDescriptors.length, 0, 'view should not appear since context isnt in');
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
const key = contextKeyService.createKey('showview1', false);
|
||||
assert.equal(model.visibleViewDescriptors.length, 0, 'view should still not appear since showview1 isnt true');
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
key.set(true);
|
||||
await new Promise(c => setTimeout(c, 30));
|
||||
assert.equal(model.visibleViewDescriptors.length, 1, 'view should appear');
|
||||
assert.equal(seq.elements.length, 1);
|
||||
assert.deepEqual(model.visibleViewDescriptors[0], viewDescriptor);
|
||||
assert.equal(seq.elements[0], viewDescriptor);
|
||||
|
||||
key.set(false);
|
||||
await new Promise(c => setTimeout(c, 30));
|
||||
assert.equal(model.visibleViewDescriptors.length, 0, 'view should disappear');
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
ViewsRegistry.deregisterViews([viewDescriptor], container);
|
||||
assert.equal(model.visibleViewDescriptors.length, 0, 'view should not be there anymore');
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
key.set(true);
|
||||
await new Promise(c => setTimeout(c, 30));
|
||||
assert.equal(model.visibleViewDescriptors.length, 0, 'view should not be there anymore');
|
||||
assert.equal(seq.elements.length, 0);
|
||||
});
|
||||
|
||||
test('when contexts - multiple', async function () {
|
||||
const model = new ContributableViewsModel(container, viewDescriptorService);
|
||||
const seq = new ViewDescriptorSequence(model);
|
||||
|
||||
const view1: IViewDescriptor = { id: 'view1', ctorDescriptor: null!, name: 'Test View 1' };
|
||||
const view2: IViewDescriptor = { id: 'view2', ctorDescriptor: null!, name: 'Test View 2', when: ContextKeyExpr.equals('showview2', true) };
|
||||
|
||||
ViewsRegistry.registerViews([view1, view2], container);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1], 'only view1 should be visible');
|
||||
assert.deepEqual(seq.elements, [view1], 'only view1 should be visible');
|
||||
|
||||
const key = contextKeyService.createKey('showview2', false);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1], 'still only view1 should be visible');
|
||||
assert.deepEqual(seq.elements, [view1], 'still only view1 should be visible');
|
||||
|
||||
key.set(true);
|
||||
await new Promise(c => setTimeout(c, 30));
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1, view2], 'both views should be visible');
|
||||
assert.deepEqual(seq.elements, [view1, view2], 'both views should be visible');
|
||||
|
||||
ViewsRegistry.deregisterViews([view1, view2], container);
|
||||
});
|
||||
|
||||
test('when contexts - multiple 2', async function () {
|
||||
const model = new ContributableViewsModel(container, viewDescriptorService);
|
||||
const seq = new ViewDescriptorSequence(model);
|
||||
|
||||
const view1: IViewDescriptor = { id: 'view1', ctorDescriptor: null!, name: 'Test View 1', when: ContextKeyExpr.equals('showview1', true) };
|
||||
const view2: IViewDescriptor = { id: 'view2', ctorDescriptor: null!, name: 'Test View 2' };
|
||||
|
||||
ViewsRegistry.registerViews([view1, view2], container);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view2], 'only view2 should be visible');
|
||||
assert.deepEqual(seq.elements, [view2], 'only view2 should be visible');
|
||||
|
||||
const key = contextKeyService.createKey('showview1', false);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view2], 'still only view2 should be visible');
|
||||
assert.deepEqual(seq.elements, [view2], 'still only view2 should be visible');
|
||||
|
||||
key.set(true);
|
||||
await new Promise(c => setTimeout(c, 30));
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1, view2], 'both views should be visible');
|
||||
assert.deepEqual(seq.elements, [view1, view2], 'both views should be visible');
|
||||
|
||||
ViewsRegistry.deregisterViews([view1, view2], container);
|
||||
});
|
||||
|
||||
test('setVisible', () => {
|
||||
const model = new ContributableViewsModel(container, viewDescriptorService);
|
||||
const seq = new ViewDescriptorSequence(model);
|
||||
|
||||
const view1: IViewDescriptor = { id: 'view1', ctorDescriptor: null!, name: 'Test View 1', canToggleVisibility: true };
|
||||
const view2: IViewDescriptor = { id: 'view2', ctorDescriptor: null!, name: 'Test View 2', canToggleVisibility: true };
|
||||
const view3: IViewDescriptor = { id: 'view3', ctorDescriptor: null!, name: 'Test View 3', canToggleVisibility: true };
|
||||
|
||||
ViewsRegistry.registerViews([view1, view2, view3], container);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1, view2, view3]);
|
||||
assert.deepEqual(seq.elements, [view1, view2, view3]);
|
||||
|
||||
model.setVisible('view2', true);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1, view2, view3], 'nothing should happen');
|
||||
assert.deepEqual(seq.elements, [view1, view2, view3]);
|
||||
|
||||
model.setVisible('view2', false);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1, view3], 'view2 should hide');
|
||||
assert.deepEqual(seq.elements, [view1, view3]);
|
||||
|
||||
model.setVisible('view1', false);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view3], 'view1 should hide');
|
||||
assert.deepEqual(seq.elements, [view3]);
|
||||
|
||||
model.setVisible('view3', false);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [], 'view3 shoud hide');
|
||||
assert.deepEqual(seq.elements, []);
|
||||
|
||||
model.setVisible('view1', true);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1], 'view1 should show');
|
||||
assert.deepEqual(seq.elements, [view1]);
|
||||
|
||||
model.setVisible('view3', true);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1, view3], 'view3 should show');
|
||||
assert.deepEqual(seq.elements, [view1, view3]);
|
||||
|
||||
model.setVisible('view2', true);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1, view2, view3], 'view2 should show');
|
||||
assert.deepEqual(seq.elements, [view1, view2, view3]);
|
||||
|
||||
ViewsRegistry.deregisterViews([view1, view2, view3], container);
|
||||
assert.deepEqual(model.visibleViewDescriptors, []);
|
||||
assert.deepEqual(seq.elements, []);
|
||||
});
|
||||
|
||||
test('move', () => {
|
||||
const model = new ContributableViewsModel(container, viewDescriptorService);
|
||||
const seq = new ViewDescriptorSequence(model);
|
||||
|
||||
const view1: IViewDescriptor = { id: 'view1', ctorDescriptor: null!, name: 'Test View 1' };
|
||||
const view2: IViewDescriptor = { id: 'view2', ctorDescriptor: null!, name: 'Test View 2' };
|
||||
const view3: IViewDescriptor = { id: 'view3', ctorDescriptor: null!, name: 'Test View 3' };
|
||||
|
||||
ViewsRegistry.registerViews([view1, view2, view3], container);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1, view2, view3], 'model views should be OK');
|
||||
assert.deepEqual(seq.elements, [view1, view2, view3], 'sql views should be OK');
|
||||
|
||||
model.move('view3', 'view1');
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view3, view1, view2], 'view3 should go to the front');
|
||||
assert.deepEqual(seq.elements, [view3, view1, view2]);
|
||||
|
||||
model.move('view1', 'view2');
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view3, view2, view1], 'view1 should go to the end');
|
||||
assert.deepEqual(seq.elements, [view3, view2, view1]);
|
||||
|
||||
model.move('view1', 'view3');
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1, view3, view2], 'view1 should go to the front');
|
||||
assert.deepEqual(seq.elements, [view1, view3, view2]);
|
||||
|
||||
model.move('view2', 'view3');
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view1, view2, view3], 'view2 should go to the middle');
|
||||
assert.deepEqual(seq.elements, [view1, view2, view3]);
|
||||
});
|
||||
|
||||
test('view states', async function () {
|
||||
const viewStates = new Map<string, IViewState>();
|
||||
viewStates.set('view1', { visibleGlobal: false, collapsed: false, visibleWorkspace: undefined });
|
||||
const model = new ContributableViewsModel(container, viewDescriptorService, viewStates);
|
||||
const seq = new ViewDescriptorSequence(model);
|
||||
|
||||
assert.equal(model.visibleViewDescriptors.length, 0);
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
const viewDescriptor: IViewDescriptor = {
|
||||
id: 'view1',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1'
|
||||
};
|
||||
|
||||
ViewsRegistry.registerViews([viewDescriptor], container);
|
||||
assert.equal(model.visibleViewDescriptors.length, 0, 'view should not appear since it was set not visible in view state');
|
||||
assert.equal(seq.elements.length, 0);
|
||||
});
|
||||
|
||||
test('view states and when contexts', async function () {
|
||||
const viewStates = new Map<string, IViewState>();
|
||||
viewStates.set('view1', { visibleGlobal: false, collapsed: false, visibleWorkspace: undefined });
|
||||
const model = new ContributableViewsModel(container, viewDescriptorService, viewStates);
|
||||
const seq = new ViewDescriptorSequence(model);
|
||||
|
||||
assert.equal(model.visibleViewDescriptors.length, 0);
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
const viewDescriptor: IViewDescriptor = {
|
||||
id: 'view1',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1',
|
||||
when: ContextKeyExpr.equals('showview1', true)
|
||||
};
|
||||
|
||||
ViewsRegistry.registerViews([viewDescriptor], container);
|
||||
assert.equal(model.visibleViewDescriptors.length, 0, 'view should not appear since context isnt in');
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
const key = contextKeyService.createKey('showview1', false);
|
||||
assert.equal(model.visibleViewDescriptors.length, 0, 'view should still not appear since showview1 isnt true');
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
key.set(true);
|
||||
await new Promise(c => setTimeout(c, 30));
|
||||
assert.equal(model.visibleViewDescriptors.length, 0, 'view should still not appear since it was set not visible in view state');
|
||||
assert.equal(seq.elements.length, 0);
|
||||
});
|
||||
|
||||
test('view states and when contexts multiple views', async function () {
|
||||
const viewStates = new Map<string, IViewState>();
|
||||
viewStates.set('view1', { visibleGlobal: false, collapsed: false, visibleWorkspace: undefined });
|
||||
const model = new ContributableViewsModel(container, viewDescriptorService, viewStates);
|
||||
const seq = new ViewDescriptorSequence(model);
|
||||
|
||||
assert.equal(model.visibleViewDescriptors.length, 0);
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
const view1: IViewDescriptor = {
|
||||
id: 'view1',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1',
|
||||
when: ContextKeyExpr.equals('showview', true)
|
||||
};
|
||||
const view2: IViewDescriptor = {
|
||||
id: 'view2',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 2',
|
||||
};
|
||||
const view3: IViewDescriptor = {
|
||||
id: 'view3',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 3',
|
||||
when: ContextKeyExpr.equals('showview', true)
|
||||
};
|
||||
|
||||
ViewsRegistry.registerViews([view1, view2, view3], container);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view2], 'Only view2 should be visible');
|
||||
assert.deepEqual(seq.elements, [view2]);
|
||||
|
||||
const key = contextKeyService.createKey('showview', false);
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view2], 'Only view2 should be visible');
|
||||
assert.deepEqual(seq.elements, [view2]);
|
||||
|
||||
key.set(true);
|
||||
await new Promise(c => setTimeout(c, 30));
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view2, view3], 'view3 should be visible');
|
||||
assert.deepEqual(seq.elements, [view2, view3]);
|
||||
|
||||
key.set(false);
|
||||
await new Promise(c => setTimeout(c, 30));
|
||||
assert.deepEqual(model.visibleViewDescriptors, [view2], 'Only view2 should be visible');
|
||||
assert.deepEqual(seq.elements, [view2]);
|
||||
});
|
||||
|
||||
test('remove event is not triggered if view was hidden and removed', async function () {
|
||||
const model = new ContributableViewsModel(container, viewDescriptorService);
|
||||
const seq = new ViewDescriptorSequence(model);
|
||||
|
||||
const viewDescriptor: IViewDescriptor = {
|
||||
id: 'view1',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1',
|
||||
when: ContextKeyExpr.equals('showview1', true),
|
||||
canToggleVisibility: true
|
||||
};
|
||||
|
||||
ViewsRegistry.registerViews([viewDescriptor], container);
|
||||
|
||||
const key = contextKeyService.createKey('showview1', true);
|
||||
await new Promise(c => setTimeout(c, 30));
|
||||
assert.equal(model.visibleViewDescriptors.length, 1, 'view should appear after context is set');
|
||||
assert.equal(seq.elements.length, 1);
|
||||
|
||||
model.setVisible('view1', false);
|
||||
assert.equal(model.visibleViewDescriptors.length, 0, 'view should disappear after setting visibility to false');
|
||||
assert.equal(seq.elements.length, 0);
|
||||
|
||||
const target = sinon.spy(model.onDidRemove);
|
||||
key.set(false);
|
||||
await new Promise(c => setTimeout(c, 30));
|
||||
assert.ok(!target.called, 'remove event should not be called since it is already hidden');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
const sidebarContainer = Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry).registerViewContainer({ id: 'testSidebar', name: 'test', ctorDescriptor: new SyncDescriptor(<any>{}) }, ViewContainerLocation.Sidebar);
|
||||
const panelContainer = Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry).registerViewContainer({ id: 'testPanel', name: 'test', ctorDescriptor: new SyncDescriptor(<any>{}) }, ViewContainerLocation.Panel);
|
||||
|
||||
suite('ViewDescriptorService', () => {
|
||||
|
||||
let viewDescriptorService: IViewDescriptorService;
|
||||
|
||||
setup(() => {
|
||||
const instantiationService: TestInstantiationService = <TestInstantiationService>workbenchInstantiationService();
|
||||
viewDescriptorService = instantiationService.createInstance(ViewDescriptorService);
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
ViewsRegistry.deregisterViews(ViewsRegistry.getViews(sidebarContainer), sidebarContainer);
|
||||
ViewsRegistry.deregisterViews(ViewsRegistry.getViews(panelContainer), panelContainer);
|
||||
});
|
||||
|
||||
test('Empty Containers', function () {
|
||||
const sidebarViews = viewDescriptorService.getViewDescriptors(sidebarContainer);
|
||||
const panelViews = viewDescriptorService.getViewDescriptors(panelContainer);
|
||||
assert.equal(sidebarViews.allViewDescriptors.length, 0, 'The sidebar container should have no views yet.');
|
||||
assert.equal(panelViews.allViewDescriptors.length, 0, 'The panel container should have no views yet.');
|
||||
});
|
||||
|
||||
test('Register/Deregister', () => {
|
||||
const viewDescriptors: IViewDescriptor[] = [
|
||||
{
|
||||
id: 'view1',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1',
|
||||
canMoveView: true
|
||||
},
|
||||
{
|
||||
id: 'view2',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 2',
|
||||
canMoveView: true
|
||||
},
|
||||
{
|
||||
id: 'view3',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 3',
|
||||
canMoveView: true
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
ViewsRegistry.registerViews(viewDescriptors.slice(0, 2), sidebarContainer);
|
||||
ViewsRegistry.registerViews(viewDescriptors.slice(2), panelContainer);
|
||||
|
||||
|
||||
let sidebarViews = viewDescriptorService.getViewDescriptors(sidebarContainer);
|
||||
let panelViews = viewDescriptorService.getViewDescriptors(panelContainer);
|
||||
|
||||
assert.equal(sidebarViews.activeViewDescriptors.length, 2, 'Sidebar should have 2 views');
|
||||
assert.equal(panelViews.activeViewDescriptors.length, 1, 'Panel should have 1 view');
|
||||
|
||||
ViewsRegistry.deregisterViews(viewDescriptors.slice(0, 2), sidebarContainer);
|
||||
ViewsRegistry.deregisterViews(viewDescriptors.slice(2), panelContainer);
|
||||
|
||||
|
||||
sidebarViews = viewDescriptorService.getViewDescriptors(sidebarContainer);
|
||||
panelViews = viewDescriptorService.getViewDescriptors(panelContainer);
|
||||
|
||||
assert.equal(sidebarViews.activeViewDescriptors.length, 0, 'Sidebar should have no views');
|
||||
assert.equal(panelViews.activeViewDescriptors.length, 0, 'Panel should have no views');
|
||||
});
|
||||
|
||||
test('move views to existing containers', async function () {
|
||||
const viewDescriptors: IViewDescriptor[] = [
|
||||
{
|
||||
id: 'view1',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1',
|
||||
canMoveView: true
|
||||
},
|
||||
{
|
||||
id: 'view2',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 2',
|
||||
canMoveView: true
|
||||
},
|
||||
{
|
||||
id: 'view3',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 3',
|
||||
canMoveView: true
|
||||
}
|
||||
];
|
||||
|
||||
ViewsRegistry.registerViews(viewDescriptors.slice(0, 2), sidebarContainer);
|
||||
ViewsRegistry.registerViews(viewDescriptors.slice(2), panelContainer);
|
||||
|
||||
viewDescriptorService.moveViewsToContainer(viewDescriptors.slice(2), sidebarContainer);
|
||||
viewDescriptorService.moveViewsToContainer(viewDescriptors.slice(0, 2), panelContainer);
|
||||
|
||||
let sidebarViews = viewDescriptorService.getViewDescriptors(sidebarContainer);
|
||||
let panelViews = viewDescriptorService.getViewDescriptors(panelContainer);
|
||||
|
||||
assert.equal(sidebarViews.activeViewDescriptors.length, 1, 'Sidebar should have 2 views');
|
||||
assert.equal(panelViews.activeViewDescriptors.length, 2, 'Panel should have 1 view');
|
||||
|
||||
assert.notEqual(sidebarViews.activeViewDescriptors.indexOf(viewDescriptors[2]), -1, `Sidebar should have ${viewDescriptors[2].name}`);
|
||||
assert.notEqual(panelViews.activeViewDescriptors.indexOf(viewDescriptors[0]), -1, `Panel should have ${viewDescriptors[0].name}`);
|
||||
assert.notEqual(panelViews.activeViewDescriptors.indexOf(viewDescriptors[1]), -1, `Panel should have ${viewDescriptors[1].name}`);
|
||||
});
|
||||
|
||||
test('move views to generated containers', async function () {
|
||||
const viewDescriptors: IViewDescriptor[] = [
|
||||
{
|
||||
id: 'view1',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1',
|
||||
canMoveView: true
|
||||
},
|
||||
{
|
||||
id: 'view2',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 2',
|
||||
canMoveView: true
|
||||
},
|
||||
{
|
||||
id: 'view3',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 3',
|
||||
canMoveView: true
|
||||
}
|
||||
];
|
||||
|
||||
ViewsRegistry.registerViews(viewDescriptors.slice(0, 2), sidebarContainer);
|
||||
ViewsRegistry.registerViews(viewDescriptors.slice(2), panelContainer);
|
||||
|
||||
viewDescriptorService.moveViewToLocation(viewDescriptors[0], ViewContainerLocation.Panel);
|
||||
viewDescriptorService.moveViewToLocation(viewDescriptors[2], ViewContainerLocation.Sidebar);
|
||||
|
||||
let sidebarViews = viewDescriptorService.getViewDescriptors(sidebarContainer);
|
||||
let panelViews = viewDescriptorService.getViewDescriptors(panelContainer);
|
||||
|
||||
assert.equal(sidebarViews.activeViewDescriptors.length, 1, 'Sidebar container should have 1 view');
|
||||
assert.equal(panelViews.activeViewDescriptors.length, 0, 'Panel container should have no views');
|
||||
|
||||
const generatedPanel = assertIsDefined(viewDescriptorService.getViewContainer(viewDescriptors[0].id));
|
||||
const generatedSidebar = assertIsDefined(viewDescriptorService.getViewContainer(viewDescriptors[2].id));
|
||||
|
||||
assert.equal(viewDescriptorService.getViewContainerLocation(generatedPanel), ViewContainerLocation.Panel, 'Generated Panel should be in located in the panel');
|
||||
assert.equal(viewDescriptorService.getViewContainerLocation(generatedSidebar), ViewContainerLocation.Sidebar, 'Generated Sidebar should be in located in the sidebar');
|
||||
|
||||
assert.equal(viewDescriptorService.getViewContainerLocation(generatedPanel), viewDescriptorService.getViewLocation(viewDescriptors[0].id), 'Panel view location and container location should match');
|
||||
assert.equal(viewDescriptorService.getViewContainerLocation(generatedSidebar), viewDescriptorService.getViewLocation(viewDescriptors[2].id), 'Sidebar view location and container location should match');
|
||||
|
||||
assert.equal(viewDescriptorService.getDefaultContainer(viewDescriptors[2].id), panelContainer, `${viewDescriptors[2].name} has wrong default container`);
|
||||
assert.equal(viewDescriptorService.getDefaultContainer(viewDescriptors[0].id), sidebarContainer, `${viewDescriptors[0].name} has wrong default container`);
|
||||
|
||||
viewDescriptorService.moveViewToLocation(viewDescriptors[0], ViewContainerLocation.Sidebar);
|
||||
viewDescriptorService.moveViewToLocation(viewDescriptors[2], ViewContainerLocation.Panel);
|
||||
|
||||
sidebarViews = viewDescriptorService.getViewDescriptors(sidebarContainer);
|
||||
panelViews = viewDescriptorService.getViewDescriptors(panelContainer);
|
||||
|
||||
assert.equal(sidebarViews.activeViewDescriptors.length, 1, 'Sidebar should have 2 views');
|
||||
assert.equal(panelViews.activeViewDescriptors.length, 0, 'Panel should have 1 view');
|
||||
|
||||
assert.equal(viewDescriptorService.getViewLocation(viewDescriptors[0].id), ViewContainerLocation.Sidebar, 'View should be located in the sidebar');
|
||||
assert.equal(viewDescriptorService.getViewLocation(viewDescriptors[2].id), ViewContainerLocation.Panel, 'View should be located in the panel');
|
||||
});
|
||||
|
||||
test('move view events', async function () {
|
||||
const viewDescriptors: IViewDescriptor[] = [
|
||||
{
|
||||
id: 'view1',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1',
|
||||
canMoveView: true
|
||||
},
|
||||
{
|
||||
id: 'view2',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 2',
|
||||
canMoveView: true
|
||||
},
|
||||
{
|
||||
id: 'view3',
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 3',
|
||||
canMoveView: true
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
let expectedSequence = '';
|
||||
let actualSequence = '';
|
||||
const disposables = [];
|
||||
|
||||
const containerMoveString = (view: IViewDescriptor, from: ViewContainer, to: ViewContainer) => {
|
||||
return `Moved ${view.id} from ${from.id} to ${to.id}\n`;
|
||||
};
|
||||
|
||||
const locationMoveString = (view: IViewDescriptor, from: ViewContainerLocation, to: ViewContainerLocation) => {
|
||||
return `Moved ${view.id} from ${from === ViewContainerLocation.Sidebar ? 'Sidebar' : 'Panel'} to ${to === ViewContainerLocation.Sidebar ? 'Sidebar' : 'Panel'}\n`;
|
||||
};
|
||||
disposables.push(viewDescriptorService.onDidChangeContainer(({ views, from, to }) => {
|
||||
views.forEach(view => {
|
||||
actualSequence += containerMoveString(view, from, to);
|
||||
});
|
||||
}));
|
||||
|
||||
disposables.push(viewDescriptorService.onDidChangeLocation(({ views, from, to }) => {
|
||||
views.forEach(view => {
|
||||
actualSequence += locationMoveString(view, from, to);
|
||||
});
|
||||
}));
|
||||
|
||||
ViewsRegistry.registerViews(viewDescriptors.slice(0, 2), sidebarContainer);
|
||||
ViewsRegistry.registerViews(viewDescriptors.slice(2), panelContainer);
|
||||
|
||||
expectedSequence += locationMoveString(viewDescriptors[0], ViewContainerLocation.Sidebar, ViewContainerLocation.Panel);
|
||||
viewDescriptorService.moveViewToLocation(viewDescriptors[0], ViewContainerLocation.Panel);
|
||||
expectedSequence += containerMoveString(viewDescriptors[0], sidebarContainer, viewDescriptorService.getViewContainer(viewDescriptors[0].id)!);
|
||||
|
||||
expectedSequence += locationMoveString(viewDescriptors[2], ViewContainerLocation.Panel, ViewContainerLocation.Sidebar);
|
||||
viewDescriptorService.moveViewToLocation(viewDescriptors[2], ViewContainerLocation.Sidebar);
|
||||
expectedSequence += containerMoveString(viewDescriptors[2], panelContainer, viewDescriptorService.getViewContainer(viewDescriptors[2].id)!);
|
||||
|
||||
|
||||
expectedSequence += locationMoveString(viewDescriptors[0], ViewContainerLocation.Panel, ViewContainerLocation.Sidebar);
|
||||
expectedSequence += containerMoveString(viewDescriptors[0], viewDescriptorService.getViewContainer(viewDescriptors[0].id)!, sidebarContainer);
|
||||
viewDescriptorService.moveViewsToContainer([viewDescriptors[0]], sidebarContainer);
|
||||
|
||||
expectedSequence += locationMoveString(viewDescriptors[2], ViewContainerLocation.Sidebar, ViewContainerLocation.Panel);
|
||||
expectedSequence += containerMoveString(viewDescriptors[2], viewDescriptorService.getViewContainer(viewDescriptors[2].id)!, panelContainer);
|
||||
viewDescriptorService.moveViewsToContainer([viewDescriptors[2]], panelContainer);
|
||||
|
||||
expectedSequence += locationMoveString(viewDescriptors[0], ViewContainerLocation.Sidebar, ViewContainerLocation.Panel);
|
||||
expectedSequence += containerMoveString(viewDescriptors[0], sidebarContainer, panelContainer);
|
||||
viewDescriptorService.moveViewsToContainer([viewDescriptors[0]], panelContainer);
|
||||
|
||||
expectedSequence += locationMoveString(viewDescriptors[2], ViewContainerLocation.Panel, ViewContainerLocation.Sidebar);
|
||||
expectedSequence += containerMoveString(viewDescriptors[2], panelContainer, sidebarContainer);
|
||||
viewDescriptorService.moveViewsToContainer([viewDescriptors[2]], sidebarContainer);
|
||||
|
||||
expectedSequence += locationMoveString(viewDescriptors[1], ViewContainerLocation.Sidebar, ViewContainerLocation.Panel);
|
||||
expectedSequence += locationMoveString(viewDescriptors[2], ViewContainerLocation.Sidebar, ViewContainerLocation.Panel);
|
||||
expectedSequence += containerMoveString(viewDescriptors[1], sidebarContainer, panelContainer);
|
||||
expectedSequence += containerMoveString(viewDescriptors[2], sidebarContainer, panelContainer);
|
||||
viewDescriptorService.moveViewsToContainer([viewDescriptors[1], viewDescriptors[2]], panelContainer);
|
||||
|
||||
assert.equal(actualSequence, expectedSequence, 'Event sequence not matching expected sequence');
|
||||
});
|
||||
|
||||
});
|
||||
@@ -52,7 +52,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations';
|
||||
import { IDisposable, toDisposable, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, IFindGroupScope, EditorGroupLayout, ICloseEditorOptions, GroupOrientation } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { IEditorService, IOpenEditorOverrideHandler, ISaveEditorsOptions, IRevertAllEditorsOptions, IResourceEditorInputType, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IEditorService, IOpenEditorOverrideHandler, ISaveEditorsOptions, IRevertAllEditorsOptions, IResourceEditorInputType, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE, IOpenEditorOverrideEntry, ICustomEditorViewTypesHandler } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
||||
import { IEditorRegistry, EditorDescriptor, Extensions } from 'vs/workbench/browser/editor';
|
||||
import { EditorGroup } from 'vs/workbench/common/editor/editorGroup';
|
||||
@@ -83,7 +83,7 @@ import { BrowserWorkbenchEnvironmentService } from 'vs/workbench/services/enviro
|
||||
import { BrowserTextFileService } from 'vs/workbench/services/textfile/browser/browserTextFileService';
|
||||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
import { createTextBufferFactoryFromStream } from 'vs/editor/common/model/textModel';
|
||||
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
|
||||
import { IPathService } from 'vs/workbench/services/path/common/pathService';
|
||||
import { Direction } from 'vs/base/browser/ui/grid/grid';
|
||||
import { IProgressService, IProgressOptions, IProgressWindowOptions, IProgressNotificationOptions, IProgressCompositeOptions, IProgress, IProgressStep, Progress } from 'vs/platform/progress/common/progress';
|
||||
import { IWorkingCopyFileService, WorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService';
|
||||
@@ -115,7 +115,10 @@ export interface ITestInstantiationService extends IInstantiationService {
|
||||
stub<T>(service: ServiceIdentifier<T>, ctor: any): T;
|
||||
}
|
||||
|
||||
export function workbenchInstantiationService(overrides?: { textFileService?: (instantiationService: IInstantiationService) => ITextFileService }): ITestInstantiationService {
|
||||
export function workbenchInstantiationService(overrides?: {
|
||||
textFileService?: (instantiationService: IInstantiationService) => ITextFileService
|
||||
pathService?: (instantiationService: IInstantiationService) => IPathService
|
||||
}): ITestInstantiationService {
|
||||
const instantiationService = new TestInstantiationService(new ServiceCollection([ILifecycleService, new TestLifecycleService()]));
|
||||
|
||||
instantiationService.stub(IWorkingCopyService, new TestWorkingCopyService());
|
||||
@@ -131,7 +134,7 @@ export function workbenchInstantiationService(overrides?: { textFileService?: (i
|
||||
instantiationService.stub(ITextResourceConfigurationService, new TestTextResourceConfigurationService(configService));
|
||||
instantiationService.stub(IUntitledTextEditorService, instantiationService.createInstance(UntitledTextEditorService));
|
||||
instantiationService.stub(IStorageService, new TestStorageService());
|
||||
instantiationService.stub(IRemotePathService, new TestRemotePathService(TestEnvironmentService));
|
||||
instantiationService.stub(IPathService, overrides?.pathService ? overrides.pathService(instantiationService) : new TestPathService());
|
||||
const layoutService = new TestLayoutService();
|
||||
instantiationService.stub(IWorkbenchLayoutService, layoutService);
|
||||
instantiationService.stub(IDialogService, new TestDialogService());
|
||||
@@ -214,7 +217,7 @@ export class TestTextFileService extends BrowserTextFileService {
|
||||
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
|
||||
@ITextModelService textModelService: ITextModelService,
|
||||
@ICodeEditorService codeEditorService: ICodeEditorService,
|
||||
@IRemotePathService remotePathService: IRemotePathService,
|
||||
@IPathService pathService: IPathService,
|
||||
@IWorkingCopyFileService workingCopyFileService: IWorkingCopyFileService
|
||||
) {
|
||||
super(
|
||||
@@ -230,7 +233,7 @@ export class TestTextFileService extends BrowserTextFileService {
|
||||
filesConfigurationService,
|
||||
textModelService,
|
||||
codeEditorService,
|
||||
remotePathService,
|
||||
pathService,
|
||||
workingCopyFileService
|
||||
);
|
||||
}
|
||||
@@ -384,6 +387,7 @@ export class TestLayoutService implements IWorkbenchLayoutService {
|
||||
|
||||
isRestored(): boolean { return true; }
|
||||
hasFocus(_part: Parts): boolean { return false; }
|
||||
focusPart(_part: Parts): void { }
|
||||
hasWindowBorder(): boolean { return false; }
|
||||
getWindowBorderRadius(): string | undefined { return undefined; }
|
||||
isVisible(_part: Parts): boolean { return true; }
|
||||
@@ -627,9 +631,12 @@ export class TestEditorService implements EditorServiceImpl {
|
||||
count = this.editors.length;
|
||||
|
||||
constructor(private editorGroupService?: IEditorGroupsService) { }
|
||||
|
||||
getEditors() { return []; }
|
||||
getEditorOverrides(editorInput: IEditorInput, options: IEditorOptions | undefined, group: IEditorGroup | undefined): [IOpenEditorOverrideHandler, IOpenEditorOverrideEntry][] { return []; }
|
||||
overrideOpenEditor(_handler: IOpenEditorOverrideHandler): IDisposable { return toDisposable(() => undefined); }
|
||||
registerCustomEditorViewTypesHandler(source: string, handler: ICustomEditorViewTypesHandler): IDisposable {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined>;
|
||||
openEditor(editor: IResourceEditorInput | IUntitledTextResourceEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextEditorPane | undefined>;
|
||||
openEditor(editor: IResourceDiffEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextDiffEditorPane | undefined>;
|
||||
@@ -1033,7 +1040,7 @@ export class TestFileEditorInput extends EditorInput implements IFileEditorInput
|
||||
|
||||
getTypeId() { return this.typeId; }
|
||||
resolve(): Promise<IEditorModel | null> { return !this.fails ? Promise.resolve(null) : Promise.reject(new Error('fails')); }
|
||||
matches(other: TestEditorInput): boolean { return other && other.resource && this.resource.toString() === other.resource.toString() && other instanceof TestFileEditorInput && other.getTypeId() === this.typeId; }
|
||||
matches(other: EditorInput): boolean { return !!(other?.resource && this.resource.toString() === other.resource.toString() && other instanceof TestFileEditorInput && other.getTypeId() === this.typeId); }
|
||||
setEncoding(encoding: string) { }
|
||||
getEncoding() { return undefined; }
|
||||
setPreferredEncoding(encoding: string) { }
|
||||
@@ -1101,16 +1108,16 @@ export class TestListService implements IListService {
|
||||
}
|
||||
}
|
||||
|
||||
export class TestRemotePathService implements IRemotePathService {
|
||||
export class TestPathService implements IPathService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
constructor(@IWorkbenchEnvironmentService private readonly environmentService: IEnvironmentService) { }
|
||||
constructor(private readonly fallbackUserHome: URI = URI.from({ scheme: Schemas.vscodeRemote, path: '/' })) { }
|
||||
|
||||
get path() { return Promise.resolve(isWindows ? win32 : posix); }
|
||||
|
||||
get userHome() { return Promise.resolve(this.environmentService.userHome!); }
|
||||
get userHomeSync() { return this.environmentService.userHome; }
|
||||
get userHome() { return Promise.resolve(this.fallbackUserHome); }
|
||||
get resolvedUserHome() { return this.fallbackUserHome; }
|
||||
|
||||
async fileURI(path: string): Promise<URI> {
|
||||
return URI.file(path);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { workbenchInstantiationService as browserWorkbenchInstantiationService, ITestInstantiationService, TestLifecycleService, TestFilesConfigurationService, TestFileService, TestFileDialogService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { workbenchInstantiationService as browserWorkbenchInstantiationService, ITestInstantiationService, TestLifecycleService, TestFilesConfigurationService, TestFileService, TestFileDialogService, TestPathService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { ISharedProcessService } from 'vs/platform/ipc/electron-browser/sharedProcessService';
|
||||
import { NativeWorkbenchEnvironmentService, INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-browser/environmentService';
|
||||
@@ -28,7 +28,7 @@ import { createTextBufferFactoryFromStream } from 'vs/editor/common/model/textMo
|
||||
import { IOpenEmptyWindowOptions, IWindowOpenable, IOpenWindowOptions } from 'vs/platform/windows/common/windows';
|
||||
import { parseArgs, OPTIONS } from 'vs/platform/environment/node/argv';
|
||||
import { LogLevel, ILogService } from 'vs/platform/log/common/log';
|
||||
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
|
||||
import { IPathService } from 'vs/workbench/services/path/common/pathService';
|
||||
import { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService';
|
||||
import { UTF16le, UTF16be, UTF8_with_bom } from 'vs/base/node/encoding';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
@@ -73,7 +73,7 @@ export class TestTextFileService extends NativeTextFileService {
|
||||
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
|
||||
@ITextModelService textModelService: ITextModelService,
|
||||
@ICodeEditorService codeEditorService: ICodeEditorService,
|
||||
@IRemotePathService remotePathService: IRemotePathService,
|
||||
@IPathService athService: IPathService,
|
||||
@IWorkingCopyFileService workingCopyFileService: IWorkingCopyFileService,
|
||||
@ILogService logService: ILogService
|
||||
) {
|
||||
@@ -91,7 +91,7 @@ export class TestTextFileService extends NativeTextFileService {
|
||||
filesConfigurationService,
|
||||
textModelService,
|
||||
codeEditorService,
|
||||
remotePathService,
|
||||
athService,
|
||||
workingCopyFileService,
|
||||
logService
|
||||
);
|
||||
@@ -219,7 +219,8 @@ export class TestElectronService implements IElectronService {
|
||||
|
||||
export function workbenchInstantiationService(): ITestInstantiationService {
|
||||
const instantiationService = browserWorkbenchInstantiationService({
|
||||
textFileService: insta => <ITextFileService>insta.createInstance(TestTextFileService)
|
||||
textFileService: insta => <ITextFileService>insta.createInstance(TestTextFileService),
|
||||
pathService: insta => <IPathService>insta.createInstance(TestNativePathService)
|
||||
});
|
||||
|
||||
instantiationService.stub(IElectronService, new TestElectronService());
|
||||
@@ -243,3 +244,12 @@ export class TestServiceAccessor {
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
export class TestNativePathService extends TestPathService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
constructor(@IWorkbenchEnvironmentService environmentService: INativeWorkbenchEnvironmentService) {
|
||||
super(environmentService.userHome);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user