Skip to content

Commit c4db641

Browse files
committed
detecting correct connection from object explorer context
1 parent 46a46d5 commit c4db641

5 files changed

Lines changed: 35 additions & 113 deletions

File tree

package.json

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,11 @@
1616
"url": "https://github.com/dzsquared/sqlops-firstresponderkit.git"
1717
},
1818
"activationEvents": [
19-
"onCommand:extension.sp_blitzversion",
20-
"onCommand:extension.sp_blitz",
21-
"onCommand:extension.run_sp_blitz",
22-
"onCommand:extension.sp_blitzwho",
23-
"onCommand:extension.sp_blitzindex",
24-
"onCommand:extension.run_sp_blitzindex",
25-
"onCommand:extension.sp_blitzcache",
26-
"onCommand:extension.run_sp_blitzcache",
27-
"onCommand:extension.sp_blitzfirst",
28-
"onCommand:extension.run_sp_blitzfirst",
2919
"*"
3020
],
3121
"main": "./out/extension",
3222
"contributes": {
3323
"commands": [
34-
{
35-
"command": "extension.OEdiagnostics",
36-
"title": "First Responder Kit: Node Info"
37-
},
3824
{
3925
"command": "extension.sp_blitzversion",
4026
"title": "First Responder Kit: Check sp_blitz Version"
@@ -88,11 +74,6 @@
8874
],
8975
"menus": {
9076
"objectExplorer/item/context": [
91-
{
92-
"command": "extension.OEdiagnostics",
93-
"when": "connectionProvider == MSSQL",
94-
"group": "FRK"
95-
},
9677
{
9778
"command": "extension.sp_blitzversion",
9879
"when": "connectionProvider == MSSQL && nodeType && nodeType == Server",

snippets/snippets.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"@CheckProcedureCacheFilter = NULL,",
1111
"@CheckServerInfo = 1",
1212
"-- uncomment the following line to write results to an output table",
13-
"--, @OutputDatabaseName = 'DBAtools', @OutputSchemaName = 'dbo', @OutputTableName = 'BlitzResults'"
13+
"--, @OutputDatabaseName = 'DBAtools', @OutputSchemaName = 'dbo', @OutputTableName = 'BlitzResults'",
14+
"-- for more info: https://www.brentozar.com/blitz/"
1415
],
1516
"description": "sp_blitz execution script"
1617
},
@@ -21,7 +22,8 @@
2122
"@DatabaseName = '${1:DatabaseName}',",
2223
"--@TableName = '${2:TableName}'",
2324
"--@Mode = 4",
24-
"--0=Diagnose, 1=Summarize, 2=Index Usage Detail, 3=Missing Index Detail, 4=Diagnose Details"
25+
"--0=Diagnose, 1=Summarize, 2=Index Usage Detail, 3=Missing Index Detail, 4=Diagnose Details",
26+
"-- for more info: https://www.brentozar.com/blitzindex/"
2527
],
2628
"description": "sp_blitzindex execution script"
2729
},
@@ -31,7 +33,8 @@
3133
"EXEC [dbo].[sp_BlitzCache]",
3234
"@SortOrder = 'reads',",
3335
" -- CPU, executions, xpm, recent compilations, memory grant, writes, all",
34-
"@Top = 10"
36+
"@Top = 10",
37+
"-- for more info: https://www.brentozar.com/blitzcache/"
3538
],
3639
"description": "sp_blitzcache execution script"
3740
},
@@ -41,7 +44,8 @@
4144
"EXEC [dbo].[sp_BlitzFirst]",
4245
"@Seconds = 5,",
4346
"@ShowSleepingSPIDs = 0,",
44-
"@ExpertMode = 0 --1 will also run sp_BlitzWho"
47+
"@ExpertMode = 0 --1 will also run sp_BlitzWho",
48+
"-- for more info: https://www.brentozar.com/askbrent/"
4549
],
4650
"description": "sp_blitzfirst execution script"
4751
}

src/blitzindex.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/extension.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import * as sqlops from 'sqlops';
55
import { error } from 'util';
66
import {placeScript} from './placescript';
77
import {updatecheck} from './updateCheck';
8-
// import {BlitzIndex} from './blitzindex';
98

