@@ -51,7 +51,7 @@ export class TestControllerManager {
51
51
public readonly debugProfile : vscode . TestRunProfile ;
52
52
private readonly refreshMutex = new Mutex ( ) ;
53
53
private readonly debugSessions = new Set < vscode . DebugSession > ( ) ;
54
-
54
+ private readonly didChangedTimer = new Map < vscode . TextDocument , number > ( ) ;
55
55
constructor (
56
56
public readonly extensionContext : vscode . ExtensionContext ,
57
57
public readonly languageClientsManager : LanguageClientsManager ,
@@ -81,21 +81,43 @@ export class TestControllerManager {
81
81
82
82
this . _disposables = vscode . Disposable . from (
83
83
fileWatcher ,
84
+ vscode . workspace . onDidCloseTextDocument ( ( document ) => {
85
+ if ( document . languageId !== "robotframework" ) return ;
86
+
87
+ if ( this . didChangedTimer . has ( document ) ) {
88
+ clearTimeout ( this . didChangedTimer . get ( document ) ) ;
89
+ this . didChangedTimer . delete ( document ) ;
90
+ }
91
+ } ) ,
84
92
vscode . workspace . onDidSaveTextDocument ( async ( document ) => {
85
93
if ( document . languageId !== "robotframework" ) return ;
86
94
95
+ if ( this . didChangedTimer . has ( document ) ) {
96
+ clearTimeout ( this . didChangedTimer . get ( document ) ) ;
97
+ }
98
+
87
99
await this . refresh ( this . findTestItemForDocument ( document ) ) ;
88
100
} ) ,
89
101
vscode . workspace . onDidOpenTextDocument ( async ( document ) => {
90
102
if ( document . languageId !== "robotframework" ) return ;
91
103
92
104
await this . refresh ( this . findTestItemForDocument ( document ) ) ;
93
105
} ) ,
94
- vscode . workspace . onDidChangeTextDocument ( async ( event ) => {
106
+ vscode . workspace . onDidChangeTextDocument ( ( event ) => {
95
107
if ( event . document . languageId !== "robotframework" ) return ;
96
- // TODO: refresh only once if several short changes are made
97
108
98
- await this . refresh ( this . findTestItemForDocument ( event . document ) ) ;
109
+ if ( this . didChangedTimer . has ( event . document ) ) {
110
+ clearTimeout ( this . didChangedTimer . get ( event . document ) ) ;
111
+ }
112
+ this . didChangedTimer . set (
113
+ event . document ,
114
+ setTimeout ( ( _ ) => {
115
+ this . refresh ( this . findTestItemForDocument ( event . document ) ) . then (
116
+ ( ) => undefined ,
117
+ ( ) => undefined
118
+ ) ;
119
+ } , 1000 )
120
+ ) ;
99
121
} ) ,
100
122
vscode . workspace . onDidChangeWorkspaceFolders ( async ( event ) => {
101
123
for ( const r of event . removed ) {
0 commit comments