Skip to content

Commit ab4ac9b

Browse files
authored
chore: Refine telemetry for Formatter Setting Editor (#657)
1 parent 9212a25 commit ab4ac9b

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/formatter-settings/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ export class JavaFormatterSettingsEditorProvider implements vscode.CustomTextEdi
9797
}
9898
break;
9999
case "onWillChangeExampleKind":
100+
sendInfo("", { formatterExample: e.exampleKind });
100101
this.exampleKind = e.exampleKind;
101102
this.format();
102103
break;
103104
case "onWillChangeSetting":
104105
const settingValue: string | undefined = FormatterConverter.webView2ProfileConvert(e.id, e.value.toString());
106+
sendInfo("", { formatterSetting: e.id });
105107
// "" represents an empty inputbox, we regard it as a valid value.
106108
if (settingValue === undefined) {
107109
return;
@@ -225,15 +227,15 @@ export class JavaFormatterSettingsEditorProvider implements vscode.CustomTextEdi
225227
for (const setting of supportedVSCodeSettings.values()) {
226228
switch (setting.id) {
227229
case SupportedSettings.TABULATION_CHAR:
228-
setting.value = (await getVSCodeSetting(VSCodeSettings.INSERT_SPACES, true) === false) ? "tab" : "space";
230+
setting.value = (getVSCodeSetting(VSCodeSettings.INSERT_SPACES, true) === false) ? "tab" : "space";
229231
this.profileSettings.set(setting.id, setting.value);
230232
break;
231233
case SupportedSettings.TABULATION_SIZE:
232-
setting.value = String(await getVSCodeSetting(VSCodeSettings.TAB_SIZE, 4));
234+
setting.value = String(getVSCodeSetting(VSCodeSettings.TAB_SIZE, 4));
233235
this.profileSettings.set(setting.id, setting.value);
234236
break;
235237
case VSCodeSettings.DETECT_INDENTATION:
236-
setting.value = String(await getVSCodeSetting(VSCodeSettings.DETECT_INDENTATION, true));
238+
setting.value = String(getVSCodeSetting(VSCodeSettings.DETECT_INDENTATION, true));
237239
break;
238240
default:
239241
return;
@@ -292,21 +294,21 @@ export class JavaFormatterSettingsEditorProvider implements vscode.CustomTextEdi
292294
return true;
293295
}
294296

295-
private checkProfileSettings = instrumentOperation("formatter.checkProfileSetting", async (operationId: string) => {
297+
private checkProfileSettings = instrumentOperation("java.formatter.checkProfileSetting", async (operationId: string) => {
296298
if (this.checkedProfileSettings) {
297299
return true;
298300
}
299301
this.readOnly = false;
300302
if (!this.settingsUrl) {
301-
sendInfo(operationId, { formatterProfile: "undefined" });
303+
sendInfo(operationId, { formatterProfileKind: "undefined" });
302304
await vscode.window.showInformationMessage("No active Formatter Profile found, do you want to create a default one?",
303305
"Yes", "No").then((result) => {
304306
if (result === "Yes") {
305307
addDefaultProfile(this.context);
306308
}
307309
});
308310
} else if (isRemote(this.settingsUrl)) {
309-
sendInfo(operationId, { formatterProfile: "remote" });
311+
sendInfo(operationId, { formatterProfileKind: "remote" });
310312
this.checkedProfileSettings = await vscode.window.showInformationMessage("The active formatter profile is remote, do you want to open it in read-only mode or download and use it locally?",
311313
"Open in read-only mode", "Download and use it locally").then(async (result) => {
312314
if (result === "Open in read-only mode") {
@@ -329,7 +331,7 @@ export class JavaFormatterSettingsEditorProvider implements vscode.CustomTextEdi
329331
this.profilePath = await getProfilePath(this.settingsUrl);
330332
}
331333
if (!(await fse.pathExists(this.profilePath))) {
332-
sendInfo(operationId, { formatterProfile: "notExist" });
334+
sendInfo(operationId, { formatterProfileKind: "notExist" });
333335
await vscode.window.showInformationMessage("The active formatter profile does not exist, please check it in the Settings and try again.",
334336
"Open Settings", "Generate a default profile").then((result) => {
335337
if (result === "Open Settings") {
@@ -340,7 +342,7 @@ export class JavaFormatterSettingsEditorProvider implements vscode.CustomTextEdi
340342
});
341343
return false;
342344
}
343-
sendInfo(operationId, { formatterProfile: "valid" });
345+
sendInfo(operationId, { formatterProfileKind: "valid" });
344346
this.checkedProfileSettings = true;
345347
}
346348
return this.checkedProfileSettings;

src/formatter-settings/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as fse from "fs-extra";
55
import * as path from "path";
66
import * as vscode from "vscode";
77
import axios from 'axios';
8-
import { instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
8+
import { sendInfo } from "vscode-extension-telemetry-wrapper";
99
import { DOMAttr, DOMElement, ProfileContent } from "./types";
1010
import { DOMParser, XMLSerializer } from "xmldom";
1111
import { getDefaultValue, getSupportedProfileSettings, JavaConstants } from "./FormatterConstants";
@@ -26,15 +26,15 @@ export async function getProfilePath(formatterUrl: string): Promise<string> {
2626
return "";
2727
}
2828

29-
export const getVSCodeSetting = instrumentOperation("formatter.getSetting", async (operationId: string, setting: string, defaultValue: any) => {
29+
export function getVSCodeSetting(setting: string, defaultValue: any) {
3030
const config = vscode.workspace.getConfiguration(undefined, { languageId: "java" });
3131
let result = config.get<any>(setting) ?? vscode.workspace.getConfiguration().get<any>(setting);
3232
if (result === undefined) {
33-
sendInfo(operationId, { notFoundSetting: setting });
33+
sendInfo("", { notFoundSetting: setting });
3434
return defaultValue;
3535
}
3636
return result;
37-
});
37+
}
3838

3939
export function isRemote(path: string): boolean {
4040
return path !== null && path.startsWith("http:/") || path.startsWith("https:/");

0 commit comments

Comments
 (0)