@@ -38,7 +38,7 @@ function formatInput(
3838 result : FormattableResult & WithInput ,
3939 options : FormatOptions = { } ,
4040) : string [ ] {
41- const { color : enabled = true , showPosition = false } = options ;
41+ const { color : enabled = true , showPosition = true } = options ;
4242 const { errors = [ ] , warnings = [ ] , input = "" } = result ;
4343
4444 if ( ! input ) {
@@ -47,19 +47,20 @@ function formatInput(
4747
4848 const sign = "⧗" ;
4949 const decoration = enabled ? pc . gray ( sign ) : sign ;
50+ const prefix = `${ decoration } input: ` ;
5051
5152 const decoratedInput = enabled ? pc . bold ( input ) : input ;
5253 const hasProblems = errors . length > 0 || warnings . length > 0 ;
5354
5455 if ( ! hasProblems ) {
55- return options . verbose ? [ `${ decoration } input: ${ decoratedInput } ` ] : [ ] ;
56+ return options . verbose ? [ `${ prefix } ${ decoratedInput } ` ] : [ ] ;
5657 }
5758
5859 const positionIndicator = showPosition
59- ? getPositionIndicator ( [ ...errors , ...warnings ] , input )
60+ ? getPositionIndicator ( [ ...errors , ...warnings ] , input , prefix . length )
6061 : undefined ;
6162
62- const lines : string [ ] = [ `${ decoration } input: ${ decoratedInput } ` ] ;
63+ const lines : string [ ] = [ `${ prefix } ${ decoratedInput } ` ] ;
6364
6465 if ( positionIndicator ) {
6566 lines . push ( positionIndicator ) ;
@@ -71,6 +72,7 @@ function formatInput(
7172function getPositionIndicator (
7273 problems : FormattableProblem [ ] ,
7374 input : string ,
75+ prefixLength : number ,
7476) : string | undefined {
7577 const problemWithPosition = problems . find (
7678 ( problem ) => problem ?. start !== undefined && problem ?. end !== undefined ,
@@ -79,28 +81,21 @@ function getPositionIndicator(
7981 return undefined ;
8082 }
8183
82- const { start, end } = problemWithPosition ;
83- const padding = " " ;
84+ const padding = " " . repeat ( prefixLength ) ;
8485
85- const tilde = "~ " ;
86+ const caret = "^ " ;
8687
8788 const normalizedInput = input . replace ( / \r \n / g, "\n" ) . replace ( / \r / g, "\n" ) ;
8889 const lines = normalizedInput . split ( "\n" ) ;
89- const targetLine = lines [ start . line - 1 ] ;
90+ const targetLine = lines [ problemWithPosition . start . line - 1 ] ;
9091
9192 if ( ! targetLine ) {
9293 return undefined ;
9394 }
9495
95- const lineLength = targetLine . length ;
96- const spacesBefore = Math . max ( 0 , start . column - 1 ) ;
97- const tildeLength = Math . max (
98- 1 ,
99- Math . min ( end . column - start . column , lineLength - ( start . column - 1 ) ) ,
100- ) ;
96+ const spacesBefore = Math . max ( 0 , problemWithPosition . start . column - 1 ) ;
10197
102- const indicator =
103- padding + " " . repeat ( spacesBefore ) + tilde . repeat ( tildeLength ) ;
98+ const indicator = padding + " " . repeat ( spacesBefore ) + caret ;
10499
105100 return indicator ;
106101}
0 commit comments