Skip to content

Commit a754db1

Browse files
committed
internal/lsp: absolutize paths when converting filenames to URIs
Fixes golang/go#30280 Change-Id: I95e72c8d952ce7d64114772e9ef3df6568ae5dd4 Reviewed-on: https://go-review.googlesource.com/c/163160 Run-TryBot: Rebecca Stambler <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Cottrell <[email protected]>
1 parent 8bdde6d commit a754db1

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

internal/lsp/cmd/definition.go

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func (d *definition) Run(ctx context.Context, args ...string) error {
6767
}
6868
tok := f.GetToken()
6969
pos := tok.Pos(from.Start.Offset)
70+
if !pos.IsValid() {
71+
return fmt.Errorf("invalid position %v", from.Start.Offset)
72+
}
7073
ident, err := source.Identifier(ctx, view, f, pos)
7174
if err != nil {
7275
return err

internal/lsp/cmd/location.go

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package cmd
77
import (
88
"fmt"
99
"go/token"
10+
"path/filepath"
1011
"regexp"
1112
"strconv"
1213

@@ -98,6 +99,9 @@ func parseLocation(value string) (Location, error) {
9899
return loc, fmt.Errorf("bad location syntax %q", value)
99100
}
100101
loc.Filename = m[posReFile]
102+
if !filepath.IsAbs(loc.Filename) {
103+
loc.Filename, _ = filepath.Abs(loc.Filename) // ignore error
104+
}
101105
if m[posReSLine] != "" {
102106
v, err := strconv.ParseInt(m[posReSLine], 10, 32)
103107
if err != nil {

0 commit comments

Comments
 (0)