mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-10 10:12:34 -05:00
Merge from vscode 718331d6f3ebd1b571530ab499edb266ddd493d5
This commit is contained in:
137
src/vs/workbench/test/common/workbenchTestServices.ts
Normal file
137
src/vs/workbench/test/common/workbenchTestServices.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { join } from 'vs/base/common/path';
|
||||
import * as resources from 'vs/base/common/resources';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IWorkspaceContextService, IWorkspace as IWorkbenchWorkspace, WorkbenchState, IWorkspaceFolder, IWorkspaceFoldersChangeEvent, Workspace } from 'vs/platform/workspace/common/workspace';
|
||||
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
|
||||
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { ITextResourcePropertiesService } from 'vs/editor/common/services/textResourceConfigurationService';
|
||||
import { isLinux, isMacintosh } from 'vs/base/common/platform';
|
||||
import { InMemoryStorageService, IWillSaveStateEvent } from 'vs/platform/storage/common/storage';
|
||||
import { WorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
|
||||
|
||||
export class TestTextResourcePropertiesService implements ITextResourcePropertiesService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
constructor(
|
||||
@IConfigurationService private readonly configurationService: IConfigurationService,
|
||||
) {
|
||||
}
|
||||
|
||||
getEOL(resource: URI, language?: string): string {
|
||||
const eol = this.configurationService.getValue<string>('files.eol', { overrideIdentifier: language, resource });
|
||||
if (eol && eol !== 'auto') {
|
||||
return eol;
|
||||
}
|
||||
return (isLinux || isMacintosh) ? '\n' : '\r\n';
|
||||
}
|
||||
}
|
||||
|
||||
export class TestContextService implements IWorkspaceContextService {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private workspace: Workspace;
|
||||
private options: any;
|
||||
|
||||
private readonly _onDidChangeWorkspaceName: Emitter<void>;
|
||||
private readonly _onDidChangeWorkspaceFolders: Emitter<IWorkspaceFoldersChangeEvent>;
|
||||
private readonly _onDidChangeWorkbenchState: Emitter<WorkbenchState>;
|
||||
|
||||
constructor(workspace: any = TestWorkspace, options: any = null) {
|
||||
this.workspace = workspace;
|
||||
this.options = options || Object.create(null);
|
||||
this._onDidChangeWorkspaceName = new Emitter<void>();
|
||||
this._onDidChangeWorkspaceFolders = new Emitter<IWorkspaceFoldersChangeEvent>();
|
||||
this._onDidChangeWorkbenchState = new Emitter<WorkbenchState>();
|
||||
}
|
||||
|
||||
get onDidChangeWorkspaceName(): Event<void> {
|
||||
return this._onDidChangeWorkspaceName.event;
|
||||
}
|
||||
|
||||
get onDidChangeWorkspaceFolders(): Event<IWorkspaceFoldersChangeEvent> {
|
||||
return this._onDidChangeWorkspaceFolders.event;
|
||||
}
|
||||
|
||||
get onDidChangeWorkbenchState(): Event<WorkbenchState> {
|
||||
return this._onDidChangeWorkbenchState.event;
|
||||
}
|
||||
|
||||
getFolders(): IWorkspaceFolder[] {
|
||||
return this.workspace ? this.workspace.folders : [];
|
||||
}
|
||||
|
||||
getWorkbenchState(): WorkbenchState {
|
||||
if (this.workspace.configuration) {
|
||||
return WorkbenchState.WORKSPACE;
|
||||
}
|
||||
|
||||
if (this.workspace.folders.length) {
|
||||
return WorkbenchState.FOLDER;
|
||||
}
|
||||
|
||||
return WorkbenchState.EMPTY;
|
||||
}
|
||||
|
||||
getCompleteWorkspace(): Promise<IWorkbenchWorkspace> {
|
||||
return Promise.resolve(this.getWorkspace());
|
||||
}
|
||||
|
||||
getWorkspace(): IWorkbenchWorkspace {
|
||||
return this.workspace;
|
||||
}
|
||||
|
||||
getWorkspaceFolder(resource: URI): IWorkspaceFolder | null {
|
||||
return this.workspace.getFolder(resource);
|
||||
}
|
||||
|
||||
setWorkspace(workspace: any): void {
|
||||
this.workspace = workspace;
|
||||
}
|
||||
|
||||
getOptions() {
|
||||
return this.options;
|
||||
}
|
||||
|
||||
updateOptions() {
|
||||
|
||||
}
|
||||
|
||||
isInsideWorkspace(resource: URI): boolean {
|
||||
if (resource && this.workspace) {
|
||||
return resources.isEqualOrParent(resource, this.workspace.folders[0].uri);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
toResource(workspaceRelativePath: string): URI {
|
||||
return URI.file(join('C:\\', workspaceRelativePath));
|
||||
}
|
||||
|
||||
isCurrentWorkspace(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): boolean {
|
||||
return isSingleFolderWorkspaceIdentifier(workspaceIdentifier) && resources.isEqual(this.workspace.folders[0].uri, workspaceIdentifier);
|
||||
}
|
||||
}
|
||||
|
||||
export class TestStorageService extends InMemoryStorageService {
|
||||
readonly _onWillSaveState = this._register(new Emitter<IWillSaveStateEvent>());
|
||||
readonly onWillSaveState = this._onWillSaveState.event;
|
||||
}
|
||||
|
||||
export class TestWorkingCopyService extends WorkingCopyService { }
|
||||
|
||||
export function mock<T>(): Ctor<T> {
|
||||
return function () { } as any;
|
||||
}
|
||||
|
||||
export interface Ctor<T> {
|
||||
new(): T;
|
||||
}
|
||||
Reference in New Issue
Block a user