Skip to content

Commit 1132194

Browse files
committed
correct updating testitems if document saved
1 parent 5f20a59 commit 1132194

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

vscode-client/testcontrollermanager.ts

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -120,45 +120,16 @@ export class TestControllerManager {
120120
this.didChangedTimer.delete(uri_str);
121121
}
122122
}),
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);
133125
}),
134126
vscode.workspace.onDidOpenTextDocument(async (document) => {
135127
if (document.languageId !== "robotframework") return;
136128

137129
await this.refresh(this.findTestItemForDocument(document));
138130
}),
139131
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);
162133
}),
163134
vscode.workspace.onDidChangeWorkspaceFolders(async (event) => {
164135
for (const r of event.removed) {
@@ -269,6 +240,31 @@ export class TestControllerManager {
269240
}
270241
}
271242

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+
272268
public findTestItemForDocument(document: vscode.TextDocument): vscode.TestItem | undefined {
273269
return this.findTestItemByUri(document.uri.toString());
274270
}

0 commit comments

Comments
 (0)