mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
This reverts commit d15a3fcc98.
This commit is contained in:
@@ -21,8 +21,8 @@ import { extname, join } from 'vs/base/common/path';
|
||||
import { equals } from 'vs/base/common/objects';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { IConfigurationModel, compare } from 'vs/platform/configuration/common/configuration';
|
||||
import { createSHA1 } from 'vs/base/browser/hash';
|
||||
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
|
||||
import { hash } from 'vs/base/common/hash';
|
||||
|
||||
export class RemoteUserConfiguration extends Disposable {
|
||||
|
||||
@@ -672,7 +672,7 @@ class CachedFolderConfiguration extends Disposable implements IFolderConfigurati
|
||||
readonly onDidChange: Event<void> = this._onDidChange.event;
|
||||
|
||||
private configurationModel: ConfigurationModel;
|
||||
private readonly key: ConfigurationKey;
|
||||
private readonly key: Thenable<ConfigurationKey>;
|
||||
|
||||
constructor(
|
||||
folder: URI,
|
||||
@@ -680,13 +680,14 @@ class CachedFolderConfiguration extends Disposable implements IFolderConfigurati
|
||||
private readonly configurationCache: IConfigurationCache
|
||||
) {
|
||||
super();
|
||||
this.key = { type: 'folder', key: hash(join(folder.path, configFolderRelativePath)).toString(16) };
|
||||
this.key = createSHA1(join(folder.path, configFolderRelativePath)).then(key => ({ type: 'folder', key }));
|
||||
this.configurationModel = new ConfigurationModel();
|
||||
}
|
||||
|
||||
async loadConfiguration(): Promise<ConfigurationModel> {
|
||||
try {
|
||||
const contents = await this.configurationCache.read(this.key);
|
||||
const key = await this.key;
|
||||
const contents = await this.configurationCache.read(key);
|
||||
const parsed: IConfigurationModel = JSON.parse(contents.toString());
|
||||
this.configurationModel = new ConfigurationModel(parsed.contents, parsed.keys, parsed.overrides);
|
||||
} catch (e) {
|
||||
@@ -695,10 +696,11 @@ class CachedFolderConfiguration extends Disposable implements IFolderConfigurati
|
||||
}
|
||||
|
||||
async updateConfiguration(configurationModel: ConfigurationModel): Promise<void> {
|
||||
const key = await this.key;
|
||||
if (configurationModel.keys.length) {
|
||||
await this.configurationCache.write(this.key, JSON.stringify(configurationModel.toJSON()));
|
||||
await this.configurationCache.write(key, JSON.stringify(configurationModel.toJSON()));
|
||||
} else {
|
||||
await this.configurationCache.remove(this.key);
|
||||
await this.configurationCache.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +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 { IConfigurationCache, ConfigurationKey } from 'vs/workbench/services/configuration/common/configuration';
|
||||
|
||||
export class ConfigurationCache implements IConfigurationCache {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
async read(key: ConfigurationKey): Promise<string> {
|
||||
return '';
|
||||
}
|
||||
|
||||
async write(key: ConfigurationKey, content: string): Promise<void> {
|
||||
}
|
||||
|
||||
async remove(key: ConfigurationKey): Promise<void> {
|
||||
}
|
||||
}
|
||||
@@ -528,7 +528,7 @@ export class ConfigurationEditingService {
|
||||
|
||||
private getConfigurationFileResource(target: EditableConfigurationTarget, config: IConfigurationValue, relativePath: string, resource: URI | null | undefined): URI | null {
|
||||
if (target === EditableConfigurationTarget.USER_LOCAL) {
|
||||
return this.environmentService.settingsResource;
|
||||
return URI.file(this.environmentService.appSettingsPath);
|
||||
}
|
||||
if (target === EditableConfigurationTarget.USER_REMOTE) {
|
||||
return this.remoteSettingsResource;
|
||||
|
||||
@@ -39,11 +39,10 @@ export class JSONEditingService implements IJSONEditingService {
|
||||
return Promise.resolve(this.queue.queue(() => this.doWriteConfiguration(resource, value, save))); // queue up writes to prevent race conditions
|
||||
}
|
||||
|
||||
private async doWriteConfiguration(resource: URI, value: IJSONValue, save: boolean): Promise<void> {
|
||||
const reference = await this.resolveAndValidate(resource, save);
|
||||
await this.writeToBuffer(reference.object.textEditorModel, value);
|
||||
|
||||
reference.dispose();
|
||||
private doWriteConfiguration(resource: URI, value: IJSONValue, save: boolean): Promise<void> {
|
||||
return this.resolveAndValidate(resource, save)
|
||||
.then(reference => this.writeToBuffer(reference.object.textEditorModel, value)
|
||||
.then(() => reference.dispose()));
|
||||
}
|
||||
|
||||
private async writeToBuffer(model: ITextModel, value: IJSONValue): Promise<any> {
|
||||
@@ -98,21 +97,21 @@ export class JSONEditingService implements IJSONEditingService {
|
||||
return parseErrors.length > 0;
|
||||
}
|
||||
|
||||
private async resolveAndValidate(resource: URI, checkDirty: boolean): Promise<IReference<IResolvedTextEditorModel>> {
|
||||
const reference = await this.resolveModelReference(resource);
|
||||
private resolveAndValidate(resource: URI, checkDirty: boolean): Promise<IReference<IResolvedTextEditorModel>> {
|
||||
return this.resolveModelReference(resource)
|
||||
.then(reference => {
|
||||
const model = reference.object.textEditorModel;
|
||||
|
||||
const model = reference.object.textEditorModel;
|
||||
if (this.hasParseErrors(model)) {
|
||||
return this.reject<IReference<IResolvedTextEditorModel>>(JSONEditingErrorCode.ERROR_INVALID_FILE);
|
||||
}
|
||||
|
||||
if (this.hasParseErrors(model)) {
|
||||
return this.reject<IReference<IResolvedTextEditorModel>>(JSONEditingErrorCode.ERROR_INVALID_FILE);
|
||||
}
|
||||
|
||||
// Target cannot be dirty if not writing into buffer
|
||||
if (checkDirty && this.textFileService.isDirty(resource)) {
|
||||
return this.reject<IReference<IResolvedTextEditorModel>>(JSONEditingErrorCode.ERROR_FILE_DIRTY);
|
||||
}
|
||||
|
||||
return reference;
|
||||
// Target cannot be dirty if not writing into buffer
|
||||
if (checkDirty && this.textFileService.isDirty(resource)) {
|
||||
return this.reject<IReference<IResolvedTextEditorModel>>(JSONEditingErrorCode.ERROR_FILE_DIRTY);
|
||||
}
|
||||
return reference;
|
||||
});
|
||||
}
|
||||
|
||||
private reject<T>(code: JSONEditingErrorCode): Promise<T> {
|
||||
|
||||
@@ -47,7 +47,7 @@ class SettingsTestEnvironmentService extends EnvironmentService {
|
||||
super(args, _execPath);
|
||||
}
|
||||
|
||||
get settingsResource(): URI { return URI.file(this.customAppSettingsHome); }
|
||||
get appSettingsPath(): string { return this.customAppSettingsHome; }
|
||||
}
|
||||
|
||||
suite('ConfigurationEditingService', () => {
|
||||
@@ -106,7 +106,7 @@ suite('ConfigurationEditingService', () => {
|
||||
instantiationService.stub(IEnvironmentService, environmentService);
|
||||
const remoteAgentService = instantiationService.createInstance(RemoteAgentService, {});
|
||||
instantiationService.stub(IRemoteAgentService, remoteAgentService);
|
||||
const workspaceService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), remoteAgentService);
|
||||
const workspaceService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), remoteAgentService);
|
||||
instantiationService.stub(IWorkspaceContextService, workspaceService);
|
||||
return workspaceService.initialize(noWorkspace ? { id: '' } : { folder: URI.file(workspaceDir), id: createHash('md5').update(URI.file(workspaceDir).toString()).digest('hex') }).then(() => {
|
||||
instantiationService.stub(IConfigurationService, workspaceService);
|
||||
@@ -187,7 +187,7 @@ suite('ConfigurationEditingService', () => {
|
||||
test('do not notify error', () => {
|
||||
instantiationService.stub(ITextFileService, 'isDirty', true);
|
||||
const target = sinon.stub();
|
||||
instantiationService.stub(INotificationService, <INotificationService>{ prompt: target, _serviceBrand: null!, notify: null!, error: null!, info: null!, warn: null!, status: null! });
|
||||
instantiationService.stub(INotificationService, <INotificationService>{ prompt: target, _serviceBrand: null, notify: null!, error: null!, info: null!, warn: null! });
|
||||
return testObject.writeConfiguration(EditableConfigurationTarget.USER_LOCAL, { key: 'configurationEditing.service.testSetting', value: 'value' }, { donotNotifyError: true })
|
||||
.then(() => assert.fail('Should fail with ERROR_CONFIGURATION_FILE_DIRTY error.'),
|
||||
(error: ConfigurationEditingError) => {
|
||||
|
||||
@@ -44,7 +44,6 @@ import { ConfigurationCache } from 'vs/workbench/services/configuration/node/con
|
||||
import { ConfigurationFileService } from 'vs/workbench/services/configuration/node/configurationFileService';
|
||||
import { IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment';
|
||||
import { IConfigurationCache } from 'vs/workbench/services/configuration/common/configuration';
|
||||
import { VSBuffer } from 'vs/base/common/buffer';
|
||||
|
||||
class SettingsTestEnvironmentService extends EnvironmentService {
|
||||
|
||||
@@ -52,7 +51,7 @@ class SettingsTestEnvironmentService extends EnvironmentService {
|
||||
super(args, _execPath);
|
||||
}
|
||||
|
||||
get settingsResource(): URI { return URI.file(this.customAppSettingsHome); }
|
||||
get appSettingsPath(): string { return this.customAppSettingsHome; }
|
||||
}
|
||||
|
||||
function setUpFolderWorkspace(folderName: string): Promise<{ parentDir: string, folderDir: string }> {
|
||||
@@ -154,7 +153,7 @@ suite('WorkspaceConfigurationService - Remote Folder', () => {
|
||||
const configurationFileService = new ConfigurationFileService();
|
||||
configurationFileService.fileService = fileService;
|
||||
const configurationCache: IConfigurationCache = { read: () => Promise.resolve(''), write: () => Promise.resolve(), remove: () => Promise.resolve() };
|
||||
testObject = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache, remoteAuthority }, configurationFileService, remoteAgentService);
|
||||
testObject = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache, remoteAuthority }, configurationFileService, remoteAgentService);
|
||||
instantiationService.stub(IWorkspaceContextService, testObject);
|
||||
instantiationService.stub(IConfigurationService, testObject);
|
||||
instantiationService.stub(IEnvironmentService, environmentService);
|
||||
@@ -248,26 +247,26 @@ suite('WorkspaceConfigurationService - Remote Folder', () => {
|
||||
return promise;
|
||||
});
|
||||
|
||||
test('update remote settings', async () => {
|
||||
registerRemoteFileSystemProvider();
|
||||
resolveRemoteEnvironment();
|
||||
await initialize();
|
||||
assert.equal(testObject.getValue('configurationService.remote.machineSetting'), 'isSet');
|
||||
const promise = new Promise((c, e) => {
|
||||
testObject.onDidChangeConfiguration(event => {
|
||||
try {
|
||||
assert.equal(event.source, ConfigurationTarget.USER);
|
||||
assert.deepEqual(event.affectedKeys, ['configurationService.remote.machineSetting']);
|
||||
assert.equal(testObject.getValue('configurationService.remote.machineSetting'), 'remoteValue');
|
||||
c();
|
||||
} catch (error) {
|
||||
e(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
await instantiationService.get(IFileService).writeFile(URI.file(remoteSettingsFile), VSBuffer.fromString('{ "configurationService.remote.machineSetting": "remoteValue" }'));
|
||||
return promise;
|
||||
});
|
||||
// test('update remote settings', async () => {
|
||||
// registerRemoteFileSystemProvider();
|
||||
// resolveRemoteEnvironment();
|
||||
// await initialize();
|
||||
// assert.equal(testObject.getValue('configurationService.remote.machineSetting'), 'isSet');
|
||||
// const promise = new Promise((c, e) => {
|
||||
// testObject.onDidChangeConfiguration(event => {
|
||||
// try {
|
||||
// assert.equal(event.source, ConfigurationTarget.USER);
|
||||
// assert.deepEqual(event.affectedKeys, ['configurationService.remote.machineSetting']);
|
||||
// assert.equal(testObject.getValue('configurationService.remote.machineSetting'), 'remoteValue');
|
||||
// c();
|
||||
// } catch (error) {
|
||||
// e(error);
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// fs.writeFileSync(remoteSettingsFile, '{ "configurationService.remote.machineSetting": "remoteValue" }');
|
||||
// return promise;
|
||||
// });
|
||||
|
||||
test('machine settings in local user settings does not override defaults', async () => {
|
||||
fs.writeFileSync(globalSettingsFile, '{ "configurationService.remote.machineSetting": "globalValue" }');
|
||||
|
||||
Reference in New Issue
Block a user