Skip to content

Commit

Permalink
Made file paths in errors clickable (#437)
Browse files Browse the repository at this point in the history
This commit adds a space into errors which make them detectable by
GoLand as file links, and allows it to automatically make those links
clickable.

### Before
<img width="717" alt="Screenshot 2022-10-13 at 13 49 28"
src="https://user-images.githubusercontent.com/236641/195601258-c4eb2768-f561-4930-b9e0-9f78da062d3a.png">

### After
<img width="721" alt="Screenshot 2022-10-13 at 13 50 40"
src="https://user-images.githubusercontent.com/236641/195601282-fb3f41b9-48e6-4b08-a028-0b0eed48b4e5.png">
  • Loading branch information
DomBlack authored Oct 13, 2022
1 parent 6b18d27 commit ead1550
Show file tree
Hide file tree
Showing 21 changed files with 26 additions and 23 deletions.
5 changes: 4 additions & 1 deletion pkg/errinsrc/srcrender.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func renderSrc(builder *strings.Builder, causes SrcLocations) {
// Render the filename
builder.WriteString(strings.Repeat(" ", numDigitsInLineNumbers+1))
builder.WriteString(aurora.Gray(grayLevelOnLineNumbers, fmt.Sprintf(" %c%c%c", set.LeftTop, set.HorizontalBar, set.LeftBracket)).String())
builder.WriteString(aurora.Cyan(fmt.Sprintf("%s:%d:%d",
// Note the space on both sides of this string is important
// as it allows editors (such as GoLand) to pickup the filename in
// terminal output and convert it into a clickable link into the code
builder.WriteString(aurora.Cyan(fmt.Sprintf(" %s:%d:%d ",
causes[0].File.RelPath,
causes[0].Start.Line,
causes[0].Start.Col,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

,-[/test.cue:5:7]
,-[ /test.cue:5:7 ]
|
3 | // This is a sample file
4 | blah: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

╭─[/test.cue:5:7]
╭─[ /test.cue:5:7 ]
3 │ // This is a sample file
4 │ blah: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

,-[/test.cue:5:7]
,-[ /test.cue:5:7 ]
|
3 | // This is a sample file
4 | blah: {
Expand All @@ -14,7 +14,7 @@ There has been a simple error in your code
7 | }
---'

,-[/test.cue:5:2]
,-[ /test.cue:5:2 ]
|
3 | // This is a sample file
4 | blah: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

╭─[/test.cue:5:7]
╭─[ /test.cue:5:7 ]
3 │ // This is a sample file
4 │ blah: {
Expand All @@ -14,7 +14,7 @@ There has been a simple error in your code
7 │ }
───╯

╭─[/test.cue:5:2]
╭─[ /test.cue:5:2 ]
3 │ // This is a sample file
4 │ blah: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

,-[/test.cue:5:7]
,-[ /test.cue:5:7 ]
|
3 | // This is a sample file
4 | blah: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

╭─[/test.cue:5:7]
╭─[ /test.cue:5:7 ]
3 │ // This is a sample file
4 │ blah: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

,-[/test.cue:4:7]
,-[ /test.cue:4:7 ]
|
2 |
3 | // This is a sample file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

╭─[/test.cue:4:7]
╭─[ /test.cue:4:7 ]
2 │
3 │ // This is a sample file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

,-[/test.cue:5:7]
,-[ /test.cue:5:7 ]
|
3 | // This is a sample file
4 | blah: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

╭─[/test.cue:5:7]
╭─[ /test.cue:5:7 ]
3 │ // This is a sample file
4 │ blah: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

,-[/test.cue:1:9]
,-[ /test.cue:1:9 ]
|
1 | package test_cue
: ---v----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

╭─[/test.cue:1:9]
╭─[ /test.cue:1:9 ]
1 │ package test_cue
⋮ ───┬────
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

,-[/test.cue:5:2]
,-[ /test.cue:5:2 ]
|
3 | // This is a sample file
4 | blah: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

╭─[/test.cue:5:2]
╭─[ /test.cue:5:2 ]
3 │ // This is a sample file
4 │ blah: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

,-[/test.cue:13:4]
,-[ /test.cue:13:4 ]
|
11 |
12 | // If foo then bar is 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

╭─[/test.cue:13:4]
╭─[ /test.cue:13:4 ]
11 │
12 │ // If foo then bar is 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

,-[/test.cue:10:7]
,-[ /test.cue:10:7 ]
|
8 |
9 | // Let's set foo to true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

╭─[/test.cue:10:7]
╭─[ /test.cue:10:7 ]
8 │
9 │ // Let's set foo to true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

,-[/test.cue:13:13]
,-[ /test.cue:13:13 ]
|
11 |
12 | // If foo then bar is 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There has been a simple error in your code

╭─[/test.cue:13:13]
╭─[ /test.cue:13:13 ]
11 │
12 │ // If foo then bar is 12
Expand Down

0 comments on commit ead1550

Please sign in to comment.