Debian Codegraph @

gopls/internal/server/highlight.go

raw symbols SCIP
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 server
6
7 import (
8 "context"
9
10 "golang.org/x/tools/gopls/internal/file"
11 "golang.org/x/tools/gopls/internal/golang"
12 "golang.org/x/tools/gopls/internal/label"
13 "golang.org/x/tools/gopls/internal/protocol"
14 "golang.org/x/tools/gopls/internal/template"
15 "golang.org/x/tools/internal/event"
16 )
17
18 func (s *server) DocumentHighlight(ctx context.Context, params *protocol.DocumentHighlightParams) ([]protocol.DocumentHighlight, error) {
19 ctx, done := event.Start(ctx, "server.DocumentHighlight", label.URI.Of(params.TextDocument.URI))
20 defer done()
21
22 fh, snapshot, release, err := s.session.FileOf(ctx, params.TextDocument.URI)
23 if err != nil {
24 return nil, err
25 }
26 defer release()
27
28 switch snapshot.FileKind(fh) {
29 case file.Tmpl:
30 return template.Highlight(ctx, snapshot, fh, params.Range)
31 case file.Go:
32 rngs, err := golang.Highlight(ctx, snapshot, fh, params.Range)
33 if err != nil {
34 event.Error(ctx, "no highlight", err)
35 }
36 return rngs, nil
37 }
38 return nil, nil // empty result
39 }