diff --git a/internal/lsp/source/util.go b/internal/lsp/source/util.go index 7feba2f36b3..194159874da 100644 --- a/internal/lsp/source/util.go +++ b/internal/lsp/source/util.go @@ -86,7 +86,7 @@ func fileToMapper(ctx context.Context, view View, uri span.URI) (*ast.File, []Pa if err != nil { return nil, nil, nil, err } - file, m, err := pkgToMapper(ctx, view, pkg, uri) + file, m, err := pkgToMapper(ctx, view, pkg, f.URI()) if err != nil { return nil, nil, nil, err } @@ -109,7 +109,7 @@ func cachedFileToMapper(ctx context.Context, view View, uri span.URI) (*ast.File if err != nil { return nil, nil, err } - file, m, err := pkgToMapper(ctx, view, pkg, uri) + file, m, err := pkgToMapper(ctx, view, pkg, f.URI()) if err != nil { return nil, nil, err } diff --git a/internal/span/uri.go b/internal/span/uri.go index 9dfbdaad9f4..e05a9e6ef5d 100644 --- a/internal/span/uri.go +++ b/internal/span/uri.go @@ -124,7 +124,11 @@ func FileURI(path string) URI { Scheme: fileScheme, Path: path, } - return URI(u.String()) + uri := u.String() + if unescaped, err := url.PathUnescape(uri); err == nil { + uri = unescaped + } + return URI(uri) } // isWindowsDrivePath returns true if the file path is of the form used by diff --git a/internal/span/uri_test.go b/internal/span/uri_test.go index 36dd1997e25..907b47bf48c 100644 --- a/internal/span/uri_test.go +++ b/internal/span/uri_test.go @@ -23,6 +23,7 @@ func TestURI(t *testing.T) { `c:/Go/src/bob.go`, `/path/to/dir`, `/a/b/c/src/bob.go`, + `c:/Go/src/bob george/george/george.go`, } { testPath := filepath.FromSlash(test) expectPath := testPath