Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201028153306-37f0764111ff / internal / lsp / highlight.go
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.
4
5 package lsp
6
7 import (
8         "context"
9
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"
14 )
15
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)
18         defer release()
19         if !ok {
20                 return nil, err
21         }
22         rngs, err := source.Highlight(ctx, snapshot, fh, params.Position)
23         if err != nil {
24                 event.Error(ctx, "no highlight", err, tag.URI.Of(params.TextDocument.URI))
25         }
26         return toProtocolHighlight(rngs), nil
27 }
28
29 func toProtocolHighlight(rngs []protocol.Range) []protocol.DocumentHighlight {
30         result := make([]protocol.DocumentHighlight, 0, len(rngs))
31         kind := protocol.Text
32         for _, rng := range rngs {
33                 result = append(result, protocol.DocumentHighlight{
34                         Kind:  kind,
35                         Range: rng,
36                 })
37         }
38         return result
39 }