Skip to content

Commit 67b98cd

Browse files
committed
Batch updates to the syntactic test index on fileDidChange events
This is more performant. In particular adding a new task to `indexingQueue` for each file to rescan can hit the quadratic issue in `AsyncQueue` if many files were changed.
1 parent 9bbb8f3 commit 67b98cd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Sources/SourceKitLSP/Swift/SyntacticTestIndex.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,24 @@ actor SyntacticTestIndex {
129129
}
130130

131131
func filesDidChange(_ events: [FileEvent]) {
132+
var removedFiles: Set<DocumentURI> = []
133+
var filesToRescan: [DocumentURI] = []
132134
for fileEvent in events {
133135
switch fileEvent.type {
134136
case .created:
135137
// We don't know if this is a potential test file. It would need to be added to the index via
136138
// `listOfTestFilesDidChange`
137139
break
138140
case .changed:
139-
rescanFiles([fileEvent.uri])
141+
filesToRescan.append(fileEvent.uri)
140142
case .deleted:
141-
removeFilesFromIndex([fileEvent.uri])
143+
removedFiles.insert(fileEvent.uri)
142144
default:
143145
logger.error("Ignoring unknown FileEvent type \(fileEvent.type.rawValue) in SyntacticTestIndex")
144146
}
145147
}
148+
removeFilesFromIndex(removedFiles)
149+
rescanFiles(filesToRescan)
146150
}
147151

148152
/// Called when a list of files was updated. Re-scans those files

0 commit comments

Comments
 (0)