mirror of https://github.com/golang/go.git
internal/lsp: check for invalid URIs in definition
URI.Filename() panics on non-file URIs. Just pass UnknownKind to beginFileRequest to allow handling template files. Fixes golang/go#49223 Change-Id: Ic2add49d3d0c04855bf25583712102a50fb425ed Reviewed-on: https://go-review.googlesource.com/c/tools/+/359734 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
170abddb9d
commit
96715ada81
|
|
@ -9,6 +9,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
. "golang.org/x/tools/internal/lsp/regtest"
|
||||
"golang.org/x/tools/internal/testenv"
|
||||
|
||||
|
|
@ -277,3 +278,14 @@ package client
|
|||
env.GoToDefinition("client/client_role_test.go", env.RegexpSearch("client/client_role_test.go", "RoleSetup"))
|
||||
})
|
||||
}
|
||||
|
||||
// This test exercises a crashing pattern from golang/go#49223.
|
||||
func TestGoToCrashingDefinition_Issue49223(t *testing.T) {
|
||||
Run(t, "", func(t *testing.T, env *Env) {
|
||||
params := &protocol.DefinitionParams{}
|
||||
params.TextDocument.URI = protocol.DocumentURI("fugitive%3A///Users/user/src/mm/ems/.git//0/pkg/domain/treasury/provider.go")
|
||||
params.Position.Character = 18
|
||||
params.Position.Line = 0
|
||||
env.Editor.Server.Definition(env.Ctx, params)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ import (
|
|||
)
|
||||
|
||||
func (s *Server) definition(ctx context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error) {
|
||||
kind := source.DetectLanguage("", params.TextDocument.URI.SpanURI().Filename())
|
||||
snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, kind)
|
||||
snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.UnknownKind)
|
||||
defer release()
|
||||
if !ok {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Reference in New Issue