Add extension api for calling azdata commands (#11763)

* Add extension api for calling azdata commands

* Update typings file name
This commit is contained in:
Charles Gagnon
2020-08-12 12:57:59 -07:00
committed by GitHub
parent d96fe82fbc
commit 094ee7c50c
4 changed files with 151 additions and 18 deletions

View File

@@ -3,22 +3,49 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as azdata from './typings/azdata-ext';
import * as vscode from 'vscode';
import { findAzdata } from './azdata';
import { findAzdata, IAzdataTool } from './azdata';
import { parsePostgresServerListResult, parseSqlInstanceListResult } from './common/azdataUtils';
export async function activate(): Promise<void> {
let localAzdata: IAzdataTool | undefined = undefined;
export async function activate(): Promise<azdata.IExtension> {
const outputChannel = vscode.window.createOutputChannel('azdata');
await checkForAzdata(outputChannel);
localAzdata = await checkForAzdata(outputChannel);
return {
postgres: {
server: {
list: async () => {
if (!localAzdata) {
throw new Error('No azdata');
}
return localAzdata.executeCommand(['postgres', 'server', 'list'], parsePostgresServerListResult);
}
}
},
sql: {
instance: {
list: async () => {
if (!localAzdata) {
throw new Error('No azdata');
}
return localAzdata.executeCommand(['sql', 'instance', 'list'], parseSqlInstanceListResult);
}
}
}
};
}
async function checkForAzdata(outputChannel: vscode.OutputChannel): Promise<void> {
async function checkForAzdata(outputChannel: vscode.OutputChannel): Promise<IAzdataTool | undefined> {
try {
await findAzdata(outputChannel);
return await findAzdata(outputChannel);
} catch (err) {
// Don't block on this since we want the extension to finish activating without needing user input.
// Calls will be made to handle azdata not being installed
promptToInstallAzdata(outputChannel).catch(e => console.log(`Unexpected error prompting to install azdata ${e}`));
}
return undefined;
}
async function promptToInstallAzdata(_outputChannel: vscode.OutputChannel): Promise<void> {