From b9ea17c2ebfccb8de8db05ab72c47b4b84c6c7e2 Mon Sep 17 00:00:00 2001 From: Matt Irvine Date: Mon, 6 Nov 2017 09:59:41 -0800 Subject: [PATCH] Change many configs to resource scope (#1017) --- package.json | 72 ++++++++++++------- src/controllers/queryRunner.ts | 6 +- src/models/resultsSerializer.ts | 6 +- src/models/sqlOutputContentProvider.ts | 21 +++--- .../src/js/services/data.service.ts | 8 ++- test/queryRunner.test.ts | 2 +- test/saveResults.test.ts | 11 +-- test/sqlOutputContentProvider.test.ts | 4 +- test/webServiceRequestHandlers.test.ts | 9 ++- 9 files changed, 91 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index 0ea24aba..a5ae92a1 100644 --- a/package.json +++ b/package.json @@ -240,12 +240,14 @@ "mssql.logDebugInfo": { "type": "boolean", "default": false, - "description": "%mssql.logDebugInfo%" + "description": "%mssql.logDebugInfo%", + "scope": "window" }, "mssql.maxRecentConnections": { "type": "number", "default": 5, - "description": "%mssql.maxRecentConnections%" + "description": "%mssql.maxRecentConnections%", + "scope": "window" }, "mssql.connections": { "type": "array", @@ -424,7 +426,8 @@ "description": "%mssql.connection.emptyPasswordInput%" } } - } + }, + "scope": "window" }, "mssql.shortcuts": { "type": "object", @@ -442,42 +445,50 @@ "event.saveAsJSON": "", "event.saveAsCSV": "", "event.saveAsExcel": "" - } + }, + "scope": "resource" }, "mssql.messagesDefaultOpen": { "type": "boolean", "description": "%mssql.messagesDefaultOpen%", - "default": true + "default": true, + "scope": "resource" }, "mssql.resultsFontFamily": { "type": "string", "description": "%mssql.resultsFontFamily%", - "default": "-apple-system,BlinkMacSystemFont,Segoe WPC,Segoe UI,HelveticaNeue-Light,Ubuntu,Droid Sans,sans-serif" + "default": "-apple-system,BlinkMacSystemFont,Segoe WPC,Segoe UI,HelveticaNeue-Light,Ubuntu,Droid Sans,sans-serif", + "scope": "resource" }, "mssql.resultsFontSize": { "type": "number", "description": "%mssql.resultsFontSize%", - "default": 13 + "default": 13, + "scope": "resource" }, "mssql.saveAsCsv.includeHeaders": { "type": "boolean", "description": "%mssql.saveAsCsv.includeHeaders%", - "default": true + "default": true, + "scope": "resource" }, "mssql.copyIncludeHeaders": { "type": "boolean", "description": "%mssql.copyIncludeHeaders%", - "default": false + "default": false, + "scope": "resource" }, "mssql.copyRemoveNewLine": { "type": "boolean", "description": "%mssql.copyRemoveNewLine%", - "default": true + "default": true, + "scope": "resource" }, "mssql.showBatchTime": { "type": "boolean", "description": "%mssql.showBatchTime%", - "default": false + "default": false, + "scope": "resource" }, "mssql.splitPaneSelection": { "type": "string", @@ -487,12 +498,14 @@ "next", "current", "end" - ] + ], + "scope": "resource" }, "mssql.format.alignColumnDefinitionsInColumns": { "type": "boolean", "description": "%mssql.format.alignColumnDefinitionsInColumns%", - "default": false + "default": false, + "scope": "window" }, "mssql.format.datatypeCasing": { "type": "string", @@ -502,7 +515,8 @@ "none", "uppercase", "lowercase" - ] + ], + "scope": "window" }, "mssql.format.keywordCasing": { "type": "string", @@ -512,52 +526,62 @@ "none", "uppercase", "lowercase" - ] + ], + "scope": "window" }, "mssql.format.placeCommasBeforeNextStatement": { "type": "boolean", "description": "%mssql.format.placeCommasBeforeNextStatement%", - "default": false + "default": false, + "scope": "window" }, "mssql.format.placeSelectStatementReferencesOnNewLine": { "type": "boolean", "description": "%mssql.format.placeSelectStatementReferencesOnNewLine%", - "default": false + "default": false, + "scope": "window" }, "mssql.applyLocalization": { "type": "boolean", "description": "%mssql.applyLocalization%", - "default": false + "default": false, + "scope": "window" }, "mssql.query.displayBitAsNumber": { "type": "boolean", "default": true, - "description": "%mssql.query.displayBitAsNumber%" + "description": "%mssql.query.displayBitAsNumber%", + "scope": "window" }, "mssql.intelliSense.enableIntelliSense": { "type": "boolean", "default": true, - "description": "%mssql.intelliSense.enableIntelliSense%" + "description": "%mssql.intelliSense.enableIntelliSense%", + "scope": "window" }, "mssql.intelliSense.enableErrorChecking": { "type": "boolean", "default": true, - "description": "%mssql.intelliSense.enableErrorChecking%" + "description": "%mssql.intelliSense.enableErrorChecking%", + "scope": "window" }, "mssql.intelliSense.enableSuggestions": { "type": "boolean", "default": true, - "description": "%mssql.intelliSense.enableSuggestions%" + "description": "%mssql.intelliSense.enableSuggestions%", + "scope": "window" }, "mssql.intelliSense.enableQuickInfo": { "type": "boolean", "default": true, - "description": "%mssql.intelliSense.enableQuickInfo%" + "description": "%mssql.intelliSense.enableQuickInfo%", + "scope": "window" }, "mssql.intelliSense.lowerCaseSuggestions": { "type": "boolean", "default": false, - "description": "%mssql.intelliSense.lowerCaseSuggestions%" + "description": "%mssql.intelliSense.lowerCaseSuggestions%", + "scope": "window" } } } diff --git a/src/controllers/queryRunner.ts b/src/controllers/queryRunner.ts index 3fc25bb0..98aed561 100644 --- a/src/controllers/queryRunner.ts +++ b/src/controllers/queryRunner.ts @@ -348,14 +348,14 @@ export default class QueryRunner { return includeHeaders; } // else get config option from vscode config - let config = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName); + let config = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName, this.uri); includeHeaders = config[Constants.copyIncludeHeaders]; return !!includeHeaders; } private shouldRemoveNewLines(): boolean { // get config copyRemoveNewLine option from vscode config - let config = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName); + let config = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName, this.uri); let removeNewLines: boolean = config[Constants.configCopyRemoveNewLine]; return removeNewLines; } @@ -371,7 +371,7 @@ export default class QueryRunner { private sendBatchTimeMessage(batchId: number, executionTime: string): void { // get config copyRemoveNewLine option from vscode config - let config = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName); + let config = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName, this.uri); let showBatchTime: boolean = config[Constants.configShowBatchTime]; if (showBatchTime) { let message: IResultMessage = { diff --git a/src/models/resultsSerializer.ts b/src/models/resultsSerializer.ts index 322264d4..59135ab8 100644 --- a/src/models/resultsSerializer.ts +++ b/src/models/resultsSerializer.ts @@ -65,7 +65,7 @@ export default class ResultsSerializer { private getConfigForCsv(): Contracts.SaveResultsAsCsvRequestParams { // get save results config from vscode config - let config = vscode.workspace.getConfiguration(Constants.extensionConfigSectionName); + let config = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName, this._uri); let saveConfig = config[Constants.configSaveAsCsv]; let saveResultsParams = new Contracts.SaveResultsAsCsvRequestParams(); @@ -80,7 +80,7 @@ export default class ResultsSerializer { private getConfigForJson(): Contracts.SaveResultsAsJsonRequestParams { // get save results config from vscode config - let config = vscode.workspace.getConfiguration(Constants.extensionConfigSectionName); + let config = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName, this._uri); let saveConfig = config[Constants.configSaveAsJson]; let saveResultsParams = new Contracts.SaveResultsAsJsonRequestParams(); @@ -94,7 +94,7 @@ export default class ResultsSerializer { // get save results config from vscode config // Note: we are currently using the configSaveAsCsv setting since it has the option mssql.saveAsCsv.includeHeaders // and we want to have just 1 setting that lists this. - let config = vscode.workspace.getConfiguration(Constants.extensionConfigSectionName); + let config = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName, this._uri); let saveConfig = config[Constants.configSaveAsCsv]; let saveResultsParams = new Contracts.SaveResultsAsExcelRequestParams(); diff --git a/src/models/sqlOutputContentProvider.ts b/src/models/sqlOutputContentProvider.ts index 30db392f..06a46bcf 100644 --- a/src/models/sqlOutputContentProvider.ts +++ b/src/models/sqlOutputContentProvider.ts @@ -97,8 +97,12 @@ export class SqlOutputContentProvider implements vscode.TextDocumentContentProvi } catch (e) { prod = false; } - let mssqlConfig = this._vscodeWrapper.getConfiguration(Constants.extensionName); - let editorConfig = this._vscodeWrapper.getConfiguration('editor', uri); + let queryUri: string; + if (this._queryResultsMap.has(uri)) { + queryUri = this._queryResultsMap.get(uri).queryRunner.uri; + } + let mssqlConfig = this._vscodeWrapper.getConfiguration(Constants.extensionName, queryUri); + let editorConfig = this._vscodeWrapper.getConfiguration('editor', queryUri); let extensionFontFamily = mssqlConfig.get(Constants.extConfigResultFontFamily).split('\'').join('').split('"').join(''); let extensionFontSize = mssqlConfig.get(Constants.extConfigResultFontSize); let fontfamily = extensionFontFamily ? @@ -133,7 +137,8 @@ export class SqlOutputContentProvider implements vscode.TextDocumentContentProvi } public configRequestHandler(req, res): void { - let extConfig = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName); + let queryUri = this._queryResultsMap.get(req.query.uri).queryRunner.uri; + let extConfig = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName, queryUri); let config = new ResultsConfig(); for (let key of Constants.extConfigResultKeys) { config[key] = extConfig[key]; @@ -260,7 +265,7 @@ export class SqlOutputContentProvider implements vscode.TextDocumentContentProvi let paneTitle = Utils.formatString(LocalizedConstants.titleResultsPane, queryRunner.title); // Always run this command even if just updating to avoid a bug - tfs 8686842 - this.displayResultPane(resultsUri, paneTitle); + this.displayResultPane(resultsUri, paneTitle, uri); } } @@ -330,14 +335,14 @@ export class SqlOutputContentProvider implements vscode.TextDocumentContentProvi } // Function to render resultspane content - public displayResultPane(resultsUri: string, paneTitle: string): void { + public displayResultPane(resultsUri: string, paneTitle: string, queryUri: string): void { // Get the active text editor let activeTextEditor = this._vscodeWrapper.activeTextEditor; // Check if the results window already exists if (!this.doesResultPaneExist(resultsUri)) { // Wrapper tells us where the new results pane should be placed - let resultPaneColumn = this.newResultPaneViewColumn(); + let resultPaneColumn = this.newResultPaneViewColumn(queryUri); // Try and Open new window then reset focus back to the editor vscode.commands.executeCommand('vscode.previewHtml', resultsUri, resultPaneColumn, paneTitle).then(() => { @@ -586,9 +591,9 @@ export class SqlOutputContentProvider implements vscode.TextDocumentContentProvi * @return ViewColumn to be used * public for testing purposes */ - public newResultPaneViewColumn(): vscode.ViewColumn { + public newResultPaneViewColumn(queryUri: string): vscode.ViewColumn { // Find configuration options - let config = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName); + let config = this._vscodeWrapper.getConfiguration(Constants.extensionConfigSectionName, queryUri); let splitPaneSelection = config[Constants.configSplitPaneSelection]; let viewColumn: vscode.ViewColumn; diff --git a/src/views/htmlcontent/src/js/services/data.service.ts b/src/views/htmlcontent/src/js/services/data.service.ts index 539b2c18..fefd94ca 100644 --- a/src/views/htmlcontent/src/js/services/data.service.ts +++ b/src/views/htmlcontent/src/js/services/data.service.ts @@ -198,7 +198,9 @@ export class DataService { return Promise.resolve(this._config); } else { return new Promise<{[key: string]: string}>((resolve, reject) => { - self.http.get('/config').map((res): IResultsConfig => { + let url = '/config?' + + '&uri=' + self.uri; + self.http.get(url).map((res): IResultsConfig => { return res.json(); }).subscribe((result: IResultsConfig) => { self._shortcuts = result.shortcuts; @@ -216,7 +218,9 @@ export class DataService { return Promise.resolve(this._shortcuts); } else { return new Promise((resolve, reject) => { - self.http.get('/config').map((res): IResultsConfig => { + let url = '/config?' + + '&uri=' + self.uri; + self.http.get(url).map((res): IResultsConfig => { return res.json(); }).subscribe((result) => { self._shortcuts = result.shortcuts; diff --git a/test/queryRunner.test.ts b/test/queryRunner.test.ts index 185d890a..110af503 100644 --- a/test/queryRunner.test.ts +++ b/test/queryRunner.test.ts @@ -490,7 +490,7 @@ suite('Query Runner tests', () => { function setupWorkspaceConfig(configResult: {[key: string]: any}): void { let config = stubs.createWorkspaceConfiguration(configResult); - testVscodeWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny())) + testVscodeWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny(), TypeMoq.It.isAny())) .returns(x => { return config; }); diff --git a/test/saveResults.test.ts b/test/saveResults.test.ts index 39377ca3..29100f24 100644 --- a/test/saveResults.test.ts +++ b/test/saveResults.test.ts @@ -5,13 +5,13 @@ import ResultsSerializer from './../src/models/resultsSerializer'; import { SaveResultsAsCsvRequestParams } from './../src/models/contracts'; import SqlToolsServerClient from './../src/languageservice/serviceclient'; import VscodeWrapper from './../src/controllers/vscodeWrapper'; -import { Uri } from 'vscode'; +import * as vscode from 'vscode'; import os = require('os'); suite('save results tests', () => { const testFile = 'file:///my/test/file.sql'; - let fileUri: Uri; + let fileUri: vscode.Uri; let serverClient: TypeMoq.IMock; let vscodeWrapper: TypeMoq.IMock; @@ -19,10 +19,13 @@ suite('save results tests', () => { serverClient = TypeMoq.Mock.ofType(SqlToolsServerClient, TypeMoq.MockBehavior.Strict); vscodeWrapper = TypeMoq.Mock.ofType(VscodeWrapper); + vscodeWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(extensionName => { + return vscode.workspace.getConfiguration(extensionName); + }); if (os.platform() === 'win32') { - fileUri = Uri.file('c:\\test.csv'); + fileUri = vscode.Uri.file('c:\\test.csv'); } else { - fileUri = Uri.file('/test.csv'); + fileUri = vscode.Uri.file('/test.csv'); } }); diff --git a/test/sqlOutputContentProvider.test.ts b/test/sqlOutputContentProvider.test.ts index 14a2601f..a2cfa948 100644 --- a/test/sqlOutputContentProvider.test.ts +++ b/test/sqlOutputContentProvider.test.ts @@ -32,7 +32,7 @@ suite('SqlOutputProvider Tests', () => { let configResult: {[key: string]: any} = {}; configResult[Constants.configSplitPaneSelection] = value; let config = stubs.createWorkspaceConfiguration(configResult); - vscodeWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny())) + vscodeWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny(), TypeMoq.It.isAny())) .returns(x => { return config; }); @@ -74,7 +74,7 @@ suite('SqlOutputProvider Tests', () => { setSplitPaneSelectionConfig(c.config); setCurrentEditorColumn(c.position); - let resultColumn = contentProvider.newResultPaneViewColumn(); + let resultColumn = contentProvider.newResultPaneViewColumn('test_uri'); // Ensure each case properly outputs the result pane assert.equal(resultColumn, c.expectedColumn); diff --git a/test/webServiceRequestHandlers.test.ts b/test/webServiceRequestHandlers.test.ts index b6019c5f..4cc70f29 100644 --- a/test/webServiceRequestHandlers.test.ts +++ b/test/webServiceRequestHandlers.test.ts @@ -51,6 +51,7 @@ suite('Web Service Request Handler Tests', () => { startColumn: 0, startLine: 0 }; + queryRunner.setup(x => x.uri).returns(() => uri); contentProvider.runQuery(statusView.object, uri, querySelection, title); contentProvider.getResultsMap.get('tsqloutput:' + uri).queryRunner = queryRunner.object; }); @@ -117,7 +118,13 @@ suite('Web Service Request Handler Tests', () => { }); test('ConfigRequestHandler properly handles request and renders content', done => { - let request = new stubs.ExpressRequest(); + let testQuery = { + resultSetNo: 0, + uri: 'tsqloutput:test_uri', + batchIndex: 0, + format: 'test_format' + }; + let request = new stubs.ExpressRequest(testQuery); // Run tested function contentProvider.configRequestHandler(request, result.object);