diff --git a/src/TracingLanguageClient.ts b/src/TracingLanguageClient.ts index 9a27d3c21..314cd64b8 100644 --- a/src/TracingLanguageClient.ts +++ b/src/TracingLanguageClient.ts @@ -3,8 +3,10 @@ import { Event, EventEmitter } from "vscode"; import { CancellationToken, LanguageClient, LanguageClientOptions, ProtocolRequestType, ProtocolRequestType0, RequestType, RequestType0, ServerOptions } from "vscode-languageclient/node"; import { TraceEvent } from "./extension.api"; -const requestEventEmitter = new EventEmitter(); -export const onDidRequestEnd: Event = requestEventEmitter.event; +const requestStartEventEmitter = new EventEmitter(); +const requestEndEventEmitter = new EventEmitter(); +export const onWillRequestStart: Event = requestStartEventEmitter.event; +export const onDidRequestEnd: Event = requestEndEventEmitter.event; export class TracingLanguageClient extends LanguageClient { private isStarted: boolean = false; @@ -17,6 +19,9 @@ export class TracingLanguageClient extends LanguageClient { const isFirstTimeStart: boolean = !this.isStarted; this.isStarted = true; const startAt: number = performance.now(); + if (isFirstTimeStart) { + this.fireRequestStartTraceEvent("initialize"); + } return super.start().then(value => { if (isFirstTimeStart) { this.fireSuccessTraceEvent("initialize", startAt, undefined); @@ -51,6 +56,7 @@ export class TracingLanguageClient extends LanguageClient { triggerCharacter: args[0].context.triggerCharacter, }; } + this.fireRequestStartTraceEvent(requestType); return this.sendRequest0(method, ...args).then((value: any) => { if (data && value?.itemDefaults?.data?.completionKinds) { // Include the completionKinds from the completion response. @@ -99,9 +105,15 @@ export class TracingLanguageClient extends LanguageClient { return requestType; } + private fireRequestStartTraceEvent(type: string): void { + requestStartEventEmitter.fire({ + type, + }); + } + private fireSuccessTraceEvent(type: string, startAt: number, resultLength: number | undefined, data?: any): void { const duration: number = performance.now() - startAt; - requestEventEmitter.fire({ + requestEndEventEmitter.fire({ type, duration, resultLength, @@ -111,7 +123,7 @@ export class TracingLanguageClient extends LanguageClient { private fireFailureTraceEvent(type: string, startAt: number, error: any, data?: any): void { const duration: number = performance.now() - startAt; - requestEventEmitter.fire({ + requestEndEventEmitter.fire({ type, duration, error, diff --git a/src/apiManager.ts b/src/apiManager.ts index 52759c963..03eebfda3 100644 --- a/src/apiManager.ts +++ b/src/apiManager.ts @@ -9,7 +9,7 @@ import { Commands } from "./commands"; import { Emitter } from "vscode-languageclient"; import { ServerMode } from "./settings"; import { registerHoverCommand } from "./hoverAction"; -import { onDidRequestEnd } from "./TracingLanguageClient"; +import { onDidRequestEnd, onWillRequestStart } from "./TracingLanguageClient"; class ApiManager { @@ -64,6 +64,7 @@ class ApiManager { onDidServerModeChange, onDidProjectsImport, serverReady, + onWillRequestStart, onDidRequestEnd, trackEvent: traceEvent, onDidSourceInvalidate: this.sourceInvalidatedEventEmitter.event, diff --git a/src/extension.api.ts b/src/extension.api.ts index 2e1da6239..dc27a68b6 100644 --- a/src/extension.api.ts +++ b/src/extension.api.ts @@ -81,7 +81,7 @@ export interface TraceEvent { /** * Time (in milliseconds) taken to process a request. */ - duration: number; + duration?: number; /** * Error that occurs while processing a request. */ @@ -107,7 +107,7 @@ export interface SourceInvalidatedEvent { affectedEditorDocuments?: Uri[]; } -export const extensionApiVersion = '0.11'; +export const extensionApiVersion = '0.12'; export interface ExtensionAPI { readonly apiVersion: string; @@ -153,6 +153,13 @@ export interface ExtensionAPI { */ readonly serverReady: () => Promise; + /** + * An event that's fired when a request is about to send to language server. + * @since API version 0.12 + * @since extension version 1.23.0 + */ + readonly onWillRequestStart: Event; + /** * An event that's fired when a request has been responded. * @since API version 0.8