Remove deleting the old config (unsupported) and add notification (#11142)

* Add CodeQL Analysis workflow (#10195)

* Add CodeQL Analysis workflow

* Fix path

* remove deleting the old config (unsupported) and add notification

* fix tests

Co-authored-by: Justin Hutchings <jhutchings1@users.noreply.github.com>
This commit is contained in:
Anthony Dresser
2020-06-29 21:40:03 -07:00
committed by GitHub
parent 749c42ce41
commit ef8205f918
2 changed files with 11 additions and 12 deletions

View File

@@ -7,6 +7,8 @@ import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { deepFreeze } from 'vs/base/common/objects';
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { localize } from 'vs/nls';
const settingsToMove: { [key: string]: string } = deepFreeze({
'sql.saveAsCsv.includeHeaders': 'queryEditor.results.saveAsCsv.includeHeaders', // June 19, 2020
@@ -36,7 +38,8 @@ export class ConfigurationUpgraderContribution implements IWorkbenchContribution
constructor(
@IStorageService private readonly storageService: IStorageService,
@IConfigurationService private readonly configurationService: IConfigurationService
@IConfigurationService private readonly configurationService: IConfigurationService,
@INotificationService private readonly notificationService: INotificationService
) {
this.globalStorage = JSON.parse(this.storageService.get(ConfigurationUpgraderContribution.STORAGE_KEY, StorageScope.GLOBAL, '{}'));
this.workspaceStorage = JSON.parse(this.storageService.get(ConfigurationUpgraderContribution.STORAGE_KEY, StorageScope.WORKSPACE, '{}'));
@@ -52,14 +55,14 @@ export class ConfigurationUpgraderContribution implements IWorkbenchContribution
const toKey = settingsToMove[key];
const value = this.configurationService.inspect(key);
if (this.globalStorage[key] !== true && value.userValue) {
await this.configurationService.updateValue(key, undefined, ConfigurationTarget.USER); // writing undefined will result in the key being deleted
await this.configurationService.updateValue(toKey, value.userValue, ConfigurationTarget.USER); // update to new settings key
this.globalStorage[key] = true; // don't proccess again
this.notificationService.info(localize('workbench.configuration.upgradeUser', "{0} was replaced with {1} in your user settings.", key, toKey));
}
if (this.workspaceStorage[key] !== true && value.workspaceValue) {
await this.configurationService.updateValue(key, undefined, ConfigurationTarget.WORKSPACE); // writing undefined will result in the key being deleted
await this.configurationService.updateValue(toKey, value.workspaceValue, ConfigurationTarget.WORKSPACE); // update to new settings key
this.workspaceStorage[key] = true; // don't proccess again
this.notificationService.info(localize('workbench.configuration.upgradeWorkspace', "{0} was replaced with {1} in your workspace settings.", key, toKey));
}
}
}

View File

@@ -7,39 +7,35 @@ import * as assert from 'assert';
import { ConfigurationUpgraderContribution } from 'sql/workbench/contrib/configuration/common/configurationUpgrader';
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
suite('Configuration Upgrader', () => {
test('does upgrade settings in user settings', async () => {
const configurationService = new TestConfigurationService({ user: { 'sql': { 'saveAsCsv': { 'includeHeaders': true } } } });
const configurationUpgrader = new ConfigurationUpgraderContribution(new TestStorageService(), configurationService);
const configurationUpgrader = new ConfigurationUpgraderContribution(new TestStorageService(), configurationService, new TestNotificationService());
await configurationUpgrader.processingPromise;
assert(configurationService.inspect('sql.saveAsCsv.includeHeaders').userValue === undefined);
assert(configurationService.inspect('queryEditor.results.saveAsCsv.includeHeaders').userValue === true);
});
test('does not change new setting', async () => {
const configurationService = new TestConfigurationService({ user: { 'queryEditor': { 'results': { 'saveAsCsv': { 'includeHeaders': true } } } } });
const configurationUpgrader = new ConfigurationUpgraderContribution(new TestStorageService(), configurationService);
const configurationUpgrader = new ConfigurationUpgraderContribution(new TestStorageService(), configurationService, new TestNotificationService());
await configurationUpgrader.processingPromise;
assert(configurationService.inspect('sql.saveAsCsv.includeHeaders').userValue === undefined);
assert(configurationService.inspect('queryEditor.results.saveAsCsv.includeHeaders').userValue === true);
});
test('correctly changes multiple settings', async () => {
const configurationService = new TestConfigurationService({ user: { 'sql': { 'saveAsCsv': { 'includeHeaders': true }, 'promptToSaveGeneratedFiles': true } } });
const configurationUpgrader = new ConfigurationUpgraderContribution(new TestStorageService(), configurationService);
const configurationUpgrader = new ConfigurationUpgraderContribution(new TestStorageService(), configurationService, new TestNotificationService());
await configurationUpgrader.processingPromise;
assert(configurationService.inspect('sql.saveAsCsv.includeHeaders').userValue === undefined);
assert(configurationService.inspect('queryEditor.results.saveAsCsv.includeHeaders').userValue === true);
assert(configurationService.inspect('sql.promptToSaveGeneratedFiles').userValue === undefined);
assert(configurationService.inspect('queryEditor.promptToSaveGeneratedFiles').userValue === true);
});
test('does change workspace settings', async () => {
const configurationService = new TestConfigurationService({ workspace: { 'sql': { 'saveAsCsv': { 'includeHeaders': true } } } });
const configurationUpgrader = new ConfigurationUpgraderContribution(new TestStorageService(), configurationService);
const configurationUpgrader = new ConfigurationUpgraderContribution(new TestStorageService(), configurationService, new TestNotificationService());
await configurationUpgrader.processingPromise;
assert(configurationService.inspect('sql.saveAsCsv.includeHeaders').workspaceValue === undefined);
assert(configurationService.inspect('queryEditor.results.saveAsCsv.includeHeaders').workspaceValue === true);
});
});