Skip to content

Commit 36c98b4

Browse files
authored
Merge pull request #30 from dzsquared/dev-0.6.0
release 0.6.0
2 parents acb6dd4 + c0a97aa commit 36c98b4

8 files changed

+114
-80
lines changed

.vscode/settings.json

-9
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,5 @@
55
},
66
"search.exclude": {
77
"out": true // set this to false to include "out" folder in search results
8-
},
9-
"terminal.integrated.env.osx": {
10-
"SFDX_SET_CLIENT_IDS": "sfdx-vscode"
11-
},
12-
"terminal.integrated.env.linux": {
13-
"SFDX_SET_CLIENT_IDS": "sfdx-vscode"
14-
},
15-
"terminal.integrated.env.windows": {
16-
"SFDX_SET_CLIENT_IDS": "sfdx-vscode"
178
}
189
}

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This extension provides immediate access to the current First Responder Kit scripts and introductory execution suggestions. (All credit due to http://firstresponderkit.org/)
44

55
## Installation
6-
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...`
6+
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...`
77

88

99
## Features
@@ -52,6 +52,11 @@ Can be raised here: https://github.com/dzsquared/sqlops-firstresponderkit/issues
5252

5353
## Release Notes
5454

55+
### 0.6.0
56+
57+
- Fix for extension unable to pull scripts from GitHub. Change to utilizing `main` branch of First Responder Kit.
58+
- Adds interactive documentation linking to status bar.
59+
5560
### 0.5.1
5661

5762
- Fix for changes to new editor connection changes in Azure Data Studio 1.15.0

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"publisher": "drewsk",
77
"engines": {
88
"vscode": "^1.25.0",
9-
"azdata": "^1.15.0"
9+
"azdata": "^1.21.0"
1010
},
1111
"categories": [
1212
"Other"
@@ -18,7 +18,7 @@
1818
"activationEvents": [
1919
"*"
2020
],
21-
"main": "./out/extension",
21+
"main": "./dist/extension",
2222
"contributes": {
2323
"commands": [
2424
{

src/extension.ts

+23-12
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import * as runScripts from './runScripts';
1010

1111
export function activate(context: vscode.ExtensionContext) {
1212
const baseUrl = "https://raw.githubusercontent.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/main/";
13-
14-
// documentation
13+
14+
// documentation help link
1515
let currentBlitz: string = 'sp_Blitz';
16+
let timeout: NodeJS.Timer | null = null;
1617
var docsspblitz = () => {
1718
openDocumentation(baseUrl, currentBlitz);
1819
};
@@ -24,15 +25,16 @@ export function activate(context: vscode.ExtensionContext) {
2425
context.subscriptions.push(docsStatusBar);
2526

2627
function checkSpBlitzType() : void {
27-
let blitzes: string[] = ['sp_Blitz', 'sp_BlitzCache', 'sp_BlitzIndex', 'sp_BlitzFirst', 'sp_BlitzWho'
28-
, 'sp_BlitzInMemoryOLTP', 'sp_BlitzLock', 'sp_BlitzQueryStore', 'sp_BlitzBackups'];
29-
let editorText: string = vscode.window.activeTextEditor.document.getText();
28+
let blitzes: string[] = ['sp_Blitz', 'sp_BlitzIndex', 'sp_BlitzCache', 'sp_BlitzWho', 'sp_BlitzFirst', 'sp_BlitzLock', 'sp_Blitz\''];
3029
let blitzLabel: string = "";
31-
blitzes.forEach( blitz => {
32-
if (editorText.toLowerCase().includes(blitz.toLowerCase())) {
33-
blitzLabel = blitz;
34-
}
35-
});
30+
if (vscode.window.activeTextEditor) {
31+
let editorText: string = vscode.window.activeTextEditor.document.getText();
32+
blitzes.forEach( blitz => {
33+
if (editorText.toLowerCase().includes(blitz.toLowerCase())) {
34+
blitzLabel = blitz.replace('\'','');
35+
}
36+
});
37+
}
3638
if (blitzLabel != "") {
3739
docsStatusBar.text = '$(question) ' + blitzLabel + ' Documentation';
3840
docsStatusBar.show();
@@ -41,8 +43,17 @@ export function activate(context: vscode.ExtensionContext) {
4143
}
4244
currentBlitz = blitzLabel;
4345
}
44-
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(checkSpBlitzType));
45-
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(checkSpBlitzType));
46+
47+
function triggerUpdateDocLink() {
48+
if (timeout) {
49+
clearTimeout(timeout);
50+
}
51+
timeout = setTimeout(checkSpBlitzType, 1000); // wait a second to avoid hammering
52+
}
53+
54+
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(triggerUpdateDocLink));
55+
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(triggerUpdateDocLink));
56+
context.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(triggerUpdateDocLink));
4657

4758
context.subscriptions.push(disposable_spblitzversion);
4859

src/getScripts.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
'use strict';
22
import * as vscode from 'vscode';
3+
import * as sqlops from 'azdata';
34
import * as request from 'request-promise-native';
45
import {placeScript} from './placescript';
56

67
const baseUrl = "https://raw.githubusercontent.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/main/";
78

8-
async function spblitzscript(baseUrl: string, fileName: string) {
9+
async function spblitzscript(baseUrl: string, fileName: string, context?: sqlops.ObjectExplorerContext) {
10+
if(context) { vscode.window.showInformationMessage("context before get: "+ context.connectionProfile.id)};
911
let options = {
1012
uri: baseUrl + fileName,
1113
};
1214
console.log('Bringing in the first responder kit from the mothership.');
1315
const scriptText = await request.get(options);
14-
new placeScript().placescript(fileName,scriptText);
16+
if(context) { vscode.window.showInformationMessage("context after get: "+ context.connectionProfile.id)};
17+
new placeScript().placescript(fileName, scriptText, context);
1518
}
1619

1720
//importing all first responder kit scripts
18-
export let getblitzall = async () => {
19-
await spblitzscript(baseUrl, "Install-All-Scripts.sql");
21+
export let getblitzall = async (context?: sqlops.ObjectExplorerContext) => {
22+
await spblitzscript(baseUrl, "Install-All-Scripts.sql", context);
2023
};
2124
export let disposable_spblitzall = vscode.commands.registerCommand('extension.sp_blitzall', getblitzall);
2225

src/placescript.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,35 @@ import * as sqlops from 'azdata';
44
import * as vscode from 'vscode';
55

66
export class placeScript {
7+
8+
private connectionId: string = '';
9+
private dbName: string = '';
710
// places scriptText into fileName editor with current connection
811
public async placescript(fileName, scriptText, context?: sqlops.ObjectExplorerContext) {
9-
var setting: vscode.Uri = vscode.Uri.parse("untitled:" + fileName);
1012
try {
11-
let doc = await vscode.workspace.openTextDocument(setting);
12-
let editor = await vscode.window.showTextDocument(doc, 1, false);
13+
let connection;
14+
if (context) {
15+
let connection = context.connectionProfile;
16+
this.connectionId = connection.id;
17+
this.dbName = context.connectionProfile.databaseName;
18+
await vscode.commands.executeCommand('explorer.query', context.connectionProfile);
19+
} else {
20+
await vscode.commands.executeCommand('newQuery');
21+
}
22+
23+
let editor = vscode.window.activeTextEditor;
24+
let doc = editor.document;
1325
editor.edit(edit => {
1426
edit.insert(new vscode.Position(0, 0), scriptText);
1527
});
28+
29+
if (context && this.dbName) {
30+
let providerName = context.connectionProfile.providerName;
31+
let dProvider = await sqlops.dataprotocol.getProvider<sqlops.ConnectionProvider>(providerName, sqlops.DataProviderType.ConnectionProvider);
32+
let connectionUri = await sqlops.connection.getUriForConnection(this.connectionId);
33+
await dProvider.changeDatabase(connectionUri,this.dbName);
34+
await sqlops.queryeditor.connect(doc.uri.toString(), this.connectionId);
35+
}
1636
} catch (err) {
1737
vscode.window.showErrorMessage(err);
1838
}

src/updateCheck.ts

+52-48
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ let apiconfig: apiConfig.apiconfig = require('../apiconfig.json');
99

1010
// checking spblitz versioning
1111
let getblitzversion = async (context?: sqlops.ObjectExplorerContext) => {
12-
// var amIUPD = new updatecheck();
1312
let updateReturn = await checkForUpdates(context);
1413
if (updateReturn) {
1514
if (updateReturn == 'update') {
16-
getblitzall();
15+
if (context) {
16+
getblitzall(context);
17+
} else {
18+
getblitzall();
19+
}
1720
} else if (updateReturn != '') {
1821
let versionURL = 'https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/releases/tag/' + updateReturn;
1922
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(versionURL));
@@ -24,19 +27,25 @@ export let disposable_spblitzversion = vscode.commands.registerCommand('extensio
2427

2528
async function checkForUpdates(context?: sqlops.ObjectExplorerContext): Promise<string> {
2629
let baseUrl = "https://api.github.com/repos/BrentOzarULTD/SQL-Server-First-Responder-Kit/releases/latest";
27-
2830
let apitoken = 'token ' + apiconfig.token;
29-
vscode.window.showInformationMessage("Checking First Responder Kit for Updates");
3031

3132
try {
3233
var connectId;
3334
if (context) {
3435
let connection = context.connectionProfile;
3536
connectId = connection.id;
37+
let connectionMaybe = await sqlops.connection.getCurrentConnection();
38+
if (!connectionMaybe) {
39+
throw("Connect to server before checking First Responder Kit version.");
40+
}
3641
} else {
3742
let connection = await sqlops.connection.getCurrentConnection();
43+
if (!connection) {
44+
throw("Connect to server before checking First Responder Kit version.");
45+
}
3846
connectId = connection.connectionId;
3947
}
48+
vscode.window.showInformationMessage("Checking First Responder Kit for Updates");
4049

4150
let query = `declare @versionno datetime
4251
DECLARE @VERSION VARCHAR(30)
@@ -55,61 +64,56 @@ async function checkForUpdates(context?: sqlops.ObjectExplorerContext): Promise<
5564
5665
select convert(varchar(10),@versionno,112) as versionno`;
5766

58-
if (connectId) {
59-
let connectionUri = await sqlops.connection.getUriForConnection(connectId);
60-
let queryProvider = sqlops.dataprotocol.getProvider<sqlops.QueryProvider>(context.connectionProfile.providerName, sqlops.DataProviderType.QueryProvider);
61-
let results = await queryProvider.runQueryAndReturn(connectionUri, query);
62-
let cell = results.rows[0][0];
63-
let currentVersion = cell.displayValue;
67+
let connectionUri = await sqlops.connection.getUriForConnection(connectId);
68+
let queryProvider = sqlops.dataprotocol.getProvider<sqlops.QueryProvider>(context.connectionProfile.providerName, sqlops.DataProviderType.QueryProvider);
69+
let results = await queryProvider.runQueryAndReturn(connectionUri, query);
70+
let cell = results.rows[0][0];
71+
let currentVersion = cell.displayValue;
6472

65-
//get live most recent version from github
66-
var options = {
67-
uri: baseUrl,
68-
headers: {
69-
'Authorization': apitoken,
70-
'User-Agent': 'Request-Promise'
71-
},
72-
json: true,
73-
simple: false
74-
};
75-
var scriptText = await request.get(options);
76-
let recentVersion = scriptText.tag_name;
73+
//get live most recent version from github
74+
var options = {
75+
uri: baseUrl,
76+
headers: {
77+
'Authorization': apitoken,
78+
'User-Agent': 'Request-Promise'
79+
},
80+
json: true,
81+
simple: false
82+
};
83+
var scriptText = await request.get(options);
84+
let recentVersion = scriptText.tag_name;
7785

78-
//compare against db version
79-
if (currentVersion == '19000101') {
80-
let updateMsg = 'First Responder Kit not detected on this server. Current version of First Responder Kit is ' + recentVersion + '.'
81-
var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More");
82-
if (buttonName){
83-
if (buttonName == "Get It Now") {
84-
return 'update';
85-
} else if (buttonName == "Tell Me More") {
86-
return recentVersion;
87-
}
88-
} else {
89-
return '';
86+
//compare against db version
87+
if (currentVersion == '19000101') {
88+
let updateMsg = 'First Responder Kit not detected on this server. Current version of First Responder Kit is ' + recentVersion + '.'
89+
var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More");
90+
if (buttonName){
91+
if (buttonName == "Get It Now") {
92+
return 'update';
93+
} else if (buttonName == "Tell Me More") {
94+
return recentVersion;
9095
}
96+
} else {
97+
return '';
9198
}
92-
else if (recentVersion > currentVersion) {
93-
let updateMsg = 'New Version of First Responder Kit available (' + recentVersion + '). You have version ' + currentVersion +'.'
94-
var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More");
95-
if (buttonName){
96-
if (buttonName == "Get It Now") {
97-
return 'update';
98-
} else if (buttonName == "Tell Me More") {
99-
return recentVersion;
100-
}
101-
} else {
102-
return '';
99+
}
100+
else if (recentVersion > currentVersion) {
101+
let updateMsg = 'New Version of First Responder Kit available (' + recentVersion + '). You have version ' + currentVersion +'.'
102+
var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More");
103+
if (buttonName){
104+
if (buttonName == "Get It Now") {
105+
return 'update';
106+
} else if (buttonName == "Tell Me More") {
107+
return recentVersion;
103108
}
104109
} else {
105-
vscode.window.showInformationMessage("You're up to date!", {modal:false}, "Close");
106110
return '';
107111
}
108-
109112
} else {
110-
vscode.window.showErrorMessage("Please connect to SQL server to check First Responder Kit version.");
113+
vscode.window.showInformationMessage("You're up to date!", {modal:false}, "Close");
111114
return '';
112115
}
116+
113117
} catch (e) {
114118
vscode.window.showErrorMessage(e);
115119
}

0 commit comments

Comments
 (0)