File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -56,20 +56,31 @@ extension CodeEditCLI {
5656 }
5757
5858 private func extractLineColumn( _ path: String ) throws -> ( path: String , line: Int ? , column: Int ? ) {
59+
60+ // split the string at `:` to get line and column numbers
5961 let components = path. split ( separator: " : " )
60- let path = String ( components [ 0 ] )
6162
63+ // set path to only the first component
64+ guard let first = components. first else {
65+ throw CLIError . invalidFileURL
66+ }
67+ let path = String ( first)
68+
69+ // switch on the number of components
6270 switch components. count {
63- case 1 :
71+ case 1 : // no line or column number provided
6472 return ( path, nil , nil )
65- case 2 :
73+
74+ case 2 : // only line number provided
6675 guard let row = Int ( components [ 1 ] ) else { throw CLIError . invalidFileURL }
6776 return ( path, row, nil )
68- case ( 3 ... ) :
77+
78+ case 3 : // line and column number provided
6979 guard let row = Int ( components [ 1 ] ) ,
7080 let column = Int ( components [ 2 ] ) else { throw CLIError . invalidFileURL }
7181 return ( path, row, column)
72- default :
82+
83+ default : // any other case throw an error since this is invalid
7384 throw CLIError . invalidFileURL
7485 }
7586 }
You can’t perform that action at this time.
0 commit comments