6
6
7
7
import path = require( "path" ) ;
8
8
import vscode = require( "vscode" ) ;
9
+ import TelemetryReporter from "vscode-extension-telemetry" ;
9
10
import { DocumentSelector } from "vscode-languageclient" ;
10
11
import { IFeature } from "./feature" ;
11
12
import { CodeActionsFeature } from "./features/CodeActions" ;
@@ -35,23 +36,33 @@ import Settings = require("./settings");
35
36
import { PowerShellLanguageId } from "./utils" ;
36
37
import utils = require( "./utils" ) ;
37
38
39
+ // The most reliable way to get the name and version of the current extension.
40
+ // tslint:disable-next-line: no-var-requires
41
+ const PackageJSON : any = require ( "../../package.json" ) ;
42
+
38
43
// NOTE: We will need to find a better way to deal with the required
39
44
// PS Editor Services version...
40
45
const requiredEditorServicesVersion = "1.12.1" ;
41
46
47
+ // the application insights key (also known as instrumentation key) used for telemetry.
48
+ const AI_KEY : string = "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217" ;
49
+
42
50
let logger : Logger ;
43
51
let sessionManager : SessionManager ;
44
52
let extensionFeatures : IFeature [ ] = [ ] ;
53
+ let telemetryReporter : TelemetryReporter ;
45
54
46
55
const documentSelector : DocumentSelector = [
47
56
{ language : "powershell" , scheme : "file" } ,
48
57
{ language : "powershell" , scheme : "untitled" } ,
49
58
] ;
50
59
51
60
export function activate ( context : vscode . ExtensionContext ) : void {
52
-
53
61
checkForUpdatedVersion ( context ) ;
54
62
63
+ // create telemetry reporter on extension activation
64
+ telemetryReporter = new TelemetryReporter ( PackageJSON . name , PackageJSON . version , AI_KEY ) ;
65
+
55
66
vscode . languages . setLanguageConfiguration (
56
67
PowerShellLanguageId ,
57
68
{
@@ -115,7 +126,9 @@ export function activate(context: vscode.ExtensionContext): void {
115
126
sessionManager =
116
127
new SessionManager (
117
128
requiredEditorServicesVersion ,
118
- logger , documentSelector ) ;
129
+ logger ,
130
+ documentSelector ,
131
+ telemetryReporter ) ;
119
132
120
133
// Create features
121
134
extensionFeatures = [
@@ -153,23 +166,15 @@ function checkForUpdatedVersion(context: vscode.ExtensionContext) {
153
166
154
167
const showReleaseNotes = "Show Release Notes" ;
155
168
const powerShellExtensionVersionKey = "powerShellExtensionVersion" ;
156
-
157
- const extensionVersion : string =
158
- vscode
159
- . extensions
160
- . getExtension ( "ms-vscode.PowerShell" )
161
- . packageJSON
162
- . version ;
163
-
164
169
const storedVersion = context . globalState . get ( powerShellExtensionVersionKey ) ;
165
170
166
171
if ( ! storedVersion ) {
167
172
// TODO: Prompt to show User Guide for first-time install
168
- } else if ( extensionVersion !== storedVersion ) {
173
+ } else if ( PackageJSON . version !== storedVersion ) {
169
174
vscode
170
175
. window
171
176
. showInformationMessage (
172
- `The PowerShell extension has been updated to version ${ extensionVersion } !` ,
177
+ `The PowerShell extension has been updated to version ${ PackageJSON . version } !` ,
173
178
showReleaseNotes )
174
179
. then ( ( choice ) => {
175
180
if ( choice === showReleaseNotes ) {
@@ -182,7 +187,7 @@ function checkForUpdatedVersion(context: vscode.ExtensionContext) {
182
187
183
188
context . globalState . update (
184
189
powerShellExtensionVersionKey ,
185
- extensionVersion ) ;
190
+ PackageJSON . version ) ;
186
191
}
187
192
188
193
export function deactivate ( ) : void {
@@ -196,4 +201,7 @@ export function deactivate(): void {
196
201
197
202
// Dispose of the logger
198
203
logger . dispose ( ) ;
204
+
205
+ // Dispose of telemetry reporter
206
+ telemetryReporter . dispose ( ) ;
199
207
}
0 commit comments