Skip to content

Commit 3c5e7e2

Browse files
authored
Report the origin of the CreateDeclaration/Definition commands (#10582)
1 parent b137b7c commit 3c5e7e2

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Extension/src/LanguageServer/Providers/codeActionProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
169169
resultCodeActions.push(...docCodeActions);
170170
return;
171171
}
172+
if (command.command === 'C_Cpp.CreateDeclarationOrDefinition' && (command.arguments ?? []).length === 0) {
173+
command.arguments = ['codeAction']; // We report the sender of the command
174+
}
172175
const vscodeCodeAction: vscode.CodeAction = {
173176
title: title,
174177
command: command.command === "edit" ? undefined : {

Extension/src/LanguageServer/extension.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,16 +425,25 @@ export function registerCommands(enabled: boolean): void {
425425
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.CreateDeclarationOrDefinition', enabled ? onCreateDeclarationOrDefinition : onDisabledCommand));
426426
}
427427

428-
async function logForUIExperiment(command: string, sender?: any): Promise<void> {
428+
function logForUIExperiment(command: string, sender?: any): void {
429429
const settings: CppSettings = new CppSettings((vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) ? vscode.workspace.workspaceFolders[0]?.uri : undefined);
430430
const properties: {[key: string]: string} = {
431431
newUI: ui.isNewUI.toString(),
432432
uiOverride: (settings.experimentalFeatures ?? false).toString(),
433-
sender: util.isString(sender) ? sender : 'commandPalette'
433+
sender: getSenderType(sender)
434434
};
435435
telemetry.logLanguageServerEvent(`experiment${command}`, properties);
436436
}
437437

438+
function getSenderType(sender?: any): string {
439+
if (util.isString(sender)) {
440+
return sender;
441+
} else if (util.isUri(sender)) {
442+
return 'contextMenu';
443+
}
444+
return 'commandPalette';
445+
}
446+
438447
function onDisabledCommand(): void {
439448
const message: string = localize(
440449
{
@@ -675,7 +684,11 @@ async function onDisableAllTypeCodeAnalysisProblems(code: string, identifiersAnd
675684
getActiveClient().handleDisableAllTypeCodeAnalysisProblems(code, identifiersAndUris);
676685
}
677686

678-
async function onCreateDeclarationOrDefinition(): Promise<void> {
687+
async function onCreateDeclarationOrDefinition(sender?: any): Promise<void> {
688+
const properties: { [key: string]: string } = {
689+
sender: getSenderType(sender)
690+
};
691+
telemetry.logLanguageServerEvent('CreateDeclDefn', properties);
679692
getActiveClient().handleCreateDeclarationOrDefinition();
680693
}
681694

0 commit comments

Comments
 (0)