1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "golang.org/x/tools/internal/event"
11 "golang.org/x/tools/internal/lsp/debug/tag"
12 "golang.org/x/tools/internal/lsp/protocol"
13 "golang.org/x/tools/internal/lsp/source"
16 func (s *Server) documentHighlight(ctx context.Context, params *protocol.DocumentHighlightParams) ([]protocol.DocumentHighlight, error) {
17 snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.Go)
22 rngs, err := source.Highlight(ctx, snapshot, fh, params.Position)
24 event.Error(ctx, "no highlight", err, tag.URI.Of(params.TextDocument.URI))
26 return toProtocolHighlight(rngs), nil
29 func toProtocolHighlight(rngs []protocol.Range) []protocol.DocumentHighlight {
30 result := make([]protocol.DocumentHighlight, 0, len(rngs))
32 for _, rng := range rngs {
33 result = append(result, protocol.DocumentHighlight{