From 83df196e5764ed2415c28c1f39ba6cb3db747da0 Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Thu, 2 May 2019 13:04:19 -0400 Subject: [PATCH] internal/span: add a filename only print for spans This prints the base of the path rather than the whole path when printing a span. This is useful for places where you are printing for the user rather than for machines. The format is %f Change-Id: I6d1a52e4583099ff298c1fb645272578a49472eb Reviewed-on: https://go-review.googlesource.com/c/tools/+/174942 Run-TryBot: Ian Cottrell TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/span/span.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/span/span.go b/internal/span/span.go index b5733252..7719257d 100644 --- a/internal/span/span.go +++ b/internal/span/span.go @@ -7,6 +7,7 @@ package span import ( "encoding/json" "fmt" + "path" ) // Span represents a source code range in standardized form. @@ -167,7 +168,9 @@ func (s Span) Format(f fmt.State, c rune) { // we should always have a uri, simplify if it is file format //TODO: make sure the end of the uri is unambiguous uri := string(s.v.URI) - if !fullForm { + if c == 'f' { + uri = path.Base(uri) + } else if !fullForm { if filename, err := s.v.URI.Filename(); err == nil { uri = filename }