mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 17:23:02 -05:00
Handle no azdata API in sql db proj extension gracefully (#15873)
* Update db proj ext to handle not having azdata API available * Fixes * Fix compile
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
import type * as azdataType from 'azdata';
|
||||
|
||||
export interface IconPath {
|
||||
dark: string;
|
||||
@@ -40,7 +40,7 @@ export class IconPathHelper {
|
||||
public static error: IconPath;
|
||||
public static inProgress: IconPath;
|
||||
|
||||
public static dashboardSqlProj: azdata.ThemedIconPath;
|
||||
public static dashboardSqlProj: azdataType.ThemedIconPath;
|
||||
|
||||
public static setExtensionContext(extensionContext: vscode.ExtensionContext) {
|
||||
IconPathHelper.extensionContext = extensionContext;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import type * as azdataType from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as os from 'os';
|
||||
import * as constants from './constants';
|
||||
@@ -324,3 +325,20 @@ export function timeConversion(duration: number): string {
|
||||
|
||||
return portions.join(', ');
|
||||
}
|
||||
|
||||
// Try to load the azdata API - but gracefully handle the failure in case we're running
|
||||
// in a context where the API doesn't exist (such as VS Code)
|
||||
let azdataApi: typeof azdataType | undefined = undefined;
|
||||
try {
|
||||
azdataApi = require('azdata');
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the azdata API if it's available in the context this extension is running in.
|
||||
* @returns The azdata API if it's available
|
||||
*/
|
||||
export function getAzdataApi(): typeof azdataType | undefined {
|
||||
return azdataApi;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user