mirror of
https://github.com/golang/go
synced 2024-11-18 14:14:46 -07:00
a6aac22fcd
We weren't returning promoted methods as implementations when the promoted method was defined in a different package than the type implementing the interface. Fix by properly mapping the implementer types.Object to its containing source.Package. I generalized the implementations() result to just contain the implementer objects and their containing package. This allowed me to get rid of some result prep code in Implementation(). Fixes golang/go#35972. Change-Id: I867f2114c34e2ad39515ee3c8b6354c1cd35f7af Reviewed-on: https://go-review.googlesource.com/c/tools/+/210280 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package lsp
|
|
|
|
import (
|
|
"context"
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
"golang.org/x/tools/internal/lsp/telemetry"
|
|
"golang.org/x/tools/internal/span"
|
|
"golang.org/x/tools/internal/telemetry/log"
|
|
)
|
|
|
|
func (s *Server) implementation(ctx context.Context, params *protocol.ImplementationParams) ([]protocol.Location, error) {
|
|
uri := span.NewURI(params.TextDocument.URI)
|
|
view, err := s.session.ViewOf(uri)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
snapshot := view.Snapshot()
|
|
f, err := view.GetFile(ctx, uri)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if f.Kind() != source.Go {
|
|
return nil, nil
|
|
}
|
|
phs, err := snapshot.PackageHandles(ctx, snapshot.Handle(ctx, f))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var (
|
|
allLocs []protocol.Location
|
|
seen = make(map[protocol.Location]bool)
|
|
)
|
|
for _, ph := range phs {
|
|
ctx := telemetry.Package.With(ctx, ph.ID())
|
|
|
|
ident, err := source.Identifier(ctx, snapshot, f, params.Position, source.SpecificPackageHandle(ph.ID()))
|
|
if err != nil {
|
|
if err == source.ErrNoIdentFound {
|
|
return nil, err
|
|
}
|
|
log.Error(ctx, "failed to find Identifer", err)
|
|
continue
|
|
}
|
|
|
|
locs, err := ident.Implementation(ctx)
|
|
if err != nil {
|
|
if err == source.ErrNotAnInterface {
|
|
return nil, err
|
|
}
|
|
log.Error(ctx, "failed to find Implemenation", err)
|
|
continue
|
|
}
|
|
|
|
for _, loc := range locs {
|
|
if seen[loc] {
|
|
continue
|
|
}
|
|
seen[loc] = true
|
|
allLocs = append(allLocs, loc)
|
|
}
|
|
}
|
|
|
|
return allLocs, nil
|
|
}
|