Skip to content

Commit

Permalink
Normalize Windows drive letter to be uppercase
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ahoppen committed Dec 11, 2024
1 parent 8f9aaed commit 9fa5200
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Sources/LanguageServerProtocol/SupportTypes/DocumentURI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Sources/SKTestSupport/SkipUnless.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9fa5200

Please sign in to comment.