Skip to content

Commit b137b7c

Browse files
authored
Report the origin of commands for the UI experiment telemetry (#10581)
1 parent 6711859 commit b137b7c

File tree

3 files changed

+163
-178
lines changed

3 files changed

+163
-178
lines changed

Extension/src/LanguageServer/extension.ts

Lines changed: 27 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -423,75 +423,16 @@ export function registerCommands(enabled: boolean): void {
423423
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.RestartIntelliSenseForFile', enabled ? onRestartIntelliSenseForFile : onDisabledCommand));
424424
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.GenerateDoxygenComment', enabled ? onGenerateDoxygenComment : onDisabledCommand));
425425
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.CreateDeclarationOrDefinition', enabled ? onCreateDeclarationOrDefinition : onDisabledCommand));
426-
// ---------------- Wrappers -------------
427-
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ConfigurationSelectUI_Telemetry', enabled ?
428-
() => {
429-
logForUIExperiment("ConfigurationSelect");
430-
onSelectConfiguration();
431-
}
432-
: onDisabledCommand));
433-
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.RescanWorkspaceUI_Telemetry', enabled ?
434-
() => {
435-
logForUIExperiment("RescanWorkspace");
436-
onRescanWorkspace();
437-
}
438-
: onDisabledCommand));
439-
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowIdleCodeAnalysisCommandsUI_Telemetry', enabled ?
440-
() => {
441-
logForUIExperiment("ShowIdleCodeAnalysisCommands");
442-
onShowIdleCodeAnalysisCommands();
443-
}
444-
: onDisabledCommand));
445-
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowActiveCodeAnalysisCommandsUI_Telemetry', enabled ?
446-
() => {
447-
logForUIExperiment("ShowActiveCodeAnalysisCommands");
448-
onShowActiveCodeAnalysisCommands();
449-
}
450-
: onDisabledCommand));
451-
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.PauseParsingUI_Telemetry', enabled ?
452-
() => {
453-
logForUIExperiment("ParsingCommands");
454-
onPauseParsing();
455-
}
456-
: onDisabledCommand));
457-
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ResumeParsingUI_Telemetry', enabled ?
458-
() => {
459-
logForUIExperiment("ParsingCommands");
460-
onResumeParsing();
461-
}
462-
: onDisabledCommand));
463-
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.CheckForCompilerUI_Telemetry', enabled ?
464-
() => {
465-
logForUIExperiment("CheckForCompiler");
466-
onCheckForCompiler();
467-
}
468-
: onDisabledCommand));
469-
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.RestartIntelliSenseForFileUI_Telemetry', enabled ?
470-
() => {
471-
logForUIExperiment("RestartIntelliSenseForFile");
472-
onRestartIntelliSenseForFile();
473-
}
474-
: onDisabledCommand));
475-
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowReferencesProgressUI_Telemetry', enabled ?
476-
() => {
477-
logForUIExperiment("ShowReferencesProgress");
478-
onShowReferencesProgress();
479-
}
480-
: onDisabledCommand));
481-
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowParsingCommandsUI_Telemetry', enabled ?
482-
() => {
483-
logForUIExperiment("ParsingCommands");
484-
onShowParsingCommands();
485-
}
486-
: onDisabledCommand));
487-
// ----------------------------------------
488426
}
489427

