@@ -77,6 +77,8 @@ const INTERESTED_REQUESTS: Set<string> = new Set([
77
77
"initialize" ,
78
78
"textDocument/completion" ,
79
79
] ) ;
80
+ const CANCELLATION_CODE : number = - 32800 ; // report such error if the request is cancelled.
81
+ const CONTENT_MODIFIED_CODE : number = - 32801 ; // report such error if semantic token request is outdated while content modified.
80
82
async function traceLSPPerformance ( javaExt : vscode . Extension < any > ) {
81
83
const javaExtVersion = javaExt . packageJSON ?. version ;
82
84
const isPreReleaseVersion = / ^ \d + \. \d + \. \d { 10 } / . test ( javaExtVersion ) ;
@@ -85,53 +87,49 @@ async function traceLSPPerformance(javaExt: vscode.Extension<any>) {
85
87
const sampling : string = isPreReleaseVersion ? "pre-release" : ( isTreatment ? "sampling" : "" ) ;
86
88
// Trace the interested LSP requests performance
87
89
javaExt . exports ?. onDidRequestEnd ( ( traceEvent : any ) => {
88
- if ( ! traceEvent . error && ! isPreReleaseVersion && ! isTreatment ) {
90
+ if ( ! isPreReleaseVersion && ! isTreatment ) {
91
+ return ;
92
+ }
93
+
94
+ if ( traceEvent . error ) {
95
+ let code : number = traceEvent . error ?. code || 0 ;
96
+ let errorMessage : string = traceEvent . error ?. message || String ( traceEvent . error ) ;
97
+ if ( code === CANCELLATION_CODE || code === CONTENT_MODIFIED_CODE ) {
98
+ return ;
99
+ }
100
+
101
+ sendInfo ( "" , {
102
+ name : "lsp" ,
103
+ kind : escapeLspRequestName ( traceEvent . type ) ,
104
+ duration : Math . trunc ( traceEvent . duration ) ,
105
+ code,
106
+ message : errorMessage ,
107
+ javaversion : javaExtVersion ,
108
+ remark : sampling ,
109
+ } ) ;
89
110
return ;
90
111
}
91
112
92
113
if ( INTERESTED_REQUESTS . has ( traceEvent . type ) ) {
93
114
// See https://github.com/redhat-developer/vscode-java/pull/3010
94
115
// to exclude the invalid completion requests.
95
- if ( ! traceEvent . error && ! traceEvent . resultLength && traceEvent . type === "textDocument/completion" ) {
116
+ if ( ! traceEvent . resultLength && traceEvent . type === "textDocument/completion" ) {
96
117
return ;
97
118
}
98
119
99
- sendTrace ( traceEvent , javaExtVersion , sampling ) ;
120
+ sendInfo ( "" , {
121
+ name : "lsp" ,
122
+ kind : escapeLspRequestName ( traceEvent . type ) ,
123
+ duration : Math . trunc ( traceEvent . duration ) ,
124
+ resultLength : traceEvent . resultLength ,
125
+ javaversion : javaExtVersion ,
126
+ remark : sampling ,
127
+ } ) ;
100
128
return ;
101
129
}
102
130
} ) ;
103
131
}
104
132
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
-
135
133
let corruptedCacheDetected : boolean = false ;
136
134
async function checkIfJavaServerCrashed ( wait : number = 0 /*ms*/ ) {
137
135
if ( corruptedCacheDetected ) {
0 commit comments