-
Notifications
You must be signed in to change notification settings - Fork 527
Add API to track lsp perf on language client level #2996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
4ec7760
ee00332
9daebaf
48c8607
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| 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<TraceEvent>(); | ||
| export const onDidRequestEnd: Event<TraceEvent> = requestEventEmitter.event; | ||
|
|
||
| export class TracingLanguageClient extends LanguageClient { | ||
| private isStarted: boolean = false; | ||
|
|
||
| constructor(id: string, name: string, serverOptions: ServerOptions, clientOptions: LanguageClientOptions, forceDebug?: boolean) { | ||
| super(id, name, serverOptions, clientOptions, forceDebug); | ||
| } | ||
|
|
||
| start(): Promise<void> { | ||
| const isFirstTimeStart: boolean = !this.isStarted; | ||
| this.isStarted = true; | ||
| const startAt: number = Date.now(); | ||
| return super.start().then(value => { | ||
| if (isFirstTimeStart) { | ||
| this.fireTraceEvent("initialize", startAt); | ||
| } | ||
| return value; | ||
| }, reason => { | ||
| if (isFirstTimeStart) { | ||
| this.fireTraceEvent("initialize", startAt, reason); | ||
| } | ||
| throw reason; | ||
| }); | ||
| } | ||
|
|
||
| stop(timeout?: number): Promise<void> { | ||
| this.isStarted = false; | ||
| return super.stop(timeout); | ||
| } | ||
|
|
||
| sendRequest<R, PR, E, RO>(type: ProtocolRequestType0<R, PR, E, RO>, token?: CancellationToken): Promise<R>; | ||
| sendRequest<P, R, PR, E, RO>(type: ProtocolRequestType<P, R, PR, E, RO>, params: P, token?: CancellationToken): Promise<R>; | ||
| sendRequest<R, E>(type: RequestType0<R, E>, token?: CancellationToken): Promise<R>; | ||
| sendRequest<P, R, E>(type: RequestType<P, R, E>, params: P, token?: CancellationToken): Promise<R>; | ||
| sendRequest<R>(method: string, token?: CancellationToken): Promise<R>; | ||
| sendRequest<R>(method: string, param: any, token?: CancellationToken): Promise<R>; | ||
| sendRequest(method: any, ...args) { | ||
| const startAt: number = Date.now(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be better to use
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks. Good to know the new API. The data will like |
||
| const requestType: string = this.getRequestType(method, ...args); | ||
| return this.sendRequest0(method, ...args).then(value => { | ||
| this.fireTraceEvent(requestType, startAt); | ||
| return value; | ||
| }, reason => { | ||
| this.fireTraceEvent(requestType, startAt, reason); | ||
|
testforstephen marked this conversation as resolved.
|
||
| throw reason; | ||
| }); | ||
| } | ||
|
|
||
| private sendRequest0(method: any, ...args) { | ||
| if (!args || !args.length) { | ||
| return super.sendRequest(method); | ||
| } | ||
|
|
||
| const first = args[0]; | ||
| const last = args[args.length - 1]; | ||
| if (CancellationToken.is(last)) { | ||
| if (first === last) { | ||
| return super.sendRequest(method, last); | ||
| } else { | ||
| return super.sendRequest(method, first, last); | ||
| } | ||
| } | ||
|
|
||
| return super.sendRequest(method, first); | ||
| } | ||
|
|
||
| private getRequestType(method: any, ...args): string { | ||
| let requestType: string; | ||
| if (typeof method === 'string' || method instanceof String) { | ||
| requestType = String(method); | ||
| } else { | ||
| requestType = method?.method; | ||
| } | ||
|
|
||
| if (requestType === "workspace/executeCommand") { | ||
| if (args?.[0]?.command) { | ||
| requestType = `workspace/executeCommand/${args[0].command}`; | ||
| } | ||
| } | ||
|
|
||
| return requestType; | ||
| } | ||
|
|
||
| private fireTraceEvent(type: string, startAt: number, reason?: any): void { | ||
| const duration: number = Date.now() - startAt; | ||
| requestEventEmitter.fire({ | ||
| type, | ||
| duration, | ||
| error: reason, | ||
| }); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.