@@ -14,13 +14,13 @@ import Foundation
14
14
public struct SourceRepository {
15
15
/// The path at which the repository is cloned locally.
16
16
public var checkoutPath : String
17
-
17
+
18
18
/// The base URL where the service hosts the repository's contents.
19
19
public var sourceServiceBaseURL : URL
20
-
20
+
21
21
/// A function that formats a line number to be included in a URL.
22
22
public var formatLineNumber : ( Int ) -> String
23
-
23
+
24
24
/// Creates a source code repository.
25
25
/// - Parameters:
26
26
/// - checkoutPath: The path at which the repository is checked out locally and from which its symbol graphs were generated.
@@ -31,11 +31,17 @@ public struct SourceRepository {
31
31
sourceServiceBaseURL: URL ,
32
32
formatLineNumber: @escaping ( Int ) -> String
33
33
) {
34
+ if checkoutPath. starts ( with: " / " ) {
35
+ self . checkoutPath = checkoutPath
36
+ } else {
37
+ self . checkoutPath = " \( FileManager . default. currentDirectoryPath) / \( checkoutPath) "
38
+ }
39
+
34
40
self . checkoutPath = checkoutPath
35
41
self . sourceServiceBaseURL = sourceServiceBaseURL
36
42
self . formatLineNumber = formatLineNumber
37
43
}
38
-
44
+
39
45
/// Formats a local source file URL to a URL hosted by the remote source code service.
40
46
/// - Parameters:
41
47
/// - sourceFileURL: The location of the source file on disk.
@@ -45,7 +51,7 @@ public struct SourceRepository {
45
51
guard sourceFileURL. path. hasPrefix ( checkoutPath) else {
46
52
return nil
47
53
}
48
-
54
+
49
55
let path = sourceFileURL. path. dropFirst ( checkoutPath. count) . removingLeadingSlash
50
56
return sourceServiceBaseURL
51
57
. appendingPathComponent ( path)
@@ -65,7 +71,7 @@ public extension SourceRepository {
65
71
formatLineNumber: { line in " L \( line) " }
66
72
)
67
73
}
68
-
74
+
69
75
/// Creates a source repository hosted by the GitLab service.
70
76
/// - Parameters:
71
77
/// - checkoutPath: The path of the local checkout.
@@ -77,7 +83,7 @@ public extension SourceRepository {
77
83
formatLineNumber: { line in " L \( line) " }
78
84
)
79
85
}
80
-
86
+
81
87
/// Creates a source repository hosted by the BitBucket service.
82
88
/// - Parameters:
83
89
/// - checkoutPath: The path of the local checkout.
@@ -89,7 +95,7 @@ public extension SourceRepository {
89
95
formatLineNumber: { line in " lines- \( line) " }
90
96
)
91
97
}
92
-
98
+
93
99
/// Creates a source repository hosted by the device's filesystem.
94
100
///
95
101
/// Use this source repository to format `doc-source-file://` links to files on the
@@ -98,7 +104,7 @@ public extension SourceRepository {
98
104
/// This source repository uses a custom scheme to offer more control local source file navigation.
99
105
static func localFilesystem( ) -> SourceRepository {
100
106
SourceRepository (
101
- checkoutPath: " " ,
107
+ checkoutPath: " / " ,
102
108
// 2 slashes to specify an empty authority/host component and 1 slash to specify a base path at the root.
103
109
sourceServiceBaseURL: URL ( string: " doc-source-file:/// " ) !,
104
110
formatLineNumber: { line in " L \( line) " }
0 commit comments