From 8d9630753dcb68ebe8dfedbcc3d899558c0e9783 Mon Sep 17 00:00:00 2001 From: Drew Skwiers-Koballa Date: Fri, 11 Sep 2020 14:11:55 -0700 Subject: [PATCH 1/3] workstation freaking out --- .vscode/settings.json | 9 --------- package-lock.json | 2 +- package.json | 2 +- src/extension.ts | 36 +++++++++++++++++++++++++----------- src/getScripts.ts | 11 +++++++---- src/placescript.ts | 27 ++++++++++++++++++++++++--- src/updateCheck.ts | 9 +++++++-- 7 files changed, 65 insertions(+), 31 deletions(-) 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/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..06897a6 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" diff --git a/src/extension.ts b/src/extension.ts index 48ccb5d..f8ddc29 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,9 +10,11 @@ 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 + vscode.window.showInformationMessage("loaded the updated version 4"); + + // documentation help link let currentBlitz: string = 'sp_Blitz'; + let timeout: NodeJS.Timer | null = null; var docsspblitz = () => { openDocumentation(baseUrl, currentBlitz); }; @@ -24,15 +26,18 @@ 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' + vscode.window.showInformationMessage("checking editor for spblitz"); + let blitzes: string[] = ['sp_Blitz', 'sp_BlitzCache', 'sp_BlitzIndex', 'sp_BlitzWho', 'sp_BlitzFirst' , 'sp_BlitzInMemoryOLTP', 'sp_BlitzLock', 'sp_BlitzQueryStore', 'sp_BlitzBackups']; - let editorText: string = vscode.window.activeTextEditor.document.getText(); 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; + } + }); + } if (blitzLabel != "") { docsStatusBar.text = '$(question) ' + blitzLabel + ' Documentation'; docsStatusBar.show(); @@ -41,8 +46,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, 700); + } + + 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..049a61a 100644 --- a/src/placescript.ts +++ b/src/placescript.ts @@ -4,15 +4,36 @@ 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) { + vscode.window.showInformationMessage("context in placescript: "+ context.connectionProfile.id) + 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..dfa8f32 100644 --- a/src/updateCheck.ts +++ b/src/updateCheck.ts @@ -9,11 +9,16 @@ let apiconfig: apiConfig.apiconfig = require('../apiconfig.json'); // checking spblitz versioning let getblitzversion = async (context?: sqlops.ObjectExplorerContext) => { - // var amIUPD = new updatecheck(); + if(context) { vscode.window.showInformationMessage("context going in to update check: "+context.connectionProfile.id)}; let updateReturn = await checkForUpdates(context); if (updateReturn) { if (updateReturn == 'update') { - getblitzall(); + if(context) { vscode.window.showInformationMessage("context after checking for update: "+ context.connectionProfile.id)}; + 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)); From 1cbb8f39d70c58fb83c1fbd550f7dd7f63fb3bc9 Mon Sep 17 00:00:00 2001 From: Drew Skwiers-Koballa Date: Fri, 18 Sep 2020 19:46:39 -0700 Subject: [PATCH 2/3] edge case cleanup --- src/extension.ts | 9 ++--- src/placescript.ts | 1 - src/updateCheck.ts | 95 +++++++++++++++++++++++----------------------- 3 files changed, 50 insertions(+), 55 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index f8ddc29..5753424 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,7 +10,6 @@ import * as runScripts from './runScripts'; export function activate(context: vscode.ExtensionContext) { const baseUrl = "https://raw.githubusercontent.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/main/"; - vscode.window.showInformationMessage("loaded the updated version 4"); // documentation help link let currentBlitz: string = 'sp_Blitz'; @@ -26,15 +25,13 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(docsStatusBar); function checkSpBlitzType() : void { - vscode.window.showInformationMessage("checking editor for spblitz"); - let blitzes: string[] = ['sp_Blitz', 'sp_BlitzCache', 'sp_BlitzIndex', 'sp_BlitzWho', 'sp_BlitzFirst' - , 'sp_BlitzInMemoryOLTP', 'sp_BlitzLock', 'sp_BlitzQueryStore', 'sp_BlitzBackups']; + let blitzes: string[] = ['sp_Blitz', 'sp_BlitzIndex', 'sp_BlitzCache', 'sp_BlitzWho', 'sp_BlitzFirst', 'sp_BlitzLock', 'sp_Blitz\'']; let blitzLabel: string = ""; if (vscode.window.activeTextEditor) { let editorText: string = vscode.window.activeTextEditor.document.getText(); blitzes.forEach( blitz => { if (editorText.toLowerCase().includes(blitz.toLowerCase())) { - blitzLabel = blitz; + blitzLabel = blitz.replace('\'',''); } }); } @@ -51,7 +48,7 @@ export function activate(context: vscode.ExtensionContext) { if (timeout) { clearTimeout(timeout); } - timeout = setTimeout(checkSpBlitzType, 700); + timeout = setTimeout(checkSpBlitzType, 1000); // wait a second to avoid hammering } context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(triggerUpdateDocLink)); diff --git a/src/placescript.ts b/src/placescript.ts index 049a61a..ce55a52 100644 --- a/src/placescript.ts +++ b/src/placescript.ts @@ -12,7 +12,6 @@ export class placeScript { try { let connection; if (context) { - vscode.window.showInformationMessage("context in placescript: "+ context.connectionProfile.id) let connection = context.connectionProfile; this.connectionId = connection.id; this.dbName = context.connectionProfile.databaseName; diff --git a/src/updateCheck.ts b/src/updateCheck.ts index dfa8f32..7b76899 100644 --- a/src/updateCheck.ts +++ b/src/updateCheck.ts @@ -9,11 +9,9 @@ let apiconfig: apiConfig.apiconfig = require('../apiconfig.json'); // checking spblitz versioning let getblitzversion = async (context?: sqlops.ObjectExplorerContext) => { - if(context) { vscode.window.showInformationMessage("context going in to update check: "+context.connectionProfile.id)}; let updateReturn = await checkForUpdates(context); if (updateReturn) { if (updateReturn == 'update') { - if(context) { vscode.window.showInformationMessage("context after checking for update: "+ context.connectionProfile.id)}; if (context) { getblitzall(context); } else { @@ -29,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) @@ -60,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); } From c0a97aa7ddd5d93ddcabd07dd2c3c13c6080ee8d Mon Sep 17 00:00:00 2001 From: Drew Skwiers-Koballa Date: Fri, 18 Sep 2020 20:02:28 -0700 Subject: [PATCH 3/3] 0.6.0 release --- README.md | 7 ++++++- package.json | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) 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.json b/package.json index 06897a6..e18931d 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "activationEvents": [ "*" ], - "main": "./out/extension", + "main": "./dist/extension", "contributes": { "commands": [ {