@@ -5,11 +5,9 @@ import { promisify } from "util";
55import * as vscode from "vscode" ;
66import { sendError , sendInfo } from "vscode-extension-telemetry-wrapper" ;
77import { LSDaemon } from "./daemon" ;
8+ import { getExpService } from "../exp" ;
9+ import { TreatmentVariables } from "../exp/TreatmentVariables" ;
810
9- const INTERESTED_REQUESTS : Set < string > = new Set ( [
10- "initialize" ,
11- "textDocument/completion" ,
12- ] ) ;
1311const delay = promisify ( setTimeout ) ;
1412
1513let daemon : LSDaemon ;
@@ -50,41 +48,7 @@ async function checkJavaExtActivated(_context: vscode.ExtensionContext): Promise
5048 return false ;
5149 }
5250
53- // Trace the interested LSP requests performance
54- javaExt . exports ?. onDidRequestEnd ( ( traceEvent : any ) => {
55- let code : number = 0 ;
56- let errorMessage : string = "" ;
57- if ( traceEvent . error ) {
58- code = traceEvent . error ?. code || 0 ;
59- errorMessage = traceEvent . error ?. message || String ( traceEvent . error ) ;
60- }
61-
62- if ( INTERESTED_REQUESTS . has ( traceEvent . type ) ) {
63- if ( errorMessage ) {
64- sendInfo ( "" , {
65- name : "lsp" ,
66- kind : escapeLspRequestName ( traceEvent . type ) ,
67- duration : Math . trunc ( traceEvent . duration ) ,
68- code,
69- message : errorMessage ,
70- } ) ;
71- return ;
72- }
73-
74- // See https://github.com/redhat-developer/vscode-java/pull/3010
75- // to exclude the invalid completion requests.
76- if ( ! traceEvent . resultLength && traceEvent . type === "textDocument/completion" ) {
77- return ;
78- }
79-
80- sendInfo ( "" , {
81- name : "lsp" ,
82- kind : escapeLspRequestName ( traceEvent . type ) ,
83- duration : Math . trunc ( traceEvent . duration ) ,
84- resultLength : traceEvent . resultLength ,
85- } ) ;
86- }
87- } ) ;
51+ traceLSPPerformance ( javaExt ) ;
8852
8953 // on ServiceReady
9054 javaExt . exports . onDidServerModeChange ( async ( mode : string ) => {
@@ -109,6 +73,65 @@ async function checkJavaExtActivated(_context: vscode.ExtensionContext): Promise
10973 return true ;
11074}
11175
76+ const INTERESTED_REQUESTS : Set < string > = new Set ( [
77+ "initialize" ,
78+ "textDocument/completion" ,
79+ ] ) ;
80+ async function traceLSPPerformance ( javaExt : vscode . Extension < any > ) {
81+ const javaExtVersion = javaExt . packageJSON ?. version ;
82+ const isPreReleaseVersion = / ^ \d + \. \d + \. \d { 10 } / . test ( javaExtVersion ) ;
83+ const isTreatment = ! isPreReleaseVersion &&
84+ ( await getExpService ( ) ?. getTreatmentVariableAsync ( TreatmentVariables . VSCodeConfig , TreatmentVariables . JavaCompletionSampling , true /*checkCache*/ ) || false ) ;
85+ const sampling : string = isPreReleaseVersion ? "pre-release" : ( isTreatment ? "sampling" : "" ) ;
86+ // Trace the interested LSP requests performance
87+ javaExt . exports ?. onDidRequestEnd ( ( traceEvent : any ) => {
88+ if ( ! traceEvent . error && ! isPreReleaseVersion && ! isTreatment ) {
89+ return ;
90+ }
91+
92+ if ( INTERESTED_REQUESTS . has ( traceEvent . type ) ) {
93+ // See https://github.com/redhat-developer/vscode-java/pull/3010
94+ // to exclude the invalid completion requests.
95+ if ( ! traceEvent . error && ! traceEvent . resultLength && traceEvent . type === "textDocument/completion" ) {
96+ return ;
97+ }
98+
99+ sendTrace ( traceEvent , javaExtVersion , sampling ) ;
100+ return ;
101+ }
102+ } ) ;
103+ }
104+
105+ function sendTrace ( traceEvent : any , javaExtVersion : any , sampling : string ) {
106+ let code : number = 0 ;
107+ let errorMessage : string = "" ;
108+ if ( traceEvent . error ) {
109+ code = traceEvent . error ?. code || 0 ;
110+ errorMessage = traceEvent . error ?. message || String ( traceEvent . error ) ;
111+ }
112+
113+ if ( errorMessage ) {
114+ sendInfo ( "" , {
115+ name : "lsp" ,
116+ kind : escapeLspRequestName ( traceEvent . type ) ,
117+ duration : Math . trunc ( traceEvent . duration ) ,
118+ code,
119+ message : errorMessage ,
120+ javaversion : javaExtVersion ,
121+ } ) ;
122+ return ;
123+ }
124+
125+ sendInfo ( "" , {
126+ name : "lsp" ,
127+ kind : escapeLspRequestName ( traceEvent . type ) ,
128+ duration : Math . trunc ( traceEvent . duration ) ,
129+ resultLength : traceEvent . resultLength ,
130+ javaversion : javaExtVersion ,
131+ remark : sampling ,
132+ } ) ;
133+ }
134+
112135let corruptedCacheDetected : boolean = false ;
113136async function checkIfJavaServerCrashed ( wait : number = 0 /*ms*/ ) {
114137 if ( corruptedCacheDetected ) {
0 commit comments