mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 09:35:36 -05:00
- Fix a number of issues that arose while testing a provider without a metadata service or serverInfo object returned via DMP calls. These should be optional services/features and we should be resilient to them not existing. In most places we already have these checks - This does not cover a number of "improvement" scenarios, such as filtering extension tabs by provider, and defaulting any tabs that don't specify a provider to be MSSQL. This and some other features to ensure things make sense will be implemented in separate PRs but this unblocked the scenario
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
'use strict';
|
|
import * as vscode from 'vscode';
|
|
import * as sqlops from 'sqlops';
|
|
|
|
import * as types from './types';
|
|
|
|
export enum BuiltInCommands {
|
|
SetContext = 'setContext',
|
|
}
|
|
|
|
export enum ContextKeys {
|
|
ISCLOUD = 'mssql:iscloud',
|
|
EDITIONID = 'mssql:engineedition'
|
|
}
|
|
|
|
const isCloudEditions = [
|
|
5,
|
|
6
|
|
];
|
|
|
|
export function setCommandContext(key: ContextKeys | string, value: any) {
|
|
return vscode.commands.executeCommand(BuiltInCommands.SetContext, key, value);
|
|
}
|
|
|
|
export default class ContextProvider {
|
|
private _disposables = new Array<vscode.Disposable>();
|
|
|
|
constructor() {
|
|
this._disposables.push(sqlops.workspace.onDidOpenDashboard(this.onDashboardOpen, this));
|
|
this._disposables.push(sqlops.workspace.onDidChangeToDashboard(this.onDashboardOpen, this));
|
|
}
|
|
|
|
public onDashboardOpen(e: sqlops.DashboardDocument): void {
|
|
let iscloud: boolean;
|
|
let edition: number;
|
|
if (e.profile.providerName.toLowerCase() === 'mssql' && !types.isUndefinedOrNull(e.serverInfo) && !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 {
|
|
this._disposables = this._disposables.map(i => i.dispose());
|
|
}
|
|
}
|