From 1529f889eb4b594d1f047f2fb8d5b3cc85c8f006 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 31 Oct 2016 09:53:48 -0400 Subject: [PATCH] cmd/guru: report start and end positions for non-PkgName Objects Most objects are declared by an identifier, so the end position is start+len(name). However, this heuristic doesn't work for PkgName objects because a (non-renaming) import creates an object without an identifier. Fixes issue github.com/Microsoft/vscode-go#562 Change-Id: I0eb44ca33a643c910d97abbf700ea4c3cd23bb41 Reviewed-on: https://go-review.googlesource.com/32440 Reviewed-by: Robert Griesemer --- cmd/guru/guru.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/guru/guru.go b/cmd/guru/guru.go index 25457fe0..3dedeb63 100644 --- a/cmd/guru/guru.go +++ b/cmd/guru/guru.go @@ -310,6 +310,14 @@ func fprintf(w io.Writer, fset *token.FileSet, pos interface{}, format string, a case token.Pos: start = pos end = start + case *types.PkgName: + // The Pos of most PkgName objects does not coincide with an identifier, + // so we suppress the usual start+len(name) heuristic for types.Objects. + start = pos.Pos() + end = start + case types.Object: + start = pos.Pos() + end = start + token.Pos(len(pos.Name())) // heuristic case interface { Pos() token.Pos }: