@@ -5,11 +5,9 @@ import { promisify } from "util";
5
5
import * as vscode from "vscode" ;
6
6
import { sendError , sendInfo } from "vscode-extension-telemetry-wrapper" ;
7
7
import { LSDaemon } from "./daemon" ;
8
+ import { getExpService } from "../exp" ;
9
+ import { TreatmentVariables } from "../exp/TreatmentVariables" ;
8
10
9
- const INTERESTED_REQUESTS : Set < string > = new Set ( [
10
- "initialize" ,
11
- "textDocument/completion" ,
12
- ] ) ;
13
11
const delay = promisify ( setTimeout ) ;
14
12
15
13
let daemon : LSDaemon ;
@@ -50,41 +48,7 @@ async function checkJavaExtActivated(_context: vscode.ExtensionContext): Promise
50
48
return false ;
51
49
}
52
50
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 ) ;
88
52
89
53
// on ServiceReady
90
54
javaExt . exports . onDidServerModeChange ( async ( mode : string ) => {
@@ -109,6 +73,65 @@ async function checkJavaExtActivated(_context: vscode.ExtensionContext): Promise
109
73
return true ;
110
74
}
111
75
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
+
112
135
let corruptedCacheDetected : boolean = false ;
113
136
async function checkIfJavaServerCrashed ( wait : number = 0 /*ms*/ ) {
114
137
if ( corruptedCacheDetected ) {
0 commit comments