| 1 |
|
| 2 |
|
| 3 |
|
| 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) SemanticTokensFull(ctx context.Context, params *protocol.SemanticTokensParams) (*protocol.SemanticTokens, error) { |
| 19 |
return s.semanticTokens(ctx, params.TextDocument, nil) |
| 20 |
} |
| 21 |
|
| 22 |
func (s *server) SemanticTokensRange(ctx context.Context, params *protocol.SemanticTokensRangeParams) (*protocol.SemanticTokens, error) { |
| 23 |
return s.semanticTokens(ctx, params.TextDocument, ¶ms.Range) |
| 24 |
} |
| 25 |
|
| 26 |
func (s *server) semanticTokens(ctx context.Context, td protocol.TextDocumentIdentifier, rng *protocol.Range) (*protocol.SemanticTokens, error) { |
| 27 |
ctx, done := event.Start(ctx, "server.semanticTokens", label.URI.Of(td.URI)) |
| 28 |
defer done() |
| 29 |
|
| 30 |
fh, snapshot, release, err := s.session.FileOf(ctx, td.URI) |
| 31 |
if err != nil { |
| 32 |
return nil, err |
| 33 |
} |
| 34 |
defer release() |
| 35 |
|
| 36 |
if snapshot.Options().SemanticTokens { |
| 37 |
switch snapshot.FileKind(fh) { |
| 38 |
case file.Tmpl: |
| 39 |
return template.SemanticTokens(ctx, snapshot, fh.URI()) |
| 40 |
case file.Go: |
| 41 |
return golang.SemanticTokens(ctx, snapshot, fh, rng) |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
return &protocol.SemanticTokens{Data: []uint32{}}, nil |
| 56 |
} |