diff --git a/.vscode/settings.json b/.vscode/settings.json index 338530a..0cea33c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,14 +5,5 @@ }, "search.exclude": { "out": true // set this to false to include "out" folder in search results - }, - "terminal.integrated.env.osx": { - "SFDX_SET_CLIENT_IDS": "sfdx-vscode" - }, - "terminal.integrated.env.linux": { - "SFDX_SET_CLIENT_IDS": "sfdx-vscode" - }, - "terminal.integrated.env.windows": { - "SFDX_SET_CLIENT_IDS": "sfdx-vscode" } } \ No newline at end of file diff --git a/README.md b/README.md index bfbda43..7565bec 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This extension provides immediate access to the current First Responder Kit scripts and introductory execution suggestions. (All credit due to http://firstresponderkit.org/) ## Installation -The current release is available to [download as a .vsix file](https://github.com/dzsquared/sqlops-firstresponderkit/releases/download/0.5.1/firstresponderkit-0.5.1.vsix) and can be installed by opening the command palette (`ctrl/command+shift+p`) and selecting `Extensions: Install from VSIX...` +The current release is available to [download as a .vsix file](https://github.com/dzsquared/sqlops-firstresponderkit/releases/download/0.6.0/firstresponderkit-0.6.0.vsix) and can be installed by opening the command palette (`ctrl/command+shift+p`) and selecting `Extensions: Install from VSIX...` ## Features @@ -52,6 +52,11 @@ Can be raised here: https://github.com/dzsquared/sqlops-firstresponderkit/issues ## Release Notes +### 0.6.0 + +- Fix for extension unable to pull scripts from GitHub. Change to utilizing `main` branch of First Responder Kit. +- Adds interactive documentation linking to status bar. + ### 0.5.1 - Fix for changes to new editor connection changes in Azure Data Studio 1.15.0 diff --git a/package-lock.json b/package-lock.json index 7085a25..4735a9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "firstresponderkit", - "version": "0.5.1", + "version": "0.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 44be32f..e18931d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "publisher": "drewsk", "engines": { "vscode": "^1.25.0", - "azdata": "^1.15.0" + "azdata": "^1.21.0" }, "categories": [ "Other" @@ -18,7 +18,7 @@ "activationEvents": [ "*" ], - "main": "./out/extension", + "main": "./dist/extension", "contributes": { "commands": [ { diff --git a/src/extension.ts b/src/extension.ts index 48ccb5d..5753424 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,9 +10,10 @@ import * as runScripts from './runScripts'; export function activate(context: vscode.ExtensionContext) { const baseUrl = "https://raw.githubusercontent.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/main/"; - - // documentation + + // documentation help link let currentBlitz: string = 'sp_Blitz'; + let timeout: NodeJS.Timer | null = null; var docsspblitz = () => { openDocumentation(baseUrl, currentBlitz); }; @@ -24,15 +25,16 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(docsStatusBar); function checkSpBlitzType() : void { - let blitzes: string[] = ['sp_Blitz', 'sp_BlitzCache', 'sp_BlitzIndex', 'sp_BlitzFirst', 'sp_BlitzWho' - , 'sp_BlitzInMemoryOLTP', 'sp_BlitzLock', 'sp_BlitzQueryStore', 'sp_BlitzBackups']; - let editorText: string = vscode.window.activeTextEditor.document.getText(); + let blitzes: string[] = ['sp_Blitz', 'sp_BlitzIndex', 'sp_BlitzCache', 'sp_BlitzWho', 'sp_BlitzFirst', 'sp_BlitzLock', 'sp_Blitz\'']; let blitzLabel: string = ""; - blitzes.forEach( blitz => { - if (editorText.toLowerCase().includes(blitz.toLowerCase())) { - blitzLabel = blitz; - } - }); + if (vscode.window.activeTextEditor) { + let editorText: string = vscode.window.activeTextEditor.document.getText(); + blitzes.forEach( blitz => { + if (editorText.toLowerCase().includes(blitz.toLowerCase())) { + blitzLabel = blitz.replace('\'',''); + } + }); + } if (blitzLabel != "") { docsStatusBar.text = '$(question) ' + blitzLabel + ' Documentation'; docsStatusBar.show(); @@ -41,8 +43,17 @@ export function activate(context: vscode.ExtensionContext) { } currentBlitz = blitzLabel; } - context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(checkSpBlitzType)); - context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(checkSpBlitzType)); + + function triggerUpdateDocLink() { + if (timeout) { + clearTimeout(timeout); + } + timeout = setTimeout(checkSpBlitzType, 1000); // wait a second to avoid hammering + } + + context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(triggerUpdateDocLink)); + context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(triggerUpdateDocLink)); + context.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(triggerUpdateDocLink)); context.subscriptions.push(disposable_spblitzversion); diff --git a/src/getScripts.ts b/src/getScripts.ts index 16e3d9d..809f064 100644 --- a/src/getScripts.ts +++ b/src/getScripts.ts @@ -1,22 +1,25 @@ 'use strict'; import * as vscode from 'vscode'; +import * as sqlops from 'azdata'; import * as request from 'request-promise-native'; import {placeScript} from './placescript'; const baseUrl = "https://raw.githubusercontent.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/main/"; -async function spblitzscript(baseUrl: string, fileName: string) { +async function spblitzscript(baseUrl: string, fileName: string, context?: sqlops.ObjectExplorerContext) { + if(context) { vscode.window.showInformationMessage("context before get: "+ context.connectionProfile.id)}; let options = { uri: baseUrl + fileName, }; console.log('Bringing in the first responder kit from the mothership.'); const scriptText = await request.get(options); - new placeScript().placescript(fileName,scriptText); + if(context) { vscode.window.showInformationMessage("context after get: "+ context.connectionProfile.id)}; + new placeScript().placescript(fileName, scriptText, context); } //importing all first responder kit scripts -export let getblitzall = async () => { - await spblitzscript(baseUrl, "Install-All-Scripts.sql"); +export let getblitzall = async (context?: sqlops.ObjectExplorerContext) => { + await spblitzscript(baseUrl, "Install-All-Scripts.sql", context); }; export let disposable_spblitzall = vscode.commands.registerCommand('extension.sp_blitzall', getblitzall); diff --git a/src/placescript.ts b/src/placescript.ts index 30ff1c3..ce55a52 100644 --- a/src/placescript.ts +++ b/src/placescript.ts @@ -4,15 +4,35 @@ import * as sqlops from 'azdata'; import * as vscode from 'vscode'; export class placeScript { + + private connectionId: string = ''; + private dbName: string = ''; // places scriptText into fileName editor with current connection public async placescript(fileName, scriptText, context?: sqlops.ObjectExplorerContext) { - var setting: vscode.Uri = vscode.Uri.parse("untitled:" + fileName); try { - let doc = await vscode.workspace.openTextDocument(setting); - let editor = await vscode.window.showTextDocument(doc, 1, false); + let connection; + if (context) { + let connection = context.connectionProfile; + this.connectionId = connection.id; + this.dbName = context.connectionProfile.databaseName; + await vscode.commands.executeCommand('explorer.query', context.connectionProfile); + } else { + await vscode.commands.executeCommand('newQuery'); + } + + let editor = vscode.window.activeTextEditor; + let doc = editor.document; editor.edit(edit => { edit.insert(new vscode.Position(0, 0), scriptText); }); + + if (context && this.dbName) { + let providerName = context.connectionProfile.providerName; + let dProvider = await sqlops.dataprotocol.getProvider(providerName, sqlops.DataProviderType.ConnectionProvider); + let connectionUri = await sqlops.connection.getUriForConnection(this.connectionId); + await dProvider.changeDatabase(connectionUri,this.dbName); + await sqlops.queryeditor.connect(doc.uri.toString(), this.connectionId); + } } catch (err) { vscode.window.showErrorMessage(err); } diff --git a/src/updateCheck.ts b/src/updateCheck.ts index da505f7..7b76899 100644 --- a/src/updateCheck.ts +++ b/src/updateCheck.ts @@ -9,11 +9,14 @@ let apiconfig: apiConfig.apiconfig = require('../apiconfig.json'); // checking spblitz versioning let getblitzversion = async (context?: sqlops.ObjectExplorerContext) => { - // var amIUPD = new updatecheck(); let updateReturn = await checkForUpdates(context); if (updateReturn) { if (updateReturn == 'update') { - getblitzall(); + if (context) { + getblitzall(context); + } else { + getblitzall(); + } } else if (updateReturn != '') { let versionURL = 'https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/releases/tag/' + updateReturn; vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(versionURL)); @@ -24,19 +27,25 @@ export let disposable_spblitzversion = vscode.commands.registerCommand('extensio async function checkForUpdates(context?: sqlops.ObjectExplorerContext): Promise { let baseUrl = "https://api.github.com/repos/BrentOzarULTD/SQL-Server-First-Responder-Kit/releases/latest"; - let apitoken = 'token ' + apiconfig.token; - vscode.window.showInformationMessage("Checking First Responder Kit for Updates"); try { var connectId; if (context) { let connection = context.connectionProfile; connectId = connection.id; + let connectionMaybe = await sqlops.connection.getCurrentConnection(); + if (!connectionMaybe) { + throw("Connect to server before checking First Responder Kit version."); + } } else { let connection = await sqlops.connection.getCurrentConnection(); + if (!connection) { + throw("Connect to server before checking First Responder Kit version."); + } connectId = connection.connectionId; } + vscode.window.showInformationMessage("Checking First Responder Kit for Updates"); let query = `declare @versionno datetime DECLARE @VERSION VARCHAR(30) @@ -55,61 +64,56 @@ async function checkForUpdates(context?: sqlops.ObjectExplorerContext): Promise< select convert(varchar(10),@versionno,112) as versionno`; - if (connectId) { - let connectionUri = await sqlops.connection.getUriForConnection(connectId); - let queryProvider = sqlops.dataprotocol.getProvider(context.connectionProfile.providerName, sqlops.DataProviderType.QueryProvider); - let results = await queryProvider.runQueryAndReturn(connectionUri, query); - let cell = results.rows[0][0]; - let currentVersion = cell.displayValue; + let connectionUri = await sqlops.connection.getUriForConnection(connectId); + let queryProvider = sqlops.dataprotocol.getProvider(context.connectionProfile.providerName, sqlops.DataProviderType.QueryProvider); + let results = await queryProvider.runQueryAndReturn(connectionUri, query); + let cell = results.rows[0][0]; + let currentVersion = cell.displayValue; - //get live most recent version from github - var options = { - uri: baseUrl, - headers: { - 'Authorization': apitoken, - 'User-Agent': 'Request-Promise' - }, - json: true, - simple: false - }; - var scriptText = await request.get(options); - let recentVersion = scriptText.tag_name; + //get live most recent version from github + var options = { + uri: baseUrl, + headers: { + 'Authorization': apitoken, + 'User-Agent': 'Request-Promise' + }, + json: true, + simple: false + }; + var scriptText = await request.get(options); + let recentVersion = scriptText.tag_name; - //compare against db version - if (currentVersion == '19000101') { - let updateMsg = 'First Responder Kit not detected on this server. Current version of First Responder Kit is ' + recentVersion + '.' - var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More"); - if (buttonName){ - if (buttonName == "Get It Now") { - return 'update'; - } else if (buttonName == "Tell Me More") { - return recentVersion; - } - } else { - return ''; + //compare against db version + if (currentVersion == '19000101') { + let updateMsg = 'First Responder Kit not detected on this server. Current version of First Responder Kit is ' + recentVersion + '.' + var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More"); + if (buttonName){ + if (buttonName == "Get It Now") { + return 'update'; + } else if (buttonName == "Tell Me More") { + return recentVersion; } + } else { + return ''; } - else if (recentVersion > currentVersion) { - let updateMsg = 'New Version of First Responder Kit available (' + recentVersion + '). You have version ' + currentVersion +'.' - var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More"); - if (buttonName){ - if (buttonName == "Get It Now") { - return 'update'; - } else if (buttonName == "Tell Me More") { - return recentVersion; - } - } else { - return ''; + } + else if (recentVersion > currentVersion) { + let updateMsg = 'New Version of First Responder Kit available (' + recentVersion + '). You have version ' + currentVersion +'.' + var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More"); + if (buttonName){ + if (buttonName == "Get It Now") { + return 'update'; + } else if (buttonName == "Tell Me More") { + return recentVersion; } } else { - vscode.window.showInformationMessage("You're up to date!", {modal:false}, "Close"); return ''; } - } else { - vscode.window.showErrorMessage("Please connect to SQL server to check First Responder Kit version."); + vscode.window.showInformationMessage("You're up to date!", {modal:false}, "Close"); return ''; } + } catch (e) { vscode.window.showErrorMessage(e); }