diff --git a/gopls/internal/regtest/misc/definition_test.go b/gopls/internal/regtest/misc/definition_test.go index 2b7d1a47d29..2f5a54820d0 100644 --- a/gopls/internal/regtest/misc/definition_test.go +++ b/gopls/internal/regtest/misc/definition_test.go @@ -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) + }) +} diff --git a/internal/lsp/definition.go b/internal/lsp/definition.go index f8932d99389..ab4aaed104f 100644 --- a/internal/lsp/definition.go +++ b/internal/lsp/definition.go @@ -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