@@ -14,13 +14,13 @@ import Foundation
1414public struct SourceRepository {
1515 /// The path at which the repository is cloned locally.
1616 public var checkoutPath : String
17-
17+
1818 /// The base URL where the service hosts the repository's contents.
1919 public var sourceServiceBaseURL : URL
20-
20+
2121 /// A function that formats a line number to be included in a URL.
2222 public var formatLineNumber : ( Int ) -> String
23-
23+
2424 /// Creates a source code repository.
2525 /// - Parameters:
2626 /// - 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 {
3131 sourceServiceBaseURL: URL ,
3232 formatLineNumber: @escaping ( Int ) -> String
3333 ) {
34+ if checkoutPath. starts ( with: " / " ) {
35+ self . checkoutPath = checkoutPath
36+ } else {
37+ self . checkoutPath = " \( FileManager . default. currentDirectoryPath) / \( checkoutPath) "
38+ }
39+
3440 self . checkoutPath = checkoutPath
3541 self . sourceServiceBaseURL = sourceServiceBaseURL
3642 self . formatLineNumber = formatLineNumber
3743 }
38-
44+
3945 /// Formats a local source file URL to a URL hosted by the remote source code service.
4046 /// - Parameters:
4147 /// - sourceFileURL: The location of the source file on disk.
@@ -45,7 +51,7 @@ public struct SourceRepository {
4551 guard sourceFileURL. path. hasPrefix ( checkoutPath) else {
4652 return nil
4753 }
48-
54+
4955 let path = sourceFileURL. path. dropFirst ( checkoutPath. count) . removingLeadingSlash
5056 return sourceServiceBaseURL
5157 . appendingPathComponent ( path)
@@ -65,7 +71,7 @@ public extension SourceRepository {
6571 formatLineNumber: { line in " L \( line) " }
6672 )
6773 }
68-
74+
6975 /// Creates a source repository hosted by the GitLab service.
7076 /// - Parameters:
7177 /// - checkoutPath: The path of the local checkout.
@@ -77,7 +83,7 @@ public extension SourceRepository {
7783 formatLineNumber: { line in " L \( line) " }
7884 )
7985 }
80-
86+
8187 /// Creates a source repository hosted by the BitBucket service.
8288 /// - Parameters:
8389 /// - checkoutPath: The path of the local checkout.
@@ -89,7 +95,7 @@ public extension SourceRepository {
8995 formatLineNumber: { line in " lines- \( line) " }
9096 )
9197 }
92-
98+
9399 /// Creates a source repository hosted by the device's filesystem.
94100 ///
95101 /// Use this source repository to format `doc-source-file://` links to files on the
@@ -98,7 +104,7 @@ public extension SourceRepository {
98104 /// This source repository uses a custom scheme to offer more control local source file navigation.
99105 static func localFilesystem( ) -> SourceRepository {
100106 SourceRepository (
101- checkoutPath: " " ,
107+ checkoutPath: " / " ,
102108 // 2 slashes to specify an empty authority/host component and 1 slash to specify a base path at the root.
103109 sourceServiceBaseURL: URL ( string: " doc-source-file:/// " ) !,
104110 formatLineNumber: { line in " L \( line) " }
0 commit comments