@@ -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