diff --git a/internal/lsp/cmd/definition.go b/internal/lsp/cmd/definition.go index 29202e88..829a44e9 100644 --- a/internal/lsp/cmd/definition.go +++ b/internal/lsp/cmd/definition.go @@ -67,6 +67,9 @@ func (d *definition) Run(ctx context.Context, args ...string) error { } tok := f.GetToken() pos := tok.Pos(from.Start.Offset) + if !pos.IsValid() { + return fmt.Errorf("invalid position %v", from.Start.Offset) + } ident, err := source.Identifier(ctx, view, f, pos) if err != nil { return err diff --git a/internal/lsp/cmd/location.go b/internal/lsp/cmd/location.go index 29372b76..101046e0 100644 --- a/internal/lsp/cmd/location.go +++ b/internal/lsp/cmd/location.go @@ -7,6 +7,7 @@ package cmd import ( "fmt" "go/token" + "path/filepath" "regexp" "strconv" @@ -98,6 +99,9 @@ func parseLocation(value string) (Location, error) { return loc, fmt.Errorf("bad location syntax %q", value) } loc.Filename = m[posReFile] + if !filepath.IsAbs(loc.Filename) { + loc.Filename, _ = filepath.Abs(loc.Filename) // ignore error + } if m[posReSLine] != "" { v, err := strconv.ParseInt(m[posReSLine], 10, 32) if err != nil {