github.com/jhump/golang-x-tools@v0.0.0-20220218190644-4958d6d39439/internal/lsp/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 lsp 6 7 import ( 8 "context" 9 10 "github.com/jhump/golang-x-tools/internal/lsp/mod" 11 "github.com/jhump/golang-x-tools/internal/lsp/protocol" 12 "github.com/jhump/golang-x-tools/internal/lsp/source" 13 "github.com/jhump/golang-x-tools/internal/lsp/template" 14 ) 15 16 func (s *Server) hover(ctx context.Context, params *protocol.HoverParams) (*protocol.Hover, error) { 17 snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.UnknownKind) 18 defer release() 19 if !ok { 20 return nil, err 21 } 22 switch snapshot.View().FileKind(fh) { 23 case source.Mod: 24 return mod.Hover(ctx, snapshot, fh, params.Position) 25 case source.Go: 26 return source.Hover(ctx, snapshot, fh, params.Position) 27 case source.Tmpl: 28 return template.Hover(ctx, snapshot, fh, params.Position) 29 } 30 return nil, nil 31 }