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 <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Ian Cottrell 2019-05-02 13:04:19 -04:00
parent 2346320968
commit 83df196e57
1 changed files with 4 additions and 1 deletions

View File

@ -7,6 +7,7 @@ package span
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"path"
) )
// Span represents a source code range in standardized form. // 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 // we should always have a uri, simplify if it is file format
//TODO: make sure the end of the uri is unambiguous //TODO: make sure the end of the uri is unambiguous
uri := string(s.v.URI) 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 { if filename, err := s.v.URI.Filename(); err == nil {
uri = filename uri = filename
} }