Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/TracingLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export class TracingLanguageClient extends LanguageClient {
const startAt: number = performance.now();
return super.start().then(value => {
if (isFirstTimeStart) {
this.fireTraceEvent("initialize", startAt);
this.fireTraceEvent("initialize", startAt, undefined);
}
return value;
}, reason => {
if (isFirstTimeStart) {
this.fireTraceEvent("initialize", startAt, reason);
this.fireTraceEvent("initialize", startAt, undefined, reason);
}
throw reason;
});
Expand All @@ -45,10 +45,10 @@ export class TracingLanguageClient extends LanguageClient {
const startAt: number = performance.now();
const requestType: string = this.getRequestType(method, ...args);
return this.sendRequest0(method, ...args).then(value => {
this.fireTraceEvent(requestType, startAt);
this.fireTraceEvent(requestType, startAt, this.getResultLength(value));
return value;
}, reason => {
this.fireTraceEvent(requestType, startAt, reason);
this.fireTraceEvent(requestType, startAt, undefined, reason);
throw reason;
});
}
Expand Down Expand Up @@ -88,12 +88,21 @@ export class TracingLanguageClient extends LanguageClient {
return requestType;
}

private fireTraceEvent(type: string, startAt: number, reason?: any): void {
private fireTraceEvent(type: string, startAt: number, resultLength: number | undefined, reason?: any): void {
const duration: number = performance.now() - startAt;
requestEventEmitter.fire({
type,
duration,
error: reason,
resultLength,
});
}

private getResultLength(value: any): number | undefined {
if (!value) {
return 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we return undefined here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the response is undefined, it indicates that there are no results and returning 0 is acceptable. For me, returning undefined means that we have not yet determined whether the response contains valid results.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it makes sense. Then we probably need to revisit line 106. If value = { someKey: "some value" }, it now returns undefined, is that expected?

If 0 is expected in above case, shall we append ?? 0 like below?

return value?.length ?? value?.items?.length ?? 0;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we probably need to revisit line 106. If value = { someKey: "some value" }, it now returns undefined, is that expected?

Yes. We can return undefined for now. Maybe one day there will be a requirement to resolve some response values more accurately and we can improve it then.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, LGTM then.

}

return value?.length ?? value?.items?.length;
}
}
4 changes: 4 additions & 0 deletions src/extension.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export interface TraceEvent {
* Error that occurs while processing a request.
*/
error?: any;
/**
* The number of results returned by a response.
*/
resultLength?: number | undefined;
}

export const extensionApiVersion = '0.8';
Expand Down