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

Fix #106934

上级 86ed8976
......@@ -19,7 +19,6 @@ import { WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/w
import { ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
import { join } from 'vs/base/common/path';
import { equals } from 'vs/base/common/objects';
import { Schemas } from 'vs/base/common/network';
import { IConfigurationModel } from 'vs/platform/configuration/common/configuration';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { hash } from 'vs/base/common/hash';
......@@ -405,7 +404,7 @@ export class WorkspaceConfiguration extends Disposable {
private _initialized: boolean = false;
get initialized(): boolean { return this._initialized; }
constructor(
configurationCache: IConfigurationCache,
private readonly configurationCache: IConfigurationCache,
fileService: IFileService
) {
super();
......@@ -413,18 +412,17 @@ export class WorkspaceConfiguration extends Disposable {
this._workspaceConfiguration = this._cachedConfiguration = new CachedWorkspaceConfiguration(configurationCache);
}
async initialize(workspaceIdentifier: IWorkspaceIdentifier): Promise<boolean> {
async initialize(workspaceIdentifier: IWorkspaceIdentifier): Promise<void> {
this._workspaceIdentifier = workspaceIdentifier;
if (!(this._workspaceConfiguration instanceof FileServiceBasedWorkspaceConfiguration)) {
if (this._workspaceIdentifier.configPath.scheme === Schemas.file) {
this.switch(new FileServiceBasedWorkspaceConfiguration(this._fileService));
if (!this._initialized) {
if (this.configurationCache.needsCaching(this._workspaceIdentifier.configPath)) {
this._workspaceConfiguration = this._cachedConfiguration;
this.waitAndInitialize(this._workspaceIdentifier);
} else {
this.waitAndSwitch(this._workspaceIdentifier);
this.doInitialize(new FileServiceBasedWorkspaceConfiguration(this._fileService));
}
}
this._initialized = this._workspaceConfiguration instanceof FileServiceBasedWorkspaceConfiguration;
await this.reload();
return this.initialized;
}
async reload(): Promise<void> {
......@@ -454,22 +452,22 @@ export class WorkspaceConfiguration extends Disposable {
return this.getConfiguration();
}
private async waitAndSwitch(workspaceIdentifier: IWorkspaceIdentifier): Promise<void> {
private async waitAndInitialize(workspaceIdentifier: IWorkspaceIdentifier): Promise<void> {
await whenProviderRegistered(workspaceIdentifier.configPath, this._fileService);
if (!(this._workspaceConfiguration instanceof FileServiceBasedWorkspaceConfiguration)) {
const fileServiceBasedWorkspaceConfiguration = this._register(new FileServiceBasedWorkspaceConfiguration(this._fileService));
await fileServiceBasedWorkspaceConfiguration.load(workspaceIdentifier);
this.switch(fileServiceBasedWorkspaceConfiguration);
this._initialized = true;
this.doInitialize(fileServiceBasedWorkspaceConfiguration);
this.onDidWorkspaceConfigurationChange(false);
}
}
private switch(fileServiceBasedWorkspaceConfiguration: FileServiceBasedWorkspaceConfiguration): void {
private doInitialize(fileServiceBasedWorkspaceConfiguration: FileServiceBasedWorkspaceConfiguration): void {
this._workspaceConfiguration.dispose();
this._workspaceConfigurationChangeDisposable.dispose();
this._workspaceConfiguration = this._register(fileServiceBasedWorkspaceConfiguration);
this._workspaceConfigurationChangeDisposable = this._register(this._workspaceConfiguration.onDidChange(e => this.onDidWorkspaceConfigurationChange(true)));
this._initialized = true;
}
private async onDidWorkspaceConfigurationChange(reload: boolean): Promise<void> {
......@@ -481,7 +479,7 @@ export class WorkspaceConfiguration extends Disposable {
}
private updateCache(): Promise<void> {
if (this._workspaceIdentifier && this._workspaceIdentifier.configPath.scheme !== Schemas.file && this._workspaceConfiguration instanceof FileServiceBasedWorkspaceConfiguration) {
if (this._workspaceIdentifier && this.configurationCache.needsCaching(this._workspaceIdentifier.configPath) && this._workspaceConfiguration instanceof FileServiceBasedWorkspaceConfiguration) {
return this._workspaceConfiguration.load(this._workspaceIdentifier)
.then(() => this._cachedConfiguration.updateWorkspace(this._workspaceIdentifier!, this._workspaceConfiguration.getConfigurationModel()));
}
......@@ -722,16 +720,14 @@ export class FolderConfiguration extends Disposable implements IFolderConfigurat
configFolderRelativePath: string,
private readonly workbenchState: WorkbenchState,
fileService: IFileService,
configurationCache: IConfigurationCache
private readonly configurationCache: IConfigurationCache
) {
super();
this.configurationFolder = resources.joinPath(workspaceFolder.uri, configFolderRelativePath);
this.folderConfiguration = this.cachedFolderConfiguration = new CachedFolderConfiguration(workspaceFolder.uri, configFolderRelativePath, configurationCache);
if (workspaceFolder.uri.scheme === Schemas.file) {
this.folderConfiguration = this.createFileServiceBasedConfiguration(fileService);
this.folderConfigurationDisposable = this._register(this.folderConfiguration.onDidChange(e => this.onDidFolderConfigurationChange()));
} else {
this.cachedFolderConfiguration = new CachedFolderConfiguration(workspaceFolder.uri, configFolderRelativePath, configurationCache);
if (this.configurationCache.needsCaching(workspaceFolder.uri)) {
this.folderConfiguration = this.cachedFolderConfiguration;
whenProviderRegistered(workspaceFolder.uri, fileService)
.then(() => {
this.folderConfiguration.dispose();
......@@ -740,6 +736,9 @@ export class FolderConfiguration extends Disposable implements IFolderConfigurat
this._register(this.folderConfiguration.onDidChange(e => this.onDidFolderConfigurationChange()));
this.onDidFolderConfigurationChange();
});
} else {
this.folderConfiguration = this.createFileServiceBasedConfiguration(fileService);
this.folderConfigurationDisposable = this._register(this.folderConfiguration.onDidChange(e => this.onDidFolderConfigurationChange()));
}
}
......@@ -763,7 +762,7 @@ export class FolderConfiguration extends Disposable implements IFolderConfigurat
}
private updateCache(): Promise<void> {
if (this.configurationFolder.scheme !== Schemas.file && this.folderConfiguration instanceof FileServiceBasedConfiguration) {
if (this.configurationCache.needsCaching(this.configurationFolder) && this.folderConfiguration instanceof FileServiceBasedConfiguration) {
return this.folderConfiguration.loadConfiguration()
.then(configurationModel => this.cachedFolderConfiguration.updateConfiguration(configurationModel));
}
......
......@@ -4,9 +4,16 @@
*--------------------------------------------------------------------------------------------*/
import { IConfigurationCache, ConfigurationKey } from 'vs/workbench/services/configuration/common/configuration';
import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
export class ConfigurationCache implements IConfigurationCache {
needsCaching(resource: URI): boolean {
// Cache all non user data resources
return resource.scheme !== Schemas.userData;
}
async read(key: ConfigurationKey): Promise<string> {
return '';
}
......
......@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
import { URI } from 'vs/base/common/uri';
export const FOLDER_CONFIG_FOLDER_NAME = '.vscode';
export const FOLDER_SETTINGS_NAME = 'settings';
......@@ -35,6 +36,7 @@ export type ConfigurationKey = { type: 'user' | 'workspaces' | 'folder', key: st
export interface IConfigurationCache {
needsCaching(resource: URI): boolean;
read(key: ConfigurationKey): Promise<string>;
write(key: ConfigurationKey, content: string): Promise<void>;
remove(key: ConfigurationKey): Promise<void>;
......
......@@ -7,6 +7,8 @@ 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';
export class ConfigurationCache implements IConfigurationCache {
......@@ -15,6 +17,11 @@ export class ConfigurationCache implements IConfigurationCache {
constructor(private readonly environmentService: INativeWorkbenchEnvironmentService) {
}
needsCaching(resource: URI): boolean {
// Cache all non native resources
return ![Schemas.file, Schemas.userData].includes(resource.scheme);
}
read(key: ConfigurationKey): Promise<string> {
return this.getCachedConfiguration(key).read();
}
......
......@@ -1891,7 +1891,7 @@ suite('WorkspaceConfigurationService - Remote Folder', () => {
const fileService = new FileService(new NullLogService());
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
fileService.registerProvider(Schemas.userData, new FileUserDataProvider(environmentService.appSettingsHome, undefined, diskFileSystemProvider, environmentService, new NullLogService()));
const configurationCache: IConfigurationCache = { read: () => Promise.resolve(''), write: () => Promise.resolve(), remove: () => Promise.resolve() };
const configurationCache: IConfigurationCache = { read: () => Promise.resolve(''), write: () => Promise.resolve(), remove: () => Promise.resolve(), needsCaching: () => false };
testObject = new WorkspaceService({ configurationCache, remoteAuthority }, environmentService, fileService, remoteAgentService, new NullLogService());
instantiationService.stub(IWorkspaceContextService, testObject);
instantiationService.stub(IConfigurationService, testObject);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册