提交 e9ae0082 编写于 作者: S Sandeep Somavarapu

use in-mem fsp in tests

上级 3f3e35bf
......@@ -393,7 +393,7 @@ class DesktopMain extends Disposable {
}
private async createWorkspaceService(payload: IWorkspaceInitializationPayload, fileService: FileService, remoteAgentService: IRemoteAgentService, uriIdentityService: IUriIdentityService, logService: ILogService): Promise<WorkspaceService> {
const workspaceService = new WorkspaceService({ remoteAuthority: this.environmentService.remoteAuthority, configurationCache: new ConfigurationCache(this.environmentService) }, this.environmentService, fileService, remoteAgentService, uriIdentityService, logService);
const workspaceService = new WorkspaceService({ remoteAuthority: this.environmentService.remoteAuthority, configurationCache: new ConfigurationCache(this.environmentService, fileService) }, this.environmentService, fileService, remoteAgentService, uriIdentityService, logService);
try {
await workspaceService.initialize(payload);
......
......@@ -3,18 +3,20 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as pfs from 'vs/base/node/pfs';
import { join } from 'vs/base/common/path';
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService';
import { IConfigurationCache, ConfigurationKey } from 'vs/workbench/services/configuration/common/configuration';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
import { IFileService } from 'vs/platform/files/common/files';
import { joinPath } from 'vs/base/common/resources';
import { VSBuffer } from 'vs/base/common/buffer';
export class ConfigurationCache implements IConfigurationCache {
private readonly cachedConfigurations: Map<string, CachedConfiguration> = new Map<string, CachedConfiguration>();
constructor(private readonly environmentService: INativeWorkbenchEnvironmentService) {
constructor(private readonly environmentService: INativeWorkbenchEnvironmentService, private readonly fileService: IFileService) {
}
needsCaching(resource: URI): boolean {
......@@ -38,7 +40,7 @@ export class ConfigurationCache implements IConfigurationCache {
const k = `${type}:${key}`;
let cachedConfiguration = this.cachedConfigurations.get(k);
if (!cachedConfiguration) {
cachedConfiguration = new CachedConfiguration({ type, key }, this.environmentService);
cachedConfiguration = new CachedConfiguration({ type, key }, this.environmentService, this.fileService);
this.cachedConfigurations.set(k, cachedConfiguration);
}
return cachedConfiguration;
......@@ -49,21 +51,22 @@ export class ConfigurationCache implements IConfigurationCache {
class CachedConfiguration {
private cachedConfigurationFolderPath: string;
private cachedConfigurationFilePath: string;
private cachedConfigurationFolderResource: URI;
private cachedConfigurationFileResource: URI;
constructor(
{ type, key }: ConfigurationKey,
environmentService: INativeWorkbenchEnvironmentService
environmentService: INativeWorkbenchEnvironmentService,
private readonly fileService: IFileService
) {
this.cachedConfigurationFolderPath = join(environmentService.userDataPath, 'CachedConfigurations', type, key);
this.cachedConfigurationFilePath = join(this.cachedConfigurationFolderPath, type === 'workspaces' ? 'workspace.json' : 'configuration.json');
this.cachedConfigurationFolderResource = URI.file(join(environmentService.userDataPath, 'CachedConfigurations', type, key));
this.cachedConfigurationFileResource = joinPath(this.cachedConfigurationFolderResource, type === 'workspaces' ? 'workspace.json' : 'configuration.json');
}
async read(): Promise<string> {
try {
const content = await pfs.readFile(this.cachedConfigurationFilePath);
return content.toString();
const content = await this.fileService.readFile(this.cachedConfigurationFileResource);
return content.value.toString();
} catch (e) {
return '';
}
......@@ -72,18 +75,24 @@ class CachedConfiguration {
async save(content: string): Promise<void> {
const created = await this.createCachedFolder();
if (created) {
await pfs.writeFile(this.cachedConfigurationFilePath, content);
await this.fileService.writeFile(this.cachedConfigurationFileResource, VSBuffer.fromString(content));
}
}
remove(): Promise<void> {
return pfs.rimraf(this.cachedConfigurationFolderPath);
return this.fileService.del(this.cachedConfigurationFolderResource, { recursive: true, useTrash: false });
}
private createCachedFolder(): Promise<boolean> {
return Promise.resolve(pfs.exists(this.cachedConfigurationFolderPath))
.then(undefined, () => false)
.then(exists => exists ? exists : pfs.mkdirp(this.cachedConfigurationFolderPath).then(() => true, () => false));
private async createCachedFolder(): Promise<boolean> {
if (await this.fileService.exists(this.cachedConfigurationFolderResource)) {
return true;
}
try {
await this.fileService.createFolder(this.cachedConfigurationFolderResource);
return true;
} catch (error) {
return false;
}
}
}
......@@ -119,7 +119,7 @@ flakySuite('WorkspaceContextService - Folder', () => {
const diskFileSystemProvider = disposables.add(new DiskFileSystemProvider(new NullLogService()));
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
fileService.registerProvider(Schemas.userData, disposables.add(new FileUserDataProvider(Schemas.file, new DiskFileSystemProvider(new NullLogService()), Schemas.userData, new NullLogService())));
workspaceContextService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService) }, environmentService, fileService, new RemoteAgentService(environmentService, { _serviceBrand: undefined, ...product }, new RemoteAuthorityResolverService(), new SignService(undefined), new NullLogService()), new UriIdentityService(fileService), new NullLogService()));
workspaceContextService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService, fileService) }, environmentService, fileService, new RemoteAgentService(environmentService, { _serviceBrand: undefined, ...product }, new RemoteAuthorityResolverService(), new SignService(undefined), new NullLogService()), new UriIdentityService(fileService), new NullLogService()));
return (<WorkspaceService>workspaceContextService).initialize(convertToWorkspacePayload(URI.file(folderDir)));
});
});
......@@ -184,7 +184,7 @@ flakySuite('WorkspaceContextService - Workspace', () => {
const diskFileSystemProvider = disposables.add(new DiskFileSystemProvider(new NullLogService()));
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
fileService.registerProvider(Schemas.userData, disposables.add(new FileUserDataProvider(Schemas.file, diskFileSystemProvider, Schemas.userData, new NullLogService())));
const workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService) }, environmentService, fileService, remoteAgentService, new UriIdentityService(fileService), new NullLogService()));
const workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService, fileService) }, environmentService, fileService, remoteAgentService, new UriIdentityService(fileService), new NullLogService()));
instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
......@@ -243,7 +243,7 @@ flakySuite('WorkspaceContextService - Workspace Editing', () => {
const diskFileSystemProvider = disposables.add(new DiskFileSystemProvider(new NullLogService()));
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
fileService.registerProvider(Schemas.userData, disposables.add(new FileUserDataProvider(Schemas.file, diskFileSystemProvider, Schemas.userData, new NullLogService())));
const workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService) }, environmentService, fileService, remoteAgentService, new UriIdentityService(fileService), new NullLogService()));
const workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService, fileService) }, environmentService, fileService, remoteAgentService, new UriIdentityService(fileService), new NullLogService()));
instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
......@@ -506,7 +506,7 @@ flakySuite('WorkspaceService - Initialization', () => {
const diskFileSystemProvider = disposables.add(new DiskFileSystemProvider(new NullLogService()));
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
fileService.registerProvider(Schemas.userData, disposables.add(new FileUserDataProvider(Schemas.file, diskFileSystemProvider, Schemas.userData, new NullLogService())));
const workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService) }, environmentService, fileService, remoteAgentService, new UriIdentityService(fileService), new NullLogService()));
const workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService, fileService) }, environmentService, fileService, remoteAgentService, new UriIdentityService(fileService), new NullLogService()));
instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
instantiationService.stub(IEnvironmentService, environmentService);
......@@ -781,7 +781,7 @@ flakySuite('WorkspaceConfigurationService - Folder', () => {
const diskFileSystemProvider = disposables.add(new DiskFileSystemProvider(new NullLogService()));
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
fileService.registerProvider(Schemas.userData, disposables.add(new FileUserDataProvider(Schemas.file, diskFileSystemProvider, Schemas.userData, new NullLogService())));
workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService) }, environmentService, fileService, remoteAgentService, new UriIdentityService(fileService), new NullLogService()));
workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService, fileService) }, environmentService, fileService, remoteAgentService, new UriIdentityService(fileService), new NullLogService()));
instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
instantiationService.stub(IEnvironmentService, environmentService);
......@@ -1311,7 +1311,7 @@ flakySuite('WorkspaceConfigurationService-Multiroot', () => {
const diskFileSystemProvider = disposables.add(new DiskFileSystemProvider(new NullLogService()));
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
fileService.registerProvider(Schemas.userData, disposables.add(new FileUserDataProvider(Schemas.file, diskFileSystemProvider, Schemas.userData, new NullLogService())));
const workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService) }, environmentService, fileService, remoteAgentService, new UriIdentityService(fileService), new NullLogService()));
const workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService, fileService) }, environmentService, fileService, remoteAgentService, new UriIdentityService(fileService), new NullLogService()));
instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册