2019-03-25 18:56:05 -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.
|
|
|
|
|
|
|
|
package lsp
|
|
|
|
|
|
|
|
import (
|
2019-04-17 13:37:20 -06:00
|
|
|
"context"
|
|
|
|
|
2019-03-25 18:56:05 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
2019-04-17 13:37:20 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/source"
|
2019-09-05 16:54:05 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/telemetry"
|
2019-03-25 18:56:05 -06:00
|
|
|
"golang.org/x/tools/internal/span"
|
2019-08-13 13:07:39 -06:00
|
|
|
"golang.org/x/tools/internal/telemetry/log"
|
2019-03-25 18:56:05 -06:00
|
|
|
)
|
|
|
|
|
2019-09-07 15:01:26 -06:00
|
|
|
func (s *Server) documentHighlight(ctx context.Context, params *protocol.DocumentHighlightParams) ([]protocol.DocumentHighlight, error) {
|
2019-04-17 13:37:20 -06:00
|
|
|
uri := span.NewURI(params.TextDocument.URI)
|
2019-05-15 10:24:49 -06:00
|
|
|
view := s.session.ViewOf(uri)
|
2019-09-05 16:54:05 -06:00
|
|
|
rngs, err := source.Highlight(ctx, view, uri, params.Position)
|
2019-08-16 11:49:17 -06:00
|
|
|
if err != nil {
|
2019-09-05 16:54:05 -06:00
|
|
|
log.Error(ctx, "no highlight", err, telemetry.URI.Of(uri))
|
2019-08-16 11:49:17 -06:00
|
|
|
}
|
2019-09-05 16:54:05 -06:00
|
|
|
return toProtocolHighlight(rngs), nil
|
2019-04-17 13:37:20 -06:00
|
|
|
}
|
|
|
|
|
2019-09-05 16:54:05 -06:00
|
|
|
func toProtocolHighlight(rngs []protocol.Range) []protocol.DocumentHighlight {
|
|
|
|
result := make([]protocol.DocumentHighlight, 0, len(rngs))
|
2019-03-25 18:56:05 -06:00
|
|
|
kind := protocol.Text
|
2019-09-05 16:54:05 -06:00
|
|
|
for _, rng := range rngs {
|
|
|
|
result = append(result, protocol.DocumentHighlight{
|
|
|
|
Kind: &kind,
|
|
|
|
Range: rng,
|
|
|
|
})
|
2019-03-25 18:56:05 -06:00
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|