@@ -84,7 +84,7 @@ const INTERESTED_REQUESTS: Set<string> = new Set([
8484const CANCELLATION_CODE : number = - 32800 ; // report such error if the request is cancelled.
8585const CONTENT_MODIFIED_CODE : number = - 32801 ; // report such error if semantic token request is outdated while content modified.
8686const INTERNAL_ERROR_CODE : number = - 32603 ; // Internal Error.
87- let lspUsageStats : LSPUsageStats ;
87+ let lspUsageStats : HybridLSPStats ;
8888async function traceLSPPerformance ( javaExt : vscode . Extension < any > ) {
8989 const javaExtVersion = javaExt . packageJSON ?. version ;
9090 const isPreReleaseVersion = / ^ \d + \. \d + \. \d { 10 } / . test ( javaExtVersion ) ;
@@ -98,7 +98,7 @@ async function traceLSPPerformance(javaExt: vscode.Extension<any>) {
9898
9999 // Enable it since [email protected] 100100 if ( javaExt . exports ?. onWillRequestStart ) {
101- lspUsageStats = new LSPUsageStats ( javaExtVersion , sampling ) ;
101+ lspUsageStats = new HybridLSPStats ( javaExtVersion , sampling ) ;
102102 try {
103103 // Load HdrHistogramJS WASM module
104104 if ( vscode . env . uiKind === vscode . UIKind . Desktop ) {
@@ -116,13 +116,15 @@ async function traceLSPPerformance(javaExt: vscode.Extension<any>) {
116116 }
117117 // Trace the request start
118118 javaExt . exports ?. onWillRequestStart ?.( ( traceEvent : any ) => {
119- lspUsageStats ?. recordRequestStart ( traceEvent . type ) ;
119+ lspUsageStats ?. recordRequestStart ( traceEvent . type , traceEvent . fromSyntaxServer ) ;
120120 } ) ;
121121 // Trace the interested LSP requests performance
122122 javaExt . exports ?. onDidRequestEnd ?.( ( traceEvent : any ) => {
123123 const duration = Math . trunc ( traceEvent . duration ) ;
124- lspUsageStats ?. recordRequestEnd ( traceEvent . type ) ;
125- lspUsageStats ?. recordDuration ( traceEvent . type , duration ) ;
124+ const fromSyntaxServer = ( traceEvent . fromSyntaxServer === undefined ) ?
125+ "" : String ( traceEvent . fromSyntaxServer ) ;
126+ lspUsageStats ?. recordRequestEnd ( traceEvent . type , traceEvent . fromSyntaxServer ) ;
127+ lspUsageStats ?. recordDuration ( traceEvent . type , duration , traceEvent . fromSyntaxServer ) ;
126128 // Trace the timeout requests
127129 if ( traceEvent . duration > 5000 ) {
128130 sendInfo ( "" , {
@@ -131,10 +133,11 @@ async function traceLSPPerformance(javaExt: vscode.Extension<any>) {
131133 duration,
132134 javaversion : javaExtVersion ,
133135 remark : sampling ,
136+ fromSyntaxServer,
134137 } ) ;
135- lspUsageStats ?. record5STimeoutRequest ( traceEvent . type ) ;
138+ lspUsageStats ?. record5STimeoutRequest ( traceEvent . type , traceEvent . fromSyntaxServer ) ;
136139 } else if ( traceEvent . duration > 1000 ) {
137- lspUsageStats ?. record1STimeoutRequest ( traceEvent . type ) ;
140+ lspUsageStats ?. record1STimeoutRequest ( traceEvent . type , traceEvent . fromSyntaxServer ) ;
138141 }
139142
140143 if ( traceEvent . error ) {
@@ -145,7 +148,7 @@ async function traceLSPPerformance(javaExt: vscode.Extension<any>) {
145148 return ;
146149 }
147150
148- lspUsageStats ?. recordErrorRequest ( traceEvent . type ) ;
151+ lspUsageStats ?. recordErrorRequest ( traceEvent . type , traceEvent . fromSyntaxServer ) ;
149152 // See https://github.com/eclipse-lsp4j/lsp4j/commit/bf22871f4e669a2d7fd97ce046cb50903aa68120#diff-3b3e5d6517a47e0459195078645a0837aafa4d4520fe79b1cb1922a749074748
150153 // lsp4j will wrap the error message as "Internal error."
151154 // when it encounters an uncaught exception from jdt language server.
@@ -167,6 +170,7 @@ async function traceLSPPerformance(javaExt: vscode.Extension<any>) {
167170 javaversion : javaExtVersion ,
168171 remark : sampling ,
169172 data : redactDataProperties ( traceEvent . data ) ,
173+ fromSyntaxServer,
170174 } ) ;
171175 return ;
172176 }
@@ -187,11 +191,12 @@ async function traceLSPPerformance(javaExt: vscode.Extension<any>) {
187191 javaversion : javaExtVersion ,
188192 remark : sampling ,
189193 data : redactDataProperties ( traceEvent . data ) ,
194+ fromSyntaxServer,
190195 } ) ;
191196 }
192197
193198 if ( traceEvent . resultLength === 0 ) {
194- lspUsageStats ?. recordNoResultRequest ( traceEvent . type ) ;
199+ lspUsageStats ?. recordNoResultRequest ( traceEvent . type , traceEvent . fromSyntaxServer ) ;
195200 }
196201 } ) ;
197202}
@@ -319,6 +324,88 @@ export function sendLSPUsageStats() {
319324 }
320325}
321326
327+ class HybridLSPStats {
328+ private lspStats : LSPUsageStats ; // standard lsp stats
329+ private ssLspStats : LSPUsageStats | undefined ; // syntax server lsp stats
330+
331+ public constructor ( readonly javaExtVersion : string , readonly sampling : string ) {
332+ this . lspStats = new LSPUsageStats ( javaExtVersion , sampling , false ) ;
333+ // TODO:
334+ // These pre-release versions include the fromSyntaxServer property in the requestEnd event,
335+ // but not in the requestStart event. Once these pre-release versions are no longer used,
336+ // it's safe to remove the following pre-release check logic.
337+ const ignoreVersions = [
338+ "1.24.2023100604" ,
339+ "1.24.2023100504" ,
340+ "1.24.2023100404" ,
341+ ] ;
342+ if ( sampling !== "pre-release" || ! ignoreVersions . includes ( javaExtVersion ) ) {
343+ this . ssLspStats = new LSPUsageStats ( javaExtVersion , sampling , true ) ;
344+ }
345+ }
346+
347+ public recordRequestStart ( type : string , fromSyntaxServer ?: boolean ) {
348+ if ( this . ssLspStats && fromSyntaxServer ) {
349+ this . ssLspStats . recordRequestStart ( type ) ;
350+ } else {
351+ this . lspStats . recordRequestStart ( type ) ;
352+ }
353+ }
354+
355+ public recordRequestEnd ( type : string , fromSyntaxServer ?: boolean ) {
356+ if ( this . ssLspStats && fromSyntaxServer ) {
357+ this . ssLspStats . recordRequestEnd ( type ) ;
358+ } else {
359+ this . lspStats . recordRequestEnd ( type ) ;
360+ }
361+ }
362+
363+ public recordDuration ( type : string , duration : number , fromSyntaxServer ?: boolean ) {
364+ if ( this . ssLspStats && fromSyntaxServer ) {
365+ this . ssLspStats . recordDuration ( type , duration ) ;
366+ } else {
367+ this . lspStats . recordDuration ( type , duration ) ;
368+ }
369+ }
370+
371+ public record1STimeoutRequest ( type : string , fromSyntaxServer ?: boolean ) {
372+ if ( this . ssLspStats && fromSyntaxServer ) {
373+ this . ssLspStats . record1STimeoutRequest ( type ) ;
374+ } else {
375+ this . lspStats . record1STimeoutRequest ( type ) ;
376+ }
377+ }
378+
379+ public record5STimeoutRequest ( type : string , fromSyntaxServer ?: boolean ) {
380+ if ( this . ssLspStats && fromSyntaxServer ) {
381+ this . ssLspStats . record5STimeoutRequest ( type ) ;
382+ } else {
383+ this . lspStats . record5STimeoutRequest ( type ) ;
384+ }
385+ }
386+
387+ public recordErrorRequest ( type : string , fromSyntaxServer ?: boolean ) {
388+ if ( this . ssLspStats && fromSyntaxServer ) {
389+ this . ssLspStats . recordErrorRequest ( type ) ;
390+ } else {
391+ this . lspStats . recordErrorRequest ( type ) ;
392+ }
393+ }
394+
395+ public recordNoResultRequest ( type : string , fromSyntaxServer ?: boolean ) {
396+ if ( this . ssLspStats && fromSyntaxServer ) {
397+ this . ssLspStats . recordNoResultRequest ( type ) ;
398+ } else {
399+ this . lspStats . recordNoResultRequest ( type ) ;
400+ }
401+ }
402+
403+ public sendStats ( ) {
404+ this . lspStats . sendStats ( ) ;
405+ this . ssLspStats ?. sendStats ( ) ;
406+ }
407+ }
408+
322409class LSPUsageStats {
323410 private requestStarts : { [ key : string ] : number } = { } ;
324411 private requestEnds : { [ key : string ] : number } = { } ;
@@ -327,7 +414,7 @@ class LSPUsageStats {
327414 private errorRequests : { [ key : string ] : number } = { } ;
328415 private noResultRequests : { [ key : string ] : number } = { } ;
329416 private hdrs : { [ key : string ] : HDR } = { } ;
330- public constructor ( readonly javaExtVersion : string , readonly sampling : string ) {
417+ public constructor ( readonly javaExtVersion : string , readonly sampling : string , readonly fromSyntaxServer : boolean = false ) {
331418 }
332419
333420 public recordRequestStart ( type : string ) {
@@ -383,7 +470,7 @@ class LSPUsageStats {
383470 }
384471 const duration = Date . now ( ) - startAt ;
385472 sendInfo ( "" , {
386- name : "lsp.aggregate.v1" ,
473+ name : this . fromSyntaxServer ? "lsp.ss.aggregate.v1" : "lsp.aggregate.v1" ,
387474 javaversion : this . javaExtVersion ,
388475 remark : this . sampling ,
389476 data : JSON . stringify ( data ) ,
0 commit comments