Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / internal / lsp / highlight.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201105173854-bc9fc8d8c4bc/internal/lsp/highlight.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201105173854-bc9fc8d8c4bc/internal/lsp/highlight.go
new file mode 100644 (file)
index 0000000..9fc897b
--- /dev/null
@@ -0,0 +1,39 @@
+// 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/event"
+       "golang.org/x/tools/internal/lsp/debug/tag"
+       "golang.org/x/tools/internal/lsp/protocol"
+       "golang.org/x/tools/internal/lsp/source"
+)
+
+func (s *Server) documentHighlight(ctx context.Context, params *protocol.DocumentHighlightParams) ([]protocol.DocumentHighlight, error) {
+       snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.Go)
+       defer release()
+       if !ok {
+               return nil, err
+       }
+       rngs, err := source.Highlight(ctx, snapshot, fh, params.Position)
+       if err != nil {
+               event.Error(ctx, "no highlight", err, tag.URI.Of(params.TextDocument.URI))
+       }
+       return toProtocolHighlight(rngs), nil
+}
+
+func toProtocolHighlight(rngs []protocol.Range) []protocol.DocumentHighlight {
+       result := make([]protocol.DocumentHighlight, 0, len(rngs))
+       kind := protocol.Text
+       for _, rng := range rngs {
+               result = append(result, protocol.DocumentHighlight{
+                       Kind:  kind,
+                       Range: rng,
+               })
+       }
+       return result
+}