z_mirror/luapls

git clone https://git.raiguard.me/z_mirror/luapls

Caleb HeuerRemove scrapped file graph nonsense582fe74

main
1.3 KiB50 linesraw
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) {
14	file := s.getFile(params.TextDocument.URI)
15	if file == nil {
16		return nil, nil
17	}
18	if file.Block == nil {
19		return nil, errors.New("Attempted to highlight file with no AST")
20	}
21	nodePath := ast.GetSemanticNode(file.Block, file.LineBreaks.ToPos(params.Position))
22	if nodePath.Node == nil {
23		return nil, nil
24	}
25	ident, ok := nodePath.Node.(*ast.Identifier)
26	if !ok {
27		return nil, nil
28	}
29	// typ, ok := file.Env.Types[ident]
30	// if !ok {
31	// 	typ = &types.Unknown{}
32	// }
33	contents := 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	// }
46	return &protocol.Hover{
47		Contents: contents,
48		Range:    util.Ptr(file.LineBreaks.ToProtocolRange(ast.Range(ident))),
49	}, nil
50}