109
export function activate(context: vscode.ExtensionContext) {
1110
const baseUrl = "https://raw.githubusercontent.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/master/";
1211

13-
1412
// checking spblitz versioning
1513
var oediag = async (context: sqlops.ObjectExplorerContext) => {
1614
vscode.window.showInformationMessage(context.isConnectionNode.toString());
@@ -25,15 +23,13 @@ export function activate(context: vscode.ExtensionContext) {
2523
var amIUPD = new updatecheck();
2624
let updateReturn = await amIUPD.checkForUpdates(context);
2725

28-
//vscode.window.showInformationMessage(updateReturn);
2926
if (updateReturn == 'update') {
3027
getblitzall();
3128
} else if (updateReturn != '') {
3229
let versionURL = 'https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/releases/tag/' + updateReturn;
3330
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(versionURL));
3431
} else {
3532
// do nothing
36-
vscode.window.showErrorMessage("Sorry about this. Please report the issue on Github.");
3733
}
3834
};
3935
var disposable_spblitzversion = vscode.commands.registerCommand('extension.sp_blitzversion', getblitzversion);
@@ -48,63 +44,58 @@ export function activate(context: vscode.ExtensionContext) {
4844
};
4945
console.log('Bringing in the first responder kit from the mothership.');
5046
const scriptText = await request.get(options);
51-
//await placeScript.placescript(fileName, scriptText);
5247
new placeScript().placescript(fileName,scriptText);
5348
};
5449
var disposable_spblitzall = vscode.commands.registerCommand('extension.sp_blitzall', getblitzall);
5550
context.subscriptions.push(disposable_spblitzall);
5651

57-
//importing the original spblitz script
52+
//importing spblitz script
5853
var getblitz = async () => {
5954
let fileName = "sp_Blitz.sql";
6055
var options = {
6156
uri: baseUrl + fileName,
6257
};
6358
console.log('Bringing in the first responder kit from the mothership.');
6459
const scriptText = await request.get(options);
65-
//await placeScript.placescript(fileName, scriptText);
6660
new placeScript().placescript(fileName,scriptText);
6761
};
6862
var disposable_spblitz = vscode.commands.registerCommand('extension.sp_blitz', getblitz);
6963
context.subscriptions.push(disposable_spblitz);
7064

71-
//importing the full spblitzcache script
65+
//importing spblitzcache script
7266
var getblitzcache = async () => {
7367
let fileName = "sp_BlitzCache.sql";
7468
var options = {
7569
uri: baseUrl + fileName,
7670
};
7771
console.log('Bringing in the first responder kit from the mothership.');
7872
const scriptText = await request.get(options);
79-
//await placeScript.placescript(fileName, scriptText);
8073
new placeScript().placescript(fileName,scriptText);
8174
};
8275
var disposable_spblitzcache = vscode.commands.registerCommand('extension.sp_blitzcache', getblitzcache);
8376
context.subscriptions.push(disposable_spblitzcache);
8477

85-
//importing the full spblitzfirst script
78+
//importing spblitzfirst script
8679
var getblitzfirst = async () => {
8780
let fileName = "sp_BlitzFirst.sql";
8881
var options = {
8982
uri: baseUrl + fileName,
9083
};
9184
console.log('Bringing in the first responder kit from the mothership.');
9285
const scriptText = await request.get(options);
93-
//await placeScript.placescript(fileName, scriptText);
9486
new placeScript().placescript(fileName,scriptText);
9587
};
9688
var disposable_spblitzfirst = vscode.commands.registerCommand('extension.sp_blitzfirst', getblitzfirst);
9789
context.subscriptions.push(disposable_spblitzfirst);
9890

99-
//importing the spblitzwho script
91+
//importing spblitzwho script
10092
var getblitzwho = async () => {
10193
let fileName = "sp_BlitzWho.sql";
10294
var options = {
10395
uri: baseUrl + fileName,
10496
};
10597
console.log('Bringing in the first responder kit from the mothership.');
10698
const scriptText = await request.get(options);
107-
//await placeScript.placescript(fileName, scriptText);
10899
new placeScript().placescript(fileName,scriptText);
109100
};
110101
var disposable_spblitzwho = vscode.commands.registerCommand('extension.sp_blitzwho', getblitzwho);
@@ -127,27 +118,25 @@ export function activate(context: vscode.ExtensionContext) {
127118
-- for more info: https://www.brentozar.com/blitz/
128119
`;
129120
var setting: vscode.Uri = vscode.Uri.parse("untitled:" + fileName);
130-
//await placeScript.placescript(fileName, scriptText);
131121
new placeScript().placescript(fileName,scriptText);
132122
};
133123
var disposable_runspblitz = vscode.commands.registerCommand('extension.run_sp_blitz', runspblitz);
134124
context.subscriptions.push(disposable_runspblitz);
135125

136-
//importing the full spblitz script
126+
//importing spblitzindex script
137127
var getblitzindex = async () => {
138128
let fileName = "sp_BlitzIndex.sql";
139129
var options = {
140130
uri: baseUrl + fileName,
141131
};
142132
console.log('Bringing in the first responder kit from the mothership.');
143133
const scriptText = await request.get(options);
144-
//await placeScript.placescript(fileName, scriptText);
145134
new placeScript().placescript(fileName,scriptText);
146135
};
147136
var disposable_spblitzindex = vscode.commands.registerCommand('extension.sp_blitzindex', getblitzindex);
148137
context.subscriptions.push(disposable_spblitzindex);
149138

150-
//creating the quickrun script
139+
//creating the quickrun script for blitzindex
151140
var runspblitzindex = async (context?: sqlops.ObjectExplorerContext) => {
152141
console.log('Preparing sample run script.');
153142
let fileName = "exec_sp_blitzindex.sql";
@@ -212,13 +201,12 @@ export function activate(context: vscode.ExtensionContext) {
212201
213202
-- for more info: https://www.brentozar.com/blitzcache/
214203
`;
215-
//await placeScript.placescript(fileName, scriptText);
216204
new placeScript().placescript(fileName,scriptText);
217205
};
218206
var disposable_runspblitzcache = vscode.commands.registerCommand('extension.run_sp_blitzcache',runspblitzcache)
219207
context.subscriptions.push(disposable_runspblitzcache);
220208

