Files
sourcekit-lsp/Sources/SourceKitLSP/IndexStoreDB+MainFilesProvider.swift
Alex Hoppen 951e923245 Use withUnsafeFileSystemRepresentation to get the path of a URL on disk
`URL.path` returns forward slashes in the path on Windows (https://github.com/swiftlang/swift-foundation/issues/973) where we expect backslashes. Work around that by defining our own `filePath` property that is backed by `withUnsafeFileSystemRepresentation`, which produces backslashes.

rdar://137963660
2024-10-21 11:12:30 -07:00

48 lines
1.5 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 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
//
//===----------------------------------------------------------------------===//
#if compiler(>=6)
import BuildSystemIntegration
import Foundation
package import LanguageServerProtocol
import SKLogging
import SemanticIndex
import SwiftExtensions
#else
import BuildSystemIntegration
import Foundation
import LanguageServerProtocol
import SKLogging
import SemanticIndex
import SwiftExtensions
#endif
extension UncheckedIndex {
package func mainFilesContainingFile(_ uri: DocumentURI) -> Set<DocumentURI> {
let mainFiles: Set<DocumentURI>
if let filePath = orLog("File path to get main files", { try uri.fileURL?.filePath }) {
let mainFilePaths = Set(self.underlyingIndexStoreDB.mainFilesContainingFile(path: filePath))
mainFiles = Set(
mainFilePaths
.filter { FileManager.default.fileExists(atPath: $0) }
.map({ DocumentURI(filePath: $0, isDirectory: false) })
)
} else {
mainFiles = []
}
logger.info("mainFilesContainingFile(\(uri.forLogging)) -> \(mainFiles)")
return mainFiles
}
}
extension UncheckedIndex: BuildSystemIntegration.MainFilesProvider {}