File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
Sources/SourceKitLSP/Swift Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,9 @@ import SKCore
18
18
import SKSupport
19
19
import SourceKitD
20
20
import TSCBasic
21
+ #if os(Windows)
22
+ import WinSDK
23
+ #endif
21
24
22
25
fileprivate extension Range {
23
26
/// Checks if this range overlaps with the other range, counting an overlap with an empty range as a valid overlap.
@@ -1130,7 +1133,24 @@ extension SwiftLanguageServer: SKDNotificationHandler {
1130
1133
1131
1134
self . queue. async {
1132
1135
let uri : DocumentURI
1133
- if name. starts ( with: " / " ) {
1136
+
1137
+ // Paths are expected to be absolute; on Windows, this means that the
1138
+ // path is either drive letter prefixed (and thus `PathGetDriveNumberW`
1139
+ // will provide the driver number OR it is a UNC path and `PathIsUNCW`
1140
+ // will return `true`. On Unix platforms, the path will start with `/`
1141
+ // which takes care of both a regular absolute path and a POSIX
1142
+ // alternate root path.
1143
+
1144
+ // TODO: this is not completely portable, e.g. MacOS 9 HFS paths are
1145
+ // unhandled.
1146
+ #if os(Windows)
1147
+ let isPath : Bool = name. withCString ( encodedAs: UTF16 . self) {
1148
+ PathIsUNCW ( $0) || ( 0 ... 25 ) ~= PathGetDriveNumberW ( $0)
1149
+ }
1150
+ #else
1151
+ let isPath : Bool = name. starts ( with: " / " )
1152
+ #endif
1153
+ if isPath {
1134
1154
// If sourcekitd returns us a path, translate it back into a URL
1135
1155
uri = DocumentURI ( URL ( fileURLWithPath: name) )
1136
1156
} else {
You can’t perform that action at this time.
0 commit comments