Skip to content

Commit 87710c7

Browse files
authored
Update client telemetry (#587)
1 parent d564949 commit 87710c7

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/extension.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
LanguageClient,
99
ServerOptions,
1010
Executable,
11+
State as ClientState
1112
} from 'vscode-languageclient/node';
1213
import ShortUniqueId from 'short-unique-id';
1314
import TelemetryReporter from 'vscode-extension-telemetry';
@@ -170,9 +171,17 @@ async function startClients(folders = prunedFolderNames()) {
170171
if (!clients.has(folder)) {
171172
const commandPrefix = shortUid.seq();
172173
const client = newClient(command, folder, commandPrefix);
174+
client.onReady().then(() => {
175+
reporter.sendTelemetryEvent('startClient');
176+
});
177+
client.onDidChangeState((event) => {
178+
if (event.newState === ClientState.Stopped) {
179+
clients.delete(folder);
180+
reporter.sendTelemetryEvent('stopClient');
181+
}
182+
});
173183
disposables.push(client.start());
174184
clients.set(folder, { commandPrefix, client });
175-
reporter.sendTelemetryEvent('startClient');
176185
} else {
177186
console.log(`Client for folder: ${folder} already started`);
178187
}
@@ -217,6 +226,10 @@ function newClient(cmd: string, location: string, commandPrefix: string) {
217226
documentSelector: [{ scheme: 'file', language: 'terraform', pattern: `${f.uri.fsPath}/**/*` }],
218227
workspaceFolder: f,
219228
initializationOptions: initializationOptions,
229+
initializationFailedHandler: (error) => {
230+
reporter.sendTelemetryException(error);
231+
return false;
232+
},
220233
outputChannel: setup,
221234
revealOutputChannelOn: 4 // hide always
222235
};
@@ -235,8 +248,6 @@ async function stopClients(folders = prunedFolderNames()) {
235248
for (const folder of folders) {
236249
if (clients.has(folder)) {
237250
promises.push(clients.get(folder).client.stop());
238-
clients.delete(folder);
239-
reporter.sendTelemetryEvent('stopClient');
240251
} else {
241252
console.log(`Attempted to stop a client for folder: ${folder} but no client exists`);
242253
}

0 commit comments

Comments
 (0)