z_mirror/luapls
git clone https://git.raiguard.me/z_mirror/luapls
582fe74
main
1package lsp 2 3import ( 4"errors" 5"fmt" 6 7"github.com/raiguard/luapls/lua/ast" 8"github.com/raiguard/luapls/util" 9"github.com/tliron/glsp" 10 protocol"github.com/tliron/glsp/protocol_3_16" 11) 12 13func (s * Server )textDocumentHover (ctx * glsp.Context ,params * protocol.HoverParams ) (* protocol.Hover ,error ) { 14file := s .getFile (params .TextDocument .URI ) 15if file == nil { 16return nil ,nil 17 } 18if file .Block == nil { 19return nil ,errors .New ("Attempted to highlight file with no AST" ) 20 } 21nodePath := ast .GetSemanticNode (file .Block ,file .LineBreaks .ToPos (params .Position )) 22if nodePath .Node == nil { 23return nil ,nil 24 } 25ident ,ok := nodePath .Node .(* ast.Identifier ) 26if ! ok { 27return nil ,nil 28 } 29// typ, ok := file.Env.Types[ident] 30// if !ok { 31// typ = &types.Unknown{} 32// } 33contents := fmt .Sprintf ("```lua\n(variable) %s\n```" ,ident .Token .Literal ) 34// comments := ident.GetComments() 35// i := len(nodePath.Parents) - 1 36// for comments == "" && i >= 0 { 37// comments = nodePath.Parents[i].GetComments() 38// if _, ok := nodePath.Parents[i].(ast.Statement); ok { 39// break 40// } 41// i-- 42// } 43// if comments != "" { 44// contents += "\n\n" + comments 45// } 46return & protocol.Hover { 47Contents :contents , 48Range :util .Ptr (file .LineBreaks .ToProtocolRange (ast .Range (ident ))), 49 },nil 50}