Files
sourcekit-lsp/Sources/SwiftLanguageService/TestDiscovery.swift
T
Rintaro Ishizaki 26f8efed5f [TestDiscovery] Use file modification time to filter semantic index
Instead of querying the index twice (once for up-to-date files, once for
outdated ones), collect file modification timestamps during the syntactic
scan phase and use them to filter a single semantic index query.
For files that don't support syntactic scans, use the semantic index
results even if outdated.

Also extracts symlink-aware mtime resolution into URL.fileModificationDate
and exposes snapshotHasInMemoryModifications(_:) on DocumentManager.
2026-03-06 15:33:19 -08:00

42 lines
1.6 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import BuildServerIntegration
@_spi(SourceKitLSP) import BuildServerProtocol
import Foundation
@_spi(SourceKitLSP) import SKLogging
import SemanticIndex
package import SourceKitLSP
import SwiftExtensions
extension SwiftLanguageService {
/// Syntactically scans the snapshot for tests declared within it.
///
/// Does not write the results to the index.
///
/// The order of the returned tests is not defined. The results should be sorted before being returned to the editor.
package func syntacticTestItems(
for snapshot: DocumentSnapshot,
) async -> [AnnotatedTestItem]? {
// Don't use the `self.syntaxTreeManager` for snapshots with version number 0,
// which indicates they were loaded from disk.
let syntaxTreeManager = snapshot.version != 0 ? self.syntaxTreeManager : SyntaxTreeManager()
async let swiftTestingTests = SyntacticSwiftTestingTestScanner.findTestSymbols(
in: snapshot,
syntaxTreeManager: syntaxTreeManager
)
async let xcTests = SyntacticSwiftXCTestScanner.findTestSymbols(in: snapshot, syntaxTreeManager: syntaxTreeManager)
return await swiftTestingTests + xcTests
}
}