mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-25 01:25:36 -05:00
Messages panel wordwrap (#10970)
* Add CodeQL Analysis workflow (#10195) * Add CodeQL Analysis workflow * Fix path * fix word wrap support in the message panel * fix width on message treee * fix import * fix settings editor to reflect the changes in the settings ids * fix tests * add configuration upgrader * make sure to maintian execution order * make the compiler happy * add tests for upgrader Co-authored-by: Justin Hutchings <jhutchings1@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
|
||||
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
|
||||
import { ConfigurationUpgraderContribution } from 'sql/workbench/contrib/configuration/common/configurationUpgrader';
|
||||
|
||||
const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
|
||||
workbenchContributionsRegistry.registerWorkbenchContribution(ConfigurationUpgraderContribution, LifecyclePhase.Starting);
|
||||
@@ -0,0 +1,66 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
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';
|
||||
|
||||
const settingsToMove: { [key: string]: string } = deepFreeze({
|
||||
'sql.saveAsCsv.includeHeaders': 'queryEditor.results.saveAsCsv.includeHeaders', // June 19, 2020
|
||||
'sql.saveAsCsv.delimiter': 'queryEditor.results.saveAsCsv.delimiter', // June 19, 2020
|
||||
'sql.saveAsCsv.lineSeperator': 'queryEditor.results.saveAsCsv.lineSeperator', // June 19, 2020
|
||||
'sql.saveAsCsv.textIdentifier': 'queryEditor.results.saveAsCsv.textIdentifier', // June 19, 2020
|
||||
'sql.saveAsCsv.encoding': 'queryEditor.results.saveAsCsv.encoding', // June 19, 2020
|
||||
'sql.results.streaming': 'queryEditor.results.streaming', // June 19, 2020
|
||||
'sql.saveAsXml.formatted': 'queryEditor.results.saveAsXml.formatted', // June 19, 2020
|
||||
'sql.saveAsXml.encoding': 'queryEditor.results.saveAsXml.encoding', // June 19, 2020
|
||||
'sql.copyIncludeHeaders': 'queryEditor.results.copyIncludeHeaders', // June 19, 2020
|
||||
'sql.copyRemoveNewLine': 'queryEditor.results.copyRemoveNewLine', // June 19, 2020
|
||||
'sql.showBatchTime': 'queryEditor.messages.showBatchTime', // June 19, 2020
|
||||
'sql.chart.defaultChartType': 'queryEditor.chart.defaultChartType', // June 19, 2020
|
||||
'sql.tabColorMode': 'queryEditor.tabColorMode', // June 19, 2020
|
||||
'sql.showConnectionInfoInTitle': 'queryEditor.showConnectionInfoInTitle', // June 19, 2020
|
||||
'sql.promptToSaveGeneratedFiles': 'queryEditor.promptToSaveGeneratedFiles', // June 19, 2020
|
||||
});
|
||||
|
||||
export class ConfigurationUpgraderContribution implements IWorkbenchContribution {
|
||||
|
||||
private static readonly STORAGE_KEY = 'configurationUpgrader';
|
||||
private readonly globalStorage: { [key: string]: boolean };
|
||||
private readonly workspaceStorage: { [key: string]: boolean };
|
||||
|
||||
public readonly processingPromise: Promise<void>;
|
||||
|
||||
constructor(
|
||||
@IStorageService private readonly storageService: IStorageService,
|
||||
@IConfigurationService private readonly configurationService: IConfigurationService
|
||||
) {
|
||||
this.globalStorage = JSON.parse(this.storageService.get(ConfigurationUpgraderContribution.STORAGE_KEY, StorageScope.GLOBAL, '{}'));
|
||||
this.workspaceStorage = JSON.parse(this.storageService.get(ConfigurationUpgraderContribution.STORAGE_KEY, StorageScope.WORKSPACE, '{}'));
|
||||
this.processingPromise = (async () => {
|
||||
await this.processSettings();
|
||||
this.storageService.store(ConfigurationUpgraderContribution.STORAGE_KEY, JSON.stringify(this.globalStorage), StorageScope.GLOBAL);
|
||||
this.storageService.store(ConfigurationUpgraderContribution.STORAGE_KEY, JSON.stringify(this.workspaceStorage), StorageScope.WORKSPACE);
|
||||
})();
|
||||
}
|
||||
|
||||
private async processSettings(): Promise<void> {
|
||||
for (const key in settingsToMove) {
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
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';
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
await configurationUpgrader.processingPromise;
|
||||
assert(configurationService.inspect('sql.saveAsCsv.includeHeaders').workspaceValue === undefined);
|
||||
assert(configurationService.inspect('queryEditor.results.saveAsCsv.includeHeaders').workspaceValue === true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user