golang.org/x/tools/gopls@v0.15.3/internal/server/hover.go (about) 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/mod" 13 "golang.org/x/tools/gopls/internal/protocol" 14 "golang.org/x/tools/gopls/internal/telemetry" 15 "golang.org/x/tools/gopls/internal/template" 16 "golang.org/x/tools/gopls/internal/work" 17 "golang.org/x/tools/internal/event" 18 "golang.org/x/tools/internal/event/tag" 19 ) 20 21 func (s *server) Hover(ctx context.Context, params *protocol.HoverParams) (_ *protocol.Hover, rerr error) { 22 recordLatency := telemetry.StartLatencyTimer("hover") 23 defer func() { 24 recordLatency(ctx, rerr) 25 }() 26 27 ctx, done := event.Start(ctx, "lsp.Server.hover", tag.URI.Of(params.TextDocument.URI)) 28 defer done() 29 30 fh, snapshot, release, err := s.fileOf(ctx, params.TextDocument.URI) 31 if err != nil { 32 return nil, err 33 } 34 defer release() 35 36 switch snapshot.FileKind(fh) { 37 case file.Mod: 38 return mod.Hover(ctx, snapshot, fh, params.Position) 39 case file.Go: 40 return golang.Hover(ctx, snapshot, fh, params.Position) 41 case file.Tmpl: 42 return template.Hover(ctx, snapshot, fh, params.Position) 43 case file.Work: 44 return work.Hover(ctx, snapshot, fh, params.Position) 45 } 46 return nil, nil // empty result 47 }