Skip to content

Commit fec0d88

Browse files
authored
Log more info with the configuration provider telemetry (#12193)
1 parent 4650cfe commit fec0d88

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ export function disposeWorkspaceData(): void {
111111
workspaceDisposables = [];
112112
}
113113

114-
function logTelemetry(notificationBody: TelemetryPayload): void {
115-
telemetry.logLanguageServerEvent(notificationBody.event, notificationBody.properties, notificationBody.metrics);
116-
}
117-
118114
/** Note: We should not await on the following functions,
119115
* or any function that returns a promise acquired from them,
120116
* vscode.window.showInformationMessage, vscode.window.showWarningMessage, vscode.window.showErrorMessage
@@ -2000,13 +1996,17 @@ export class DefaultClient implements Client {
20001996
onFinished();
20011997
return;
20021998
}
2003-
telemetry.logLanguageServerEvent('provideCustomConfiguration', { providerId });
2004-
void this.provideCustomConfigurationAsync(docUri, requestFile, replaceExisting, onFinished, provider);
1999+
try {
2000+
DefaultClient.isStarted.reset();
2001+
const result = await this.provideCustomConfigurationAsync(docUri, requestFile, replaceExisting, provider);
2002+
telemetry.logLanguageServerEvent('provideCustomConfiguration', { providerId, result });
2003+
} finally {
2004+
onFinished();
2005+
DefaultClient.isStarted.resolve();
2006+
}
20052007
}
20062008

2007-
private async provideCustomConfigurationAsync(docUri: vscode.Uri, requestFile: string | undefined, replaceExisting: boolean | undefined, onFinished: () => void, provider: CustomConfigurationProvider1) {
2008-
DefaultClient.isStarted.reset();
2009-
2009+
private async provideCustomConfigurationAsync(docUri: vscode.Uri, requestFile: string | undefined, replaceExisting: boolean | undefined, provider: CustomConfigurationProvider1): Promise<string> {
20102010
const tokenSource: vscode.CancellationTokenSource = new vscode.CancellationTokenSource();
20112011

20122012
const params: QueryTranslationUnitSourceParams = {
@@ -2018,14 +2018,12 @@ export class DefaultClient implements Client {
20182018
const response: QueryTranslationUnitSourceResult = await this.languageClient.sendRequest(QueryTranslationUnitSourceRequest, params);
20192019
if (!response.candidates || response.candidates.length === 0) {
20202020
// If we didn't receive any candidates, no configuration is needed.
2021-
onFinished();
2022-
DefaultClient.isStarted.resolve();
2023-
return;
2021+
return "noCandidates";
20242022
}
20252023

20262024
// Need to loop through candidates, to see if we can get a custom configuration from any of them.
20272025
// Wrap all lookups in a single task, so we can apply a timeout to the entire duration.
2028-
const provideConfigurationAsync: () => Thenable<SourceFileConfigurationItem[] | null | undefined> = async () => {
2026+
const provideConfigurationAsync: () => Thenable<SourceFileConfigurationItem[] | undefined> = async () => {
20292027
const uris: vscode.Uri[] = [];
20302028
for (let i: number = 0; i < response.candidates.length; ++i) {
20312029
const candidate: string = response.candidates[i];
@@ -2085,44 +2083,41 @@ export class DefaultClient implements Client {
20852083
}
20862084
return configs as SourceFileConfigurationItem[];
20872085
}
2088-
if (tokenSource.token.isCancellationRequested) {
2089-
return null;
2090-
}
2086+
return undefined;
20912087
};
2088+
let result: string = "success";
20922089
try {
2093-
const configs: SourceFileConfigurationItem[] | null | undefined = await this.callTaskWithTimeout(provideConfigurationAsync, configProviderTimeout, tokenSource);
2090+
const configs: SourceFileConfigurationItem[] | undefined = await this.callTaskWithTimeout(provideConfigurationAsync, configProviderTimeout, tokenSource);
20942091
if (configs && configs.length > 0) {
20952092
this.sendCustomConfigurations(configs, provider.version);
2093+
} else {
2094+
result = "noConfigurations";
20962095
}
2097-
onFinished();
20982096
} catch (err) {
2099-
if (requestFile) {
2100-
onFinished();
2101-
return;
2102-
}
2103-
const settings: CppSettings = new CppSettings(this.RootUri);
2104-
if (settings.configurationWarnings && !this.isExternalHeader(docUri) && !vscode.debug.activeDebugSession) {
2105-
const dismiss: string = localize("dismiss.button", "Dismiss");
2106-
const disable: string = localize("disable.warnings.button", "Disable Warnings");
2107-
const configName: string | undefined = this.configuration.CurrentConfiguration?.name;
2108-
if (!configName) {
2109-
return;
2110-
}
2111-
let message: string = localize("unable.to.provide.configuration",
2112-
"{0} is unable to provide IntelliSense configuration information for '{1}'. Settings from the '{2}' configuration will be used instead.",
2113-
provider.name, docUri.fsPath, configName);
2114-
if (err) {
2115-
message += ` (${err})`;
2116-
}
2097+
result = "timeout";
2098+
if (!requestFile) {
2099+
const settings: CppSettings = new CppSettings(this.RootUri);
2100+
if (settings.configurationWarnings && !this.isExternalHeader(docUri) && !vscode.debug.activeDebugSession) {
2101+
const dismiss: string = localize("dismiss.button", "Dismiss");
2102+
const disable: string = localize("disable.warnings.button", "Disable Warnings");
2103+
const configName: string | undefined = this.configuration.CurrentConfiguration?.name;
2104+
if (!configName) {
2105+
return "noConfigName";
2106+
}
2107+
let message: string = localize("unable.to.provide.configuration",
2108+
"{0} is unable to provide IntelliSense configuration information for '{1}'. Settings from the '{2}' configuration will be used instead.",
2109+
provider.name, docUri.fsPath, configName);
2110+
if (err) {
2111+
message += ` (${err})`;
2112+
}
21172113

2118-
if (await vscode.window.showInformationMessage(message, dismiss, disable) === disable) {
2119-
settings.toggleSetting("configurationWarnings", "enabled", "disabled");
2114+
if (await vscode.window.showInformationMessage(message, dismiss, disable) === disable) {
2115+
settings.toggleSetting("configurationWarnings", "enabled", "disabled");
2116+
}
21202117
}
21212118
}
2122-
} finally {
2123-
DefaultClient.isStarted.resolve();
21242119
}
2125-
2120+
return result;
21262121
}
21272122

21282123
private async handleRequestCustomConfig(requestFile: string): Promise<void> {
@@ -2323,7 +2318,7 @@ export class DefaultClient implements Client {
23232318

23242319
this.languageClient.onNotification(ReloadWindowNotification, () => void util.promptForReloadWindowDueToSettingsChange());
23252320
this.languageClient.onNotification(UpdateTrustedCompilersNotification, (e) => void this.addTrustedCompiler(e.compilerPath));
2326-
this.languageClient.onNotification(LogTelemetryNotification, logTelemetry);
2321+
this.languageClient.onNotification(LogTelemetryNotification, (e) => this.logTelemetry(e));
23272322
this.languageClient.onNotification(ReportStatusNotification, (e) => void this.updateStatus(e));
23282323
this.languageClient.onNotification(ReportTagParseStatusNotification, (e) => this.updateTagParseStatus(e));
23292324
this.languageClient.onNotification(CompileCommandsPathsNotification, (e) => void this.promptCompileCommands(e));
@@ -2562,6 +2557,13 @@ export class DefaultClient implements Client {
25622557
}
25632558
}
25642559

2560+
private logTelemetry(notificationBody: TelemetryPayload): void {
2561+
if (notificationBody.event === "includeSquiggles" && this.configurationProvider && notificationBody.properties) {
2562+
notificationBody.properties["providerId"] = this.configurationProvider;
2563+
}
2564+
telemetry.logLanguageServerEvent(notificationBody.event, notificationBody.properties, notificationBody.metrics);
2565+
}
2566+
25652567
private async updateStatus(notificationBody: ReportStatusNotificationBody): Promise<void> {
25662568
const message: string = notificationBody.status;
25672569
util.setProgress(util.getProgressExecutableSuccess());

0 commit comments

Comments
 (0)