mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode 1b314ab317fbff7d799b21754326b7d849889ceb
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { ExtHostTreeViewsShape, IExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { mock } from 'vs/base/test/common/mock';
|
||||
import { ITreeItem, IViewsRegistry, Extensions, ViewContainerLocation, IViewContainersRegistry, ITreeViewDescriptor, ITreeView, ViewContainer, IViewDescriptorService, TreeItemCollapsibleState } from 'vs/workbench/common/views';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
import { MainThreadTreeViews } from 'vs/workbench/api/browser/mainThreadTreeViews';
|
||||
import { TestViewsService, workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { TestExtensionService } from 'vs/workbench/test/common/workbenchTestServices';
|
||||
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
import { CustomTreeView } from 'vs/workbench/contrib/views/browser/treeView';
|
||||
import { ViewDescriptorService } from 'vs/workbench/services/views/browser/viewDescriptorService';
|
||||
|
||||
suite('MainThreadHostTreeView', function () {
|
||||
const testTreeViewId = 'testTreeView';
|
||||
const customValue = 'customValue';
|
||||
const ViewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
|
||||
|
||||
interface CustomTreeItem extends ITreeItem {
|
||||
customProp: string;
|
||||
}
|
||||
|
||||
class MockExtHostTreeViewsShape extends mock<ExtHostTreeViewsShape>() {
|
||||
async $getChildren(treeViewId: string, treeItemHandle?: string): Promise<ITreeItem[]> {
|
||||
return [<CustomTreeItem>{ handle: 'testItem1', collapsibleState: TreeItemCollapsibleState.Expanded, customProp: customValue }];
|
||||
}
|
||||
|
||||
async $hasResolve(): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
|
||||
$setVisible(): void { }
|
||||
}
|
||||
|
||||
let container: ViewContainer;
|
||||
let mainThreadTreeViews: MainThreadTreeViews;
|
||||
let extHostTreeViewsShape: MockExtHostTreeViewsShape;
|
||||
|
||||
setup(async () => {
|
||||
const instantiationService: TestInstantiationService = <TestInstantiationService>workbenchInstantiationService();
|
||||
const viewDescriptorService = instantiationService.createInstance(ViewDescriptorService);
|
||||
instantiationService.stub(IViewDescriptorService, viewDescriptorService);
|
||||
container = Registry.as<IViewContainersRegistry>(Extensions.ViewContainersRegistry).registerViewContainer({ id: 'testContainer', name: 'test', ctorDescriptor: new SyncDescriptor(<any>{}) }, ViewContainerLocation.Sidebar);
|
||||
const viewDescriptor: ITreeViewDescriptor = {
|
||||
id: testTreeViewId,
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1',
|
||||
treeView: instantiationService.createInstance(CustomTreeView, 'testTree', 'Test Title'),
|
||||
};
|
||||
ViewsRegistry.registerViews([viewDescriptor], container);
|
||||
|
||||
const testExtensionService = new TestExtensionService();
|
||||
extHostTreeViewsShape = new MockExtHostTreeViewsShape();
|
||||
mainThreadTreeViews = new MainThreadTreeViews(
|
||||
new class implements IExtHostContext {
|
||||
remoteAuthority = '';
|
||||
assertRegistered() { }
|
||||
set(v: any): any { return null; }
|
||||
getProxy(): any {
|
||||
return extHostTreeViewsShape;
|
||||
}
|
||||
}, new TestViewsService(), new TestNotificationService(), testExtensionService, new NullLogService());
|
||||
mainThreadTreeViews.$registerTreeViewDataProvider(testTreeViewId, { showCollapseAll: false, canSelectMany: false });
|
||||
await testExtensionService.whenInstalledExtensionsRegistered();
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
ViewsRegistry.deregisterViews(ViewsRegistry.getViews(container), container);
|
||||
});
|
||||
|
||||
test('getChildren keeps custom properties', async () => {
|
||||
const treeView: ITreeView = (<ITreeViewDescriptor>ViewsRegistry.getView(testTreeViewId)).treeView;
|
||||
const children = await treeView.dataProvider?.getChildren({ handle: 'root', collapsibleState: TreeItemCollapsibleState.Expanded });
|
||||
assert(children!.length === 1, 'Exactly one child should be returned');
|
||||
assert((<CustomTreeItem>children![0]).customProp === customValue, 'Tree Items should keep custom properties');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
@@ -251,6 +251,9 @@ suite('Workbench base editor', () => {
|
||||
assert.ok(!memento.loadEditorState(testGroup4, URI.file('/C')));
|
||||
assert.ok(memento.loadEditorState(testGroup0, URI.file('/D')));
|
||||
assert.ok(!memento.loadEditorState(testGroup0, URI.file('/E')));
|
||||
|
||||
// Use fallbackToOtherGroupState
|
||||
assert.ok(memento.loadEditorState(testGroup4, URI.file('/C'), true));
|
||||
});
|
||||
|
||||
test('EditorMemento - move', function () {
|
||||
|
||||
@@ -32,7 +32,7 @@ suite('Breadcrumb Model', function () {
|
||||
|
||||
test('only uri, inside workspace', function () {
|
||||
|
||||
let model = new EditorBreadcrumbsModel(URI.parse('foo:/bar/baz/ws/some/path/file.ts'), undefined, configService, configService, workspaceService);
|
||||
let model = new EditorBreadcrumbsModel(URI.parse('foo:/bar/baz/ws/some/path/file.ts'), URI.parse('foo:/bar/baz/ws/some/path/file.ts'), undefined, configService, configService, workspaceService);
|
||||
let elements = model.getElements();
|
||||
|
||||
assert.equal(elements.length, 3);
|
||||
@@ -45,9 +45,24 @@ suite('Breadcrumb Model', function () {
|
||||
assert.equal(three.uri.toString(), 'foo:/bar/baz/ws/some/path/file.ts');
|
||||
});
|
||||
|
||||
test('display uri matters for FileElement', function () {
|
||||
|
||||
let model = new EditorBreadcrumbsModel(URI.parse('foo:/bar/baz/ws/some/PATH/file.ts'), URI.parse('foo:/bar/baz/ws/some/path/file.ts'), undefined, configService, configService, workspaceService);
|
||||
let elements = model.getElements();
|
||||
|
||||
assert.equal(elements.length, 3);
|
||||
let [one, two, three] = elements as FileElement[];
|
||||
assert.equal(one.kind, FileKind.FOLDER);
|
||||
assert.equal(two.kind, FileKind.FOLDER);
|
||||
assert.equal(three.kind, FileKind.FILE);
|
||||
assert.equal(one.uri.toString(), 'foo:/bar/baz/ws/some');
|
||||
assert.equal(two.uri.toString(), 'foo:/bar/baz/ws/some/PATH');
|
||||
assert.equal(three.uri.toString(), 'foo:/bar/baz/ws/some/PATH/file.ts');
|
||||
});
|
||||
|
||||
test('only uri, outside workspace', function () {
|
||||
|
||||
let model = new EditorBreadcrumbsModel(URI.parse('foo:/outside/file.ts'), undefined, configService, configService, workspaceService);
|
||||
let model = new EditorBreadcrumbsModel(URI.parse('foo:/outside/file.ts'), URI.parse('foo:/outside/file.ts'), undefined, configService, configService, workspaceService);
|
||||
let elements = model.getElements();
|
||||
|
||||
assert.equal(elements.length, 2);
|
||||
|
||||
@@ -23,7 +23,7 @@ import { IUntitledTextEditorService, UntitledTextEditorService } from 'vs/workbe
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { ILifecycleService, BeforeShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase, WillShutdownEvent } from 'vs/platform/lifecycle/common/lifecycle';
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { FileOperationEvent, IFileService, IFileStat, IResolveFileResult, FileChangesEvent, IResolveFileOptions, ICreateFileOptions, IFileSystemProvider, FileSystemProviderCapabilities, IFileChange, IWatchOptions, IStat, FileType, FileDeleteOptions, FileOverwriteOptions, FileWriteOptions, FileOpenOptions, IFileStatWithMetadata, IResolveMetadataFileOptions, IWriteFileOptions, IReadFileOptions, IFileContent, IFileStreamContent, FileOperationError } from 'vs/platform/files/common/files';
|
||||
import { FileOperationEvent, IFileService, IFileStat, IResolveFileResult, FileChangesEvent, IResolveFileOptions, ICreateFileOptions, IFileSystemProvider, FileSystemProviderCapabilities, IFileChange, IWatchOptions, IStat, FileType, FileDeleteOptions, FileOverwriteOptions, FileWriteOptions, FileOpenOptions, IFileStatWithMetadata, IResolveMetadataFileOptions, IWriteFileOptions, IReadFileOptions, IFileContent, IFileStreamContent, FileOperationError, IFileSystemProviderWithFileReadStreamCapability } from 'vs/platform/files/common/files';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
|
||||
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
|
||||
@@ -110,6 +110,10 @@ import { IPaneComposite } from 'vs/workbench/common/panecomposite';
|
||||
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
|
||||
import { UriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentityService';
|
||||
import { TextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textFileEditorModelManager';
|
||||
import { InMemoryFileSystemProvider } from 'vs/platform/files/common/inMemoryFilesystemProvider';
|
||||
import { newWriteableStream, ReadableStreamEvents } from 'vs/base/common/stream';
|
||||
import { EncodingOracle, IEncodingOverride } from 'vs/workbench/services/textfile/browser/textFileService';
|
||||
import { UTF16le, UTF16be, UTF8_with_bom } from 'vs/workbench/services/textfile/common/encoding';
|
||||
|
||||
export function createFileEditorInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
|
||||
return instantiationService.createInstance(FileEditorInput, resource, undefined, undefined, undefined);
|
||||
@@ -226,7 +230,8 @@ export class TestTextFileService extends BrowserTextFileService {
|
||||
@ICodeEditorService codeEditorService: ICodeEditorService,
|
||||
@IPathService pathService: IPathService,
|
||||
@IWorkingCopyFileService workingCopyFileService: IWorkingCopyFileService,
|
||||
@IUriIdentityService uriIdentityService: IUriIdentityService
|
||||
@IUriIdentityService uriIdentityService: IUriIdentityService,
|
||||
@IModeService modeService: IModeService
|
||||
) {
|
||||
super(
|
||||
fileService,
|
||||
@@ -243,7 +248,8 @@ export class TestTextFileService extends BrowserTextFileService {
|
||||
codeEditorService,
|
||||
pathService,
|
||||
workingCopyFileService,
|
||||
uriIdentityService
|
||||
uriIdentityService,
|
||||
modeService
|
||||
);
|
||||
}
|
||||
|
||||
@@ -273,6 +279,31 @@ export class TestTextFileService extends BrowserTextFileService {
|
||||
}
|
||||
}
|
||||
|
||||
export class TestBrowserTextFileServiceWithEncodingOverrides extends BrowserTextFileService {
|
||||
|
||||
private _testEncoding: TestEncodingOracle | undefined;
|
||||
get encoding(): TestEncodingOracle {
|
||||
if (!this._testEncoding) {
|
||||
this._testEncoding = this._register(this.instantiationService.createInstance(TestEncodingOracle));
|
||||
}
|
||||
|
||||
return this._testEncoding;
|
||||
}
|
||||
}
|
||||
|
||||
export class TestEncodingOracle extends EncodingOracle {
|
||||
|
||||
protected get encodingOverrides(): IEncodingOverride[] {
|
||||
return [
|
||||
{ extension: 'utf16le', encoding: UTF16le },
|
||||
{ extension: 'utf16be', encoding: UTF16be },
|
||||
{ extension: 'utf8bom', encoding: UTF8_with_bom }
|
||||
];
|
||||
}
|
||||
|
||||
protected set encodingOverrides(overrides: IEncodingOverride[]) { }
|
||||
}
|
||||
|
||||
class TestEnvironmentServiceWithArgs extends BrowserWorkbenchEnvironmentService {
|
||||
args = [];
|
||||
}
|
||||
@@ -495,6 +526,7 @@ export class TestViewsService implements IViewsService {
|
||||
openView<T extends IView>(id: string, focus?: boolean | undefined): Promise<T | null> { return Promise.resolve(null); }
|
||||
closeView(id: string): void { }
|
||||
getViewProgressIndicator(id: string) { return null!; }
|
||||
getActiveViewPaneContainerWithId(id: string) { return null; }
|
||||
}
|
||||
|
||||
export class TestEditorGroupsService implements IEditorGroupsService {
|
||||
@@ -945,6 +977,39 @@ export class RemoteFileSystemProvider implements IFileSystemProvider {
|
||||
private toFileResource(resource: URI): URI { return resource.with({ scheme: Schemas.file, authority: '' }); }
|
||||
}
|
||||
|
||||
export class TestInMemoryFileSystemProvider extends InMemoryFileSystemProvider implements IFileSystemProviderWithFileReadStreamCapability {
|
||||
readonly capabilities: FileSystemProviderCapabilities =
|
||||
FileSystemProviderCapabilities.FileReadWrite
|
||||
| FileSystemProviderCapabilities.PathCaseSensitive
|
||||
| FileSystemProviderCapabilities.FileReadStream;
|
||||
|
||||
|
||||
readFileStream(resource: URI): ReadableStreamEvents<Uint8Array> {
|
||||
const BUFFER_SIZE = 64 * 1024;
|
||||
const stream = newWriteableStream<Uint8Array>(data => VSBuffer.concat(data.map(data => VSBuffer.wrap(data))).buffer);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const data = await this.readFile(resource);
|
||||
|
||||
let offset = 0;
|
||||
while (offset < data.length) {
|
||||
await timeout(0);
|
||||
await stream.write(data.subarray(offset, offset + BUFFER_SIZE));
|
||||
offset += BUFFER_SIZE;
|
||||
}
|
||||
|
||||
await timeout(0);
|
||||
stream.end();
|
||||
} catch (error) {
|
||||
stream.end(error);
|
||||
}
|
||||
})();
|
||||
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
export const productService: IProductService = { _serviceBrand: undefined, ...product };
|
||||
|
||||
export class TestHostService implements IHostService {
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { workbenchInstantiationService as browserWorkbenchInstantiationService, ITestInstantiationService, TestLifecycleService, TestFilesConfigurationService, TestFileService, TestFileDialogService, TestPathService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { workbenchInstantiationService as browserWorkbenchInstantiationService, ITestInstantiationService, TestLifecycleService, TestFilesConfigurationService, TestFileService, TestFileDialogService, TestPathService, TestEncodingOracle } 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';
|
||||
import { NativeTextFileService, } from 'vs/workbench/services/textfile/electron-browser/nativeTextFileService';
|
||||
import { EncodingOracle, IEncodingOverride } from 'vs/workbench/services/textfile/browser/textFileService';
|
||||
import { IElectronService } from 'vs/platform/electron/electron-sandbox/electron';
|
||||
import { FileOperationError, IFileService } from 'vs/platform/files/common/files';
|
||||
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||
@@ -30,7 +29,6 @@ import { parseArgs, OPTIONS } from 'vs/platform/environment/node/argv';
|
||||
import { LogLevel, ILogService } from 'vs/platform/log/common/log';
|
||||
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/workbench/services/textfile/common/encoding';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
|
||||
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
|
||||
@@ -41,6 +39,7 @@ import { INativeWindowConfiguration } from 'vs/platform/windows/node/window';
|
||||
import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices';
|
||||
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
|
||||
import { MouseInputEvent } from 'vs/base/parts/sandbox/common/electronTypes';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
|
||||
export const TestWindowConfiguration: INativeWindowConfiguration = {
|
||||
windowId: 0,
|
||||
@@ -78,7 +77,8 @@ export class TestTextFileService extends NativeTextFileService {
|
||||
@IPathService athService: IPathService,
|
||||
@IWorkingCopyFileService workingCopyFileService: IWorkingCopyFileService,
|
||||
@ILogService logService: ILogService,
|
||||
@IUriIdentityService uriIdentityService: IUriIdentityService
|
||||
@IUriIdentityService uriIdentityService: IUriIdentityService,
|
||||
@IModeService modeService: IModeService
|
||||
) {
|
||||
super(
|
||||
fileService,
|
||||
@@ -97,7 +97,8 @@ export class TestTextFileService extends NativeTextFileService {
|
||||
athService,
|
||||
workingCopyFileService,
|
||||
logService,
|
||||
uriIdentityService
|
||||
uriIdentityService,
|
||||
modeService
|
||||
);
|
||||
}
|
||||
|
||||
@@ -139,19 +140,6 @@ export class TestNativeTextFileServiceWithEncodingOverrides extends NativeTextFi
|
||||
}
|
||||
}
|
||||
|
||||
class TestEncodingOracle extends EncodingOracle {
|
||||
|
||||
protected get encodingOverrides(): IEncodingOverride[] {
|
||||
return [
|
||||
{ extension: 'utf16le', encoding: UTF16le },
|
||||
{ extension: 'utf16be', encoding: UTF16be },
|
||||
{ extension: 'utf8bom', encoding: UTF8_with_bom }
|
||||
];
|
||||
}
|
||||
|
||||
protected set encodingOverrides(overrides: IEncodingOverride[]) { }
|
||||
}
|
||||
|
||||
export class TestSharedProcessService implements ISharedProcessService {
|
||||
|
||||
declare readonly _serviceBrand: undefined;
|
||||
@@ -205,6 +193,7 @@ export class TestElectronService implements IElectronService {
|
||||
async pickWorkspaceAndOpen(options: INativeOpenDialogOptions): Promise<void> { }
|
||||
async showItemInFolder(path: string): Promise<void> { }
|
||||
async setRepresentedFilename(path: string): Promise<void> { }
|
||||
async isAdmin(): Promise<boolean> { return false; }
|
||||
async setDocumentEdited(edited: boolean): Promise<void> { }
|
||||
async openExternal(url: string): Promise<boolean> { return false; }
|
||||
async updateTouchBar(): Promise<void> { }
|
||||
|
||||
Reference in New Issue
Block a user