2019-06-11 13:09:43 -06:00
|
|
|
// 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.
|
|
|
|
|
2019-06-07 08:04:22 -06:00
|
|
|
package lsp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) references(ctx context.Context, params *protocol.ReferenceParams) ([]protocol.Location, error) {
|
2020-02-13 11:46:49 -07:00
|
|
|
snapshot, fh, ok, err := s.beginFileRequest(params.TextDocument.URI, source.Go)
|
|
|
|
if !ok {
|
2019-08-16 11:49:17 -06:00
|
|
|
return nil, err
|
|
|
|
}
|
2020-02-13 11:46:49 -07:00
|
|
|
references, err := source.References(ctx, snapshot, fh, params.Position, params.Context.IncludeDeclaration)
|
2019-06-07 08:04:22 -06:00
|
|
|
if err != nil {
|
2019-12-17 22:06:31 -07:00
|
|
|
return nil, err
|
2019-06-07 08:04:22 -06:00
|
|
|
}
|
2019-07-02 15:41:09 -06:00
|
|
|
|
2019-12-17 22:06:31 -07:00
|
|
|
var locations []protocol.Location
|
|
|
|
for _, ref := range references {
|
|
|
|
refRange, err := ref.Range()
|
2019-06-07 08:04:22 -06:00
|
|
|
if err != nil {
|
2020-01-08 11:17:22 -07:00
|
|
|
return nil, err
|
2019-12-09 09:36:55 -07:00
|
|
|
}
|
|
|
|
|
2019-12-17 22:06:31 -07:00
|
|
|
locations = append(locations, protocol.Location{
|
2020-02-12 14:36:46 -07:00
|
|
|
URI: protocol.URIFromSpanURI(ref.URI()),
|
2019-12-17 22:06:31 -07:00
|
|
|
Range: refRange,
|
|
|
|
})
|
2019-06-07 08:04:22 -06:00
|
|
|
}
|
2019-12-09 09:36:55 -07:00
|
|
|
|
2019-06-07 08:04:22 -06:00
|
|
|
return locations, nil
|
|
|
|
}
|