Skip to content

Commit

Permalink
Store and report file name with issues (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaloney authored Jan 22, 2024
1 parent 497f506 commit 4f6791d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions amod/amod.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func modelReader(r io.Reader) (model *actr.Model, iLog *issues.Log, err error) {
pErr, ok := err.(participle.Error)
if ok {
location := issues.Location{
SourceFile: pErr.Position().Filename,
Line: pErr.Position().Line,
ColumnStart: pErr.Position().Column,
ColumnEnd: pErr.Position().Column,
Expand Down
15 changes: 11 additions & 4 deletions util/issues/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package issues
import (
"fmt"
"io"
"path/filepath"
"strings"
)

Expand All @@ -16,9 +17,10 @@ const (
)

type Location struct {
Line int `json:"line"`
ColumnStart int `json:"columnStart"`
ColumnEnd int `json:"columnEnd"`
SourceFile string `json:"sourceFile"`
Line int `json:"line"`
ColumnStart int `json:"columnStart"`
ColumnEnd int `json:"columnEnd"`
}

type Issue struct {
Expand Down Expand Up @@ -114,7 +116,12 @@ func (l Log) Write(w io.Writer) error {
str += entry.Text

if entry.Location != nil {
str += fmt.Sprintf(" (line %d, col %d)", entry.Line, entry.ColumnStart)
if entry.SourceFile == "" {
str += fmt.Sprintf(" (line %d, col %d)", entry.Line, entry.ColumnStart)
} else {
file := filepath.Base(entry.SourceFile)
str += fmt.Sprintf(" (%s, line %d, col %d)", file, entry.Line, entry.ColumnStart)
}
}

str += "\n"
Expand Down

0 comments on commit 4f6791d

Please sign in to comment.