From 4f6791d0af4a2f7cace774969ab8da6e9afff25a Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Mon, 22 Jan 2024 13:01:19 -0500 Subject: [PATCH] Store and report file name with issues (#407) --- amod/amod.go | 1 + util/issues/issues.go | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/amod/amod.go b/amod/amod.go index fb1ac943..d8867633 100644 --- a/amod/amod.go +++ b/amod/amod.go @@ -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, diff --git a/util/issues/issues.go b/util/issues/issues.go index ddcfaa09..c6413475 100644 --- a/util/issues/issues.go +++ b/util/issues/issues.go @@ -4,6 +4,7 @@ package issues import ( "fmt" "io" + "path/filepath" "strings" ) @@ -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 { @@ -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"