z_mirror/luapls

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

Caleb HeuerRemove scrapped file graph nonsense582fe74

main
1.1 KiB39 linesraw
1package lsp
2
3import (
4	"errors"
5
6	"github.com/raiguard/luapls/lua/ast"
7	"github.com/tliron/glsp"
8	protocol "github.com/tliron/glsp/protocol_3_16"
9)
10
11func (s *Server) textDocumentHighlight(ctx *glsp.Context, params *protocol.DocumentHighlightParams) ([]protocol.DocumentHighlight, error) {
12	file := s.getFile(params.TextDocument.URI)
13	if file == nil {
14		return nil, errors.New("File not found")
15	}
16	if file.Block == nil {
17		return nil, errors.New("Attempted to highlight file that has no AST")
18	}
19	nodePath := ast.GetSemanticNode(file.Block, file.LineBreaks.ToPos(params.Position))
20	if nodePath.Node == nil {
21		return nil, nil
22	}
23	highlights := []protocol.DocumentHighlight{}
24	// TODO: Labels
25	_, ok := nodePath.Node.(ast.LeafNode)
26	if !ok {
27		return nil, nil
28	}
29	// TODO: References
30	highlights = append(highlights, protocol.DocumentHighlight{Range: file.LineBreaks.ToProtocolRange(ast.Range(nodePath.Node))})
31
32	// TODO:
33	// def := file.Env.FindDefinition(nodePath)
34	// if def != nil {
35	// 	highlights = append(highlights, protocol.DocumentHighlight{Range: file.LineBreaks.ToProtocolRange(ast.Range(def))})
36	// }
37
38	return highlights, nil
39}