Skip to content

Commit 942f86b

Browse files
committed
Show tests as needing re-run when the tests file is modified
1 parent ab9cca9 commit 942f86b

5 files changed

Lines changed: 71 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [0.83.0]
4+
5+
* Show tests as needing re-run when the tests file is modified
6+
* Fix the "Problems" pane not being cleared when the tests file is modified
7+
* Fix the "Problems" pane not updating when re-running tests when the test files were not modified
8+
39
## [0.82.0]
410

511
* Changed file system calls to use the VSCode API instead of the Node API

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "logtalk-for-vscode",
33
"displayName": "Logtalk for VSCode",
44
"description": "Logtalk programming support",
5-
"version": "0.82.0",
5+
"version": "0.83.0",
66
"publisher": "LogtalkDotOrg",
77
"icon": "images/logtalk.png",
88
"license": "MIT",
@@ -1328,7 +1328,7 @@
13281328
"compile": "tsc -watch -p ./",
13291329
"test": "tsc ./tests/runTest.ts",
13301330
"vsix:make": "vsce package --baseImagesUrl https://raw.githubusercontent.com/llvm/llvm-project/master/clang-tools-extra/clangd/clients/clangd-vscode/",
1331-
"vsix:install": "code --install-extension logtalk-for-vscode-0.82.0.vsix"
1331+
"vsix:install": "code --install-extension logtalk-for-vscode-0.83.0.vsix"
13321332
},
13331333
"devDependencies": {
13341334
"@types/bluebird": "^3.5.38",

src/features/terminal.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,9 @@ export default class LogtalkTerminal {
997997
uri = window.activeTextEditor.document.uri;
998998
}
999999

1000+
// Clear all existing test diagnostics before running tests
1001+
testsReporter.clearAll();
1002+
10001003
// Declare Variables
10011004
// Check if URI is a directory or file
10021005
let dir0: string;
@@ -1088,6 +1091,9 @@ export default class LogtalkTerminal {
10881091
uri = window.activeTextEditor.document.uri;
10891092
}
10901093

1094+
// Clear all existing test diagnostics before running tests
1095+
testsReporter.clearAll();
1096+
10911097
// Declare Variables
10921098
const dir0 = path.dirname(uri.fsPath);
10931099

@@ -1163,6 +1169,9 @@ export default class LogtalkTerminal {
11631169
uri = window.activeTextEditor.document.uri;
11641170
}
11651171

1172+
// Clear all existing test diagnostics before running tests
1173+
testsReporter.clearAll();
1174+
11661175
// Declare Variables
11671176
const dir0 = path.dirname(uri.fsPath);
11681177

@@ -1239,6 +1248,9 @@ export default class LogtalkTerminal {
12391248
uri = window.activeTextEditor.document.uri;
12401249
}
12411250

1251+
// Clear all existing test diagnostics before running tests
1252+
testsReporter.clearAll();
1253+
12421254
// Declare Variables
12431255
const dir0 = path.dirname(uri.fsPath);
12441256

@@ -1654,6 +1666,11 @@ export default class LogtalkTerminal {
16541666
LogtalkTerminal.createLogtalkTerm();
16551667
LogtalkTerminal._outputChannel.clear();
16561668

1669+
// Clear all existing test diagnostics before running tests
1670+
if (testsReporter) {
1671+
testsReporter.clearAll();
1672+
}
1673+
16571674
const dir = LogtalkTerminal.getWorkspaceFolderForUri(uri);
16581675
if (!dir) {
16591676
vscode.window.showErrorMessage('No workspace folder open');
@@ -1710,6 +1727,9 @@ export default class LogtalkTerminal {
17101727
LogtalkTerminal.createLogtalkTerm();
17111728
LogtalkTerminal._outputChannel.clear();
17121729

1730+
// Clear all existing test diagnostics before running tests
1731+
testsReporter.clearAll();
1732+
17131733
const dir = LogtalkTerminal.getWorkspaceFolderForUri(uri);
17141734
if (!dir) {
17151735
vscode.window.showErrorMessage('No workspace folder open');

src/features/testsCodeActionProvider.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ export default class LogtalkTestsReporter implements CodeActionProvider {
274274
DiagnosticsUtils.updateDiagnostics(this.diagnosticCollection, uri, diagnosticToRemove);
275275
}
276276

277+
public clearAll() {
278+
this.diagnosticCollection.clear();
279+
this.diagnostics = {};
280+
this.diagnosticHash = [];
281+
}
282+
277283
private removeDuplicateDiagnostics(diagnostics: Diagnostic[]): Diagnostic[] {
278284
return DiagnosticsUtils.removeDuplicateDiagnostics(diagnostics);
279285
}
@@ -314,6 +320,21 @@ export default class LogtalkTestsReporter implements CodeActionProvider {
314320
subscriptions
315321
);
316322

323+
// Clear diagnostics when a test file is modified
324+
workspace.onDidChangeTextDocument(
325+
textDocumentChangeEvent => {
326+
if (textDocumentChangeEvent.contentChanges.length > 0) {
327+
const filePath = textDocumentChangeEvent.document.uri.fsPath;
328+
if (filePath in this.diagnostics) {
329+
this.diagnosticCollection.delete(textDocumentChangeEvent.document.uri);
330+
this.diagnostics[filePath] = [];
331+
}
332+
}
333+
},
334+
this,
335+
subscriptions
336+
);
337+
317338
this.loadConfiguration();
318339

319340
workspace.onDidCloseTextDocument(

src/features/testsExplorer.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@ export class LogtalkTestsExplorerProvider implements Disposable {
290290
}
291291
});
292292
this.disposables.push(saveDocumentListener);
293+
294+
// Watch for source file modifications to invalidate test results
295+
// This marks tests as needing re-run when the file is edited
296+
const changeDocumentListener = workspace.onDidChangeTextDocument(event => {
297+
// Only process Logtalk files with actual content changes
298+
if (event.document.languageId === 'logtalk' && event.contentChanges.length > 0) {
299+
this.invalidateTestResultsForFile(event.document.uri);
300+
}
301+
});
302+
this.disposables.push(changeDocumentListener);
293303
}
294304

295305
/**
@@ -1744,7 +1754,8 @@ export class LogtalkTestsExplorerProvider implements Disposable {
17441754

17451755
/**
17461756
* Invalidate test results for a specific source file
1747-
* This marks all test items associated with the file as outdated
1757+
* This marks all test items associated with the file as needing re-run
1758+
* while preserving the counter for tests in other files
17481759
*/
17491760
private invalidateTestResultsForFile(uri: Uri): void {
17501761
const normalizedPath = Utils.normalizeFilePath(uri.fsPath);
@@ -1761,23 +1772,23 @@ export class LogtalkTestsExplorerProvider implements Disposable {
17611772
return;
17621773
}
17631774

1764-
// Collect all test items for this file (file, objects, and individual tests)
1765-
const testItemsToInvalidate: TestItem[] = [fileItem];
1775+
// Collect individual test items for this file
1776+
const individualTestItems: TestItem[] = [];
17661777

1767-
// Add all object-level items
1778+
// Add all individual test items from each object
17681779
fileItem.children.forEach(objectItem => {
1769-
testItemsToInvalidate.push(objectItem);
1770-
1771-
// Add all individual test items
17721780
objectItem.children.forEach(testItem => {
1773-
testItemsToInvalidate.push(testItem);
1781+
individualTestItems.push(testItem);
17741782
});
17751783
});
17761784

1777-
// Invalidate all collected test items
1778-
this.controller.invalidateTestResults(testItemsToInvalidate);
1785+
// Mark individual tests as needing re-run (shows enqueued icon)
1786+
// Use individual test runs to avoid resetting the counter for other files
1787+
for (const testItem of individualTestItems) {
1788+
this.markTestAsNeedsRerun(testItem);
1789+
}
17791790

1780-
this.logger.debug(`Invalidated ${testItemsToInvalidate.length} test item(s) for file: ${fileUri.fsPath}`);
1791+
this.logger.debug(`Marked ${individualTestItems.length} test(s) as needing re-run for file: ${fileUri.fsPath}`);
17811792
}
17821793

17831794
/**

0 commit comments

Comments
 (0)