490-
async function logForUIExperiment(command: string): Promise<void> {
428+
async function logForUIExperiment(command: string, sender?: any): Promise<void> {
491429
const settings: CppSettings = new CppSettings((vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) ? vscode.workspace.workspaceFolders[0]?.uri : undefined);
492-
const isNewUI: string = ui.isNewUI.toString();
493-
const isOverridden: string = (settings.experimentalFeatures ?? false).toString();
494-
telemetry.logLanguageServerEvent(`experiment${command}`, { newUI: isNewUI, uiOverride: isOverridden });
430+
const properties: {[key: string]: string} = {
431+
newUI: ui.isNewUI.toString(),
432+
uiOverride: (settings.experimentalFeatures ?? false).toString(),
433+
sender: util.isString(sender) ? sender : 'commandPalette'
434+
};
435+
telemetry.logLanguageServerEvent(`experiment${command}`, properties);
495436
}
496437

497438
function onDisabledCommand(): void {
@@ -506,7 +447,8 @@ function onDisabledCommand(): void {
506447
vscode.window.showWarningMessage(message);
507448
}
508449

509-
function onRestartIntelliSenseForFile(): void {
450+
function onRestartIntelliSenseForFile(sender?: any): void {
451+
logForUIExperiment("RestartIntelliSenseForFile", sender);
510452
const activeEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
511453
if (!activeEditor || !activeEditor.document || activeEditor.document.uri.scheme !== "file" ||
512454
(activeEditor.document.languageId !== "c" && activeEditor.document.languageId !== "cpp" && activeEditor.document.languageId !== "cuda-cpp")) {
@@ -590,7 +532,8 @@ function selectDefaultCompiler(): void {
590532
clients.ActiveClient.promptSelectCompiler(true);
591533
}
592534

593-
function onSelectConfiguration(): void {
535+
function onSelectConfiguration(sender?: any): void {
536+
logForUIExperiment("ConfigurationSelect", sender);
594537
if (!isFolderOpen()) {
595538
vscode.window.showInformationMessage(localize("configuration.select.first", 'Open a folder first to select a configuration.'));
596539
} else {
@@ -656,7 +599,8 @@ function onGoToPrevDirectiveInGroup(): void {
656599
client.handleGoToDirectiveInGroup(false);
657600
}
658601

659-
function onCheckForCompiler(): void {
602+
function onCheckForCompiler(sender?: any): void {
603+
logForUIExperiment("CheckForCompiler", sender);
660604
const client: Client = getActiveClient();
661605
client.handleCheckForCompiler();
662606
}
@@ -769,11 +713,13 @@ function onToggleDimInactiveRegions(): void {
769713
settings.update<boolean>("dimInactiveRegions", !settings.dimInactiveRegions);
770714
}
771715

772-
function onPauseParsing(): void {
716+
function onPauseParsing(sender?: any): void {
717+
logForUIExperiment("ParsingCommands", sender);
773718
clients.ActiveClient.pauseParsing();
774719
}
775720

776-
function onResumeParsing(): void {
721+
function onResumeParsing(sender?: any): void {
722+
logForUIExperiment("ParsingCommands", sender);
777723
clients.ActiveClient.resumeParsing();
778724
}
779725

@@ -789,19 +735,23 @@ function onCancelCodeAnalysis(): void {
789735
clients.ActiveClient.CancelCodeAnalysis();
790736
}
791737

792-
function onShowParsingCommands(): void {
738+
function onShowParsingCommands(sender?: any): void {
739+
logForUIExperiment("ParsingCommands", sender);
793740
clients.ActiveClient.handleShowParsingCommands();
794741
}
795742

796-
function onShowActiveCodeAnalysisCommands(): void {
743+
function onShowActiveCodeAnalysisCommands(sender?: any): void {
744+
logForUIExperiment("ShowActiveCodeAnalysisCommands", sender);
797745
clients.ActiveClient.handleShowActiveCodeAnalysisCommands();
798746
}
799747

800-
function onShowIdleCodeAnalysisCommands(): void {
748+
function onShowIdleCodeAnalysisCommands(sender?: any): void {
749+
logForUIExperiment("ShowIdleCodeAnalysisCommands", sender);
801750
clients.ActiveClient.handleShowIdleCodeAnalysisCommands();
802751
}
803752

804-
function onShowReferencesProgress(): void {
753+
function onShowReferencesProgress(sender?: any): void {
754+
logForUIExperiment("ShowReferencesProgress", sender);
805755
clients.ActiveClient.handleReferencesIcon();
806756
}
807757

@@ -898,7 +848,8 @@ function onLogDiagnostics(): void {
898848
clients.ActiveClient.logDiagnostics();
899849
}
900850

901-
function onRescanWorkspace(): void {
851+
function onRescanWorkspace(sender?: string): void {
852+
logForUIExperiment("RescanWorkspace", sender);
902853
clients.ActiveClient.rescanFolder();
903854
}
904855

Extension/src/LanguageServer/ui.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ interface ConfigurationStatus {
5656
priority: ConfigurationPriority;
5757
}
5858

59+
const commandArguments: string[] = ['oldUI']; // We report the sender of the command
60+
5961
export class OldUI implements UI {
6062
private configStatusBarItem: vscode.StatusBarItem;
6163
private browseEngineStatusBarItem: vscode.StatusBarItem;
@@ -84,14 +86,22 @@ export class OldUI implements UI {
8486
const configTooltip: string = localize("c.cpp.configuration.tooltip", "C/C++ Configuration");
8587
this.configStatusBarItem = vscode.window.createStatusBarItem("c.cpp.configuration.tooltip", vscode.StatusBarAlignment.Right, 0);
8688
this.configStatusBarItem.name = configTooltip;
87-
this.configStatusBarItem.command = "C_Cpp.ConfigurationSelectUI_Telemetry";
89+
this.configStatusBarItem.command = {
90+
command: "C_Cpp.ConfigurationSelect",
91+
title: configTooltip,
92+
arguments: commandArguments
93+
};
8894
this.configStatusBarItem.tooltip = configTooltip;
8995
this.ShowConfiguration = true;
9096

9197
this.referencesStatusBarItem = vscode.window.createStatusBarItem("c.cpp.references.statusbar", vscode.StatusBarAlignment.Right, 901);
9298
this.referencesStatusBarItem.name = localize("c.cpp.references.statusbar", "C/C++ References Status");
9399
this.referencesStatusBarItem.tooltip = "";
94-
this.referencesStatusBarItem.command = "C_Cpp.ShowReferencesProgressUI_Telemetry";
100+
this.referencesStatusBarItem.command = {
101+
command: "C_Cpp.ShowReferencesProgress",
102+
title: this.referencesStatusBarItem.name,
103+
arguments: commandArguments
104+
};
95105
this.ShowReferencesIcon = false;
96106

97107
this.intelliSenseStatusBarItem = vscode.window.createStatusBarItem("c.cpp.intellisense.statusbar", vscode.StatusBarAlignment.Right, 903);
@@ -133,7 +143,11 @@ export class OldUI implements UI {
133143

134144
private setIsParsingWorkspacePausable(val: boolean): void {
135145
if (val) {
136-
this.browseEngineStatusBarItem.command = "C_Cpp.ShowParsingCommandsUI_Telemetry";
146+
this.browseEngineStatusBarItem.command = {
147+
command: "C_Cpp.ShowParsingCommands",
148+
title: this.browseEngineStatusBarItem.name ?? '',
149+
arguments: commandArguments
150+
};
137151
} else {
138152
this.browseEngineStatusBarItem.command = undefined;
139153
}
@@ -189,7 +203,11 @@ export class OldUI implements UI {
189203
this.intelliSenseStatusBarItem.tooltip = (this.isUpdatingIntelliSense ? this.updatingIntelliSenseTooltip : "")
190204
+ (twoStatus ? " | " : "")
191205
+ (val ? this.runningCodeAnalysisTooltip : "");
192-
this.intelliSenseStatusBarItem.command = val ? "C_Cpp.ShowActiveCodeAnalysisCommandsUI_Telemetry" : undefined;
206+
this.intelliSenseStatusBarItem.command = val ? {
207+
command: "C_Cpp.ShowActiveCodeAnalysisCommands",
208+
title: this.intelliSenseStatusBarItem.name ?? '',
209+
arguments: commandArguments
210+
} : undefined;
193211
}
194212

195213
private updateCodeAnalysisTooltip(): void {

0 commit comments

Comments
 (0)