From 9fa52008d9b968701655f47412f47116f587d6a5 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Tue, 10 Dec 2024 15:57:04 -0800 Subject: [PATCH] Normalize Windows drive letter to be uppercase VS Code spells file paths with a lowercase drive letter, while the rest of Windows APIs use an uppercase drive letter. Normalize the drive letter spelling to be uppercase. Fixes #1855 rdar://141001203 --- .../SupportTypes/DocumentURI.swift | 17 +++++++++++++++-- Sources/SKTestSupport/SkipUnless.swift | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Sources/LanguageServerProtocol/SupportTypes/DocumentURI.swift b/Sources/LanguageServerProtocol/SupportTypes/DocumentURI.swift index 2eea9c173..7d83569ec 100644 --- a/Sources/LanguageServerProtocol/SupportTypes/DocumentURI.swift +++ b/Sources/LanguageServerProtocol/SupportTypes/DocumentURI.swift @@ -48,8 +48,21 @@ public struct DocumentURI: Codable, Hashable, Sendable { /// fallback mode that drops semantic functionality. public var pseudoPath: String { if storage.isFileURL { - return storage.withUnsafeFileSystemRepresentation { - String(cString: $0!) + return storage.withUnsafeFileSystemRepresentation { filePathPtr in + guard let filePathPtr else { + return "" + } + let filePath = String(cString: filePathPtr) + #if os(Windows) + // VS Code spells file paths with a lowercase drive letter, while the rest of Windows APIs use an uppercase + // drive letter. Normalize the drive letter spelling to be uppercase. + if filePath.first?.isASCII ?? false, filePath.first?.isLetter ?? false, filePath.first?.isLowercase ?? false, + filePath.count > 1, filePath[filePath.index(filePath.startIndex, offsetBy: 1)] == ":" + { + return filePath.first!.uppercased() + filePath.dropFirst() + } + #endif + return filePath } } else { return storage.absoluteString diff --git a/Sources/SKTestSupport/SkipUnless.swift b/Sources/SKTestSupport/SkipUnless.swift index f22c79cdc..54cb80fce 100644 --- a/Sources/SKTestSupport/SkipUnless.swift +++ b/Sources/SKTestSupport/SkipUnless.swift @@ -415,6 +415,10 @@ public actor SkipUnless { try XCTSkipUnless(Platform.current == .darwin, message) } + public static func platformIsWindows(_ message: String) throws { + try XCTSkipUnless(Platform.current == .windows, message) + } + public static func platformSupportsTaskPriorityElevation() throws { #if os(macOS) guard #available(macOS 14.0, *) else {