Skip to content

Commit 9fa5200

Browse files
committed
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
1 parent 8f9aaed commit 9fa5200

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Sources/LanguageServerProtocol/SupportTypes/DocumentURI.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,21 @@ public struct DocumentURI: Codable, Hashable, Sendable {
4848
/// fallback mode that drops semantic functionality.
4949
public var pseudoPath: String {
5050
if storage.isFileURL {
51-
return storage.withUnsafeFileSystemRepresentation {
52-
String(cString: $0!)
51+
return storage.withUnsafeFileSystemRepresentation { filePathPtr in
52+
guard let filePathPtr else {
53+
return ""
54+
}
55+
let filePath = String(cString: filePathPtr)
56+
#if os(Windows)
57+
// VS Code spells file paths with a lowercase drive letter, while the rest of Windows APIs use an uppercase
58+
// drive letter. Normalize the drive letter spelling to be uppercase.
59+
if filePath.first?.isASCII ?? false, filePath.first?.isLetter ?? false, filePath.first?.isLowercase ?? false,
60+
filePath.count > 1, filePath[filePath.index(filePath.startIndex, offsetBy: 1)] == ":"
61+
{
62+
return filePath.first!.uppercased() + filePath.dropFirst()
63+
}
64+
#endif
65+
return filePath
5366
}
5467
} else {
5568
return storage.absoluteString

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ public actor SkipUnless {
415415
try XCTSkipUnless(Platform.current == .darwin, message)
416416
}
417417

418+
public static func platformIsWindows(_ message: String) throws {
419+
try XCTSkipUnless(Platform.current == .windows, message)
420+
}
421+
418422
public static func platformSupportsTaskPriorityElevation() throws {
419423
#if os(macOS)
420424
guard #available(macOS 14.0, *) else {

0 commit comments

Comments
 (0)