From 58036bb364253cdbb2ca75180b1124778c2ee132 Mon Sep 17 00:00:00 2001 From: Anthony Dresser Date: Fri, 1 Jun 2018 14:43:15 -0700 Subject: [PATCH] Mssql edition context (#1537) * added sql server edition context * formatting * change context key to engine edition --- extensions/mssql/src/contextProvider.ts | 18 +++++++++++++---- extensions/mssql/src/types.ts | 27 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 extensions/mssql/src/types.ts diff --git a/extensions/mssql/src/contextProvider.ts b/extensions/mssql/src/contextProvider.ts index 5ac4fd2c1e..17677d3fb6 100644 --- a/extensions/mssql/src/contextProvider.ts +++ b/extensions/mssql/src/contextProvider.ts @@ -6,12 +6,15 @@ import * as vscode from 'vscode'; import * as sqlops from 'sqlops'; +import * as types from './types'; + export enum BuiltInCommands { - SetContext = 'setContext', + SetContext = 'setContext', } export enum ContextKeys { - ISCLOUD = 'mssql:iscloud' + ISCLOUD = 'mssql:iscloud', + EDITIONID = 'mssql:engineedition' } const isCloudEditions = [ @@ -20,7 +23,7 @@ const isCloudEditions = [ ]; export function setCommandContext(key: ContextKeys | string, value: any) { - return vscode.commands.executeCommand(BuiltInCommands.SetContext, key, value); + return vscode.commands.executeCommand(BuiltInCommands.SetContext, key, value); } export default class ContextProvider { @@ -33,17 +36,24 @@ export default class ContextProvider { public onDashboardOpen(e: sqlops.DashboardDocument): void { let iscloud: boolean; - if (e.profile.providerName.toLowerCase() === 'mssql' && e.serverInfo.engineEditionId) { + let edition: number; + if (e.profile.providerName.toLowerCase() === 'mssql' && !types.isUndefinedOrNull(e.serverInfo.engineEditionId)) { if (isCloudEditions.some(i => i === e.serverInfo.engineEditionId)) { iscloud = true; } else { iscloud = false; } + + edition = e.serverInfo.engineEditionId; } if (iscloud === true || iscloud === false) { setCommandContext(ContextKeys.ISCLOUD, iscloud); } + + if (!types.isUndefinedOrNull(edition)) { + setCommandContext(ContextKeys.EDITIONID, edition); + } } dispose(): void { diff --git a/extensions/mssql/src/types.ts b/extensions/mssql/src/types.ts new file mode 100644 index 0000000000..a50f1bfb26 --- /dev/null +++ b/extensions/mssql/src/types.ts @@ -0,0 +1,27 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +const _typeof = { + number: 'number', + string: 'string', + undefined: 'undefined', + object: 'object', + function: 'function' +}; + +/** + * @returns whether the provided parameter is undefined or null. + */ +export function isUndefinedOrNull(obj: any): boolean { + return isUndefined(obj) || obj === null; +} + +/** + * @returns whether the provided parameter is undefined. + */ +export function isUndefined(obj: any): boolean { + return typeof (obj) === _typeof.undefined; +}