99*/
1010
1111import Foundation
12+ import ArgumentParser
1213
1314/// A remote repository that hosts source code.
1415public struct SourceRepository {
1516 /// The path at which the repository is cloned locally.
1617 public var checkoutPath : String
17-
18+
1819 /// The base URL where the service hosts the repository's contents.
1920 public var sourceServiceBaseURL : URL
20-
21+
2122 /// A function that formats a line number to be included in a URL.
2223 public var formatLineNumber : ( Int ) -> String
23-
24+
2425 /// Creates a source code repository.
2526 /// - Parameters:
2627 /// - checkoutPath: The path at which the repository is checked out locally and from which its symbol graphs were generated.
2728 /// - sourceServiceBaseURL: The base URL where the service hosts the repository's contents.
2829 /// - formatLineNumber: A function that formats a line number to be included in a URL.
29- public init (
30+ public init (
3031 checkoutPath: String ,
3132 sourceServiceBaseURL: URL ,
3233 formatLineNumber: @escaping ( Int ) -> String
3334 ) {
34- self . checkoutPath = checkoutPath
35+
36+
37+ // guard FileManager.default.directoryExists(atPath: checkoutPath) else {
38+ // throw ValidationError("User provided checkout-path argument {checkoutPath} is invalid.")
39+ // }
40+ let absoluteCheckoutPath = URL ( fileURLWithPath: checkoutPath) . absoluteString
41+ let startIndex = absoluteCheckoutPath. index ( absoluteCheckoutPath. startIndex, offsetBy: 7 )
42+
43+ self . checkoutPath = String ( absoluteCheckoutPath [ startIndex... ] )
3544 self . sourceServiceBaseURL = sourceServiceBaseURL
3645 self . formatLineNumber = formatLineNumber
3746 }
38-
47+
3948 /// Formats a local source file URL to a URL hosted by the remote source code service.
4049 /// - Parameters:
4150 /// - sourceFileURL: The location of the source file on disk.
@@ -45,7 +54,7 @@ public struct SourceRepository {
4554 guard sourceFileURL. path. hasPrefix ( checkoutPath) else {
4655 return nil
4756 }
48-
57+
4958 let path = sourceFileURL. path. dropFirst ( checkoutPath. count) . removingLeadingSlash
5059 return sourceServiceBaseURL
5160 . appendingPathComponent ( path)
@@ -65,7 +74,7 @@ public extension SourceRepository {
6574 formatLineNumber: { line in " L \( line) " }
6675 )
6776 }
68-
77+
6978 /// Creates a source repository hosted by the GitLab service.
7079 /// - Parameters:
7180 /// - checkoutPath: The path of the local checkout.
@@ -77,7 +86,7 @@ public extension SourceRepository {
7786 formatLineNumber: { line in " L \( line) " }
7887 )
7988 }
80-
89+
8190 /// Creates a source repository hosted by the BitBucket service.
8291 /// - Parameters:
8392 /// - checkoutPath: The path of the local checkout.
@@ -89,7 +98,7 @@ public extension SourceRepository {
8998 formatLineNumber: { line in " lines- \( line) " }
9099 )
91100 }
92-
101+
93102 /// Creates a source repository hosted by the device's filesystem.
94103 ///
95104 /// Use this source repository to format `doc-source-file://` links to files on the
@@ -98,7 +107,7 @@ public extension SourceRepository {
98107 /// This source repository uses a custom scheme to offer more control local source file navigation.
99108 static func localFilesystem( ) -> SourceRepository {
100109 SourceRepository (
101- checkoutPath: " " ,
110+ checkoutPath: " / " ,
102111 // 2 slashes to specify an empty authority/host component and 1 slash to specify a base path at the root.
103112 sourceServiceBaseURL: URL ( string: " doc-source-file:/// " ) !,
104113 formatLineNumber: { line in " L \( line) " }
0 commit comments