221-
//creating the quickrun script
209+
//creating the quickrun script for blitzfirst
222210
var runspblitzfirst = async () => {
223211
let fileName = "exec_sp_blitzfirst.sql";
224212
console.log('Preparing sample run script.');
@@ -229,16 +217,13 @@ export function activate(context: vscode.ExtensionContext) {
229217
230218
-- for more info: https://www.brentozar.com/askbrent/
231219
`;
232-
//await placeScript.placescript(fileName, scriptText);
233220
new placeScript().placescript(fileName,scriptText);
234221
};
235222
var disposable_runspblitzfirst = vscode.commands.registerCommand('extension.run_sp_blitzfirst',runspblitzfirst);
236223
context.subscriptions.push(disposable_runspblitzfirst);
237224

238225
}
239226

240-
241-
// this method is called when your extension is deactivated
242227
export function deactivate() {
243228
}
244229

src/updateCheck.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as sqlops from 'sqlops';
44
import * as vscode from 'vscode';
55
import * as request from 'request-promise-native';
66
import * as apiConfig from './apiconfig';
7-
import { STATUS_CODES } from 'http';
87
let apiconfig: apiConfig.apiconfig = require('../apiconfig.json');
98

109
export class updatecheck {
@@ -15,21 +14,21 @@ export class updatecheck {
1514
let queryProvider = sqlops.dataprotocol.getProvider<sqlops.QueryProvider>(context.connectionProfile.providerName, sqlops.DataProviderType.QueryProvider);
1615
vscode.window.showInformationMessage("Checking First Responder Kit for Updates");
1716
try {
18-
let connection = await sqlops.connection.getCurrentConnection();
17+
let connection = context.connectionProfile;
1918
let query = `declare @versionno datetime
2019
IF OBJECT_ID('dbo.sp_Blitz') IS NULL
2120
set @versionno = '1/1/1900'
2221
ELSE
2322
exec sp_blitz @help = 1, @versiondate = @versionno output
2423
select convert(varchar(10),@versionno,112) as versionno`;
2524

26-
let connectionUri = await sqlops.connection.getUriForConnection(connection.connectionId);
25+
let connectionUri = await sqlops.connection.getUriForConnection(connection.id);
2726
if (connection) {
2827
let results = await queryProvider.runQueryAndReturn(connectionUri, query);
2928
let cell = results.rows[0][0];
3029
let currentVersion = cell.displayValue;
3130

32-
//get live most recent version
31+
//get live most recent version from github
3332
var options = {
3433
uri: baseUrl,
3534
headers: {
@@ -40,14 +39,27 @@ export class updatecheck {
4039
simple: false
4140
};
4241
var scriptText = await request.get(options);
43-
4442
let recentVersion = scriptText.tag_name;
43+
4544
//compare against db version
46-
if (recentVersion > currentVersion) {
45+
if (currentVersion == '19000101') {
46+
let updateMsg = 'First Responder Kit not detected on this server. Current version of First Responder Kit is ' + recentVersion + '.'
47+
var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More");
48+
if (buttonName){
49+
if (buttonName == "Get It Now") {
50+
return 'update';
51+
} else if (buttonName == "Tell Me More") {
52+
return recentVersion;
53+
}
54+
} else {
55+
return '';
56+
}
57+
}
58+
else if (recentVersion > currentVersion) {
4759
let updateMsg = 'New Version of First Responder Kit available (' + recentVersion + '). You have version ' + currentVersion +'.'
48-
var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It", "Tell Me More");
60+
var buttonName = await vscode.window.showInformationMessage(updateMsg, {modal:false}, "Get It Now", "Tell Me More");
4961
if (buttonName){
50-
if (buttonName == "Get It") {
62+
if (buttonName == "Get It Now") {
5163
return 'update';
5264
} else if (buttonName == "Tell Me More") {
5365
return recentVersion;

0 commit comments

Comments
 (0)