@@ -120,45 +120,16 @@ export class TestControllerManager {
120
120
this . didChangedTimer . delete ( uri_str ) ;
121
121
}
122
122
} ) ,
123
- vscode . workspace . onDidSaveTextDocument ( async ( document ) => {
124
- if ( document . languageId !== "robotframework" ) return ;
125
-
126
- const uri_str = document . uri . toString ( ) ;
127
- if ( this . didChangedTimer . has ( uri_str ) ) {
128
- this . didChangedTimer . get ( uri_str ) ?. cancel ( ) ;
129
- this . didChangedTimer . delete ( uri_str ) ;
130
- }
131
-
132
- await this . refresh ( this . findTestItemForDocument ( document ) ) ;
123
+ vscode . workspace . onDidSaveTextDocument ( ( document ) => {
124
+ this . addRefreshDocumentTimer ( document ) ;
133
125
} ) ,
134
126
vscode . workspace . onDidOpenTextDocument ( async ( document ) => {
135
127
if ( document . languageId !== "robotframework" ) return ;
136
128
137
129
await this . refresh ( this . findTestItemForDocument ( document ) ) ;
138
130
} ) ,
139
131
vscode . workspace . onDidChangeTextDocument ( ( event ) => {
140
- if ( event . document . languageId !== "robotframework" ) return ;
141
-
142
- const uri_str = event . document . uri . toString ( ) ;
143
- if ( this . didChangedTimer . has ( uri_str ) ) {
144
- this . didChangedTimer . get ( uri_str ) ?. cancel ( ) ;
145
- this . didChangedTimer . delete ( uri_str ) ;
146
- }
147
-
148
- const token = new vscode . CancellationTokenSource ( ) ;
149
-
150
- this . didChangedTimer . set (
151
- uri_str ,
152
- new DidChangeEntry (
153
- setTimeout ( ( _ ) => {
154
- this . refresh ( this . findTestItemForDocument ( event . document ) ) . then (
155
- ( ) => undefined ,
156
- ( ) => undefined
157
- ) ;
158
- } , 1000 ) ,
159
- token
160
- )
161
- ) ;
132
+ this . addRefreshDocumentTimer ( event . document ) ;
162
133
} ) ,
163
134
vscode . workspace . onDidChangeWorkspaceFolders ( async ( event ) => {
164
135
for ( const r of event . removed ) {
@@ -269,6 +240,31 @@ export class TestControllerManager {
269
240
}
270
241
}
271
242
243
+ public addRefreshDocumentTimer ( document : vscode . TextDocument ) : void {
244
+ if ( document . languageId !== "robotframework" ) return ;
245
+
246
+ const uri_str = document . uri . toString ( ) ;
247
+ if ( this . didChangedTimer . has ( uri_str ) ) {
248
+ this . didChangedTimer . get ( uri_str ) ?. cancel ( ) ;
249
+ this . didChangedTimer . delete ( uri_str ) ;
250
+ }
251
+
252
+ const token = new vscode . CancellationTokenSource ( ) ;
253
+
254
+ this . didChangedTimer . set (
255
+ uri_str ,
256
+ new DidChangeEntry (
257
+ setTimeout ( ( _ ) => {
258
+ this . refresh ( this . findTestItemForDocument ( document ) ) . then (
259
+ ( ) => undefined ,
260
+ ( ) => undefined
261
+ ) ;
262
+ } , 1000 ) ,
263
+ token
264
+ )
265
+ ) ;
266
+ }
267
+
272
268
public findTestItemForDocument ( document : vscode . TextDocument ) : vscode . TestItem | undefined {
273
269
return this . findTestItemByUri ( document . uri . toString ( ) ) ;
274
270
}
0 commit comments