z_mirror/luapls

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

Caleb HeuerSupport editing of newly created files2a9160e

main
1.4 KiB48 linesraw
1package lsp
2
3import (
4	"errors"
5	"time"
6
7	"github.com/raiguard/luapls/lua/parser"
8	"github.com/tliron/glsp"
9	protocol "github.com/tliron/glsp/protocol_3_16"
10)
11
12// TODO: Incremental changes
13func (s *Server) textDocumentDidOpen(ctx *glsp.Context, params *protocol.DidOpenTextDocumentParams) error {
14	file := s.getFile(params.TextDocument.URI)
15	if file == nil {
16		file = s.environment.AddTransientFile(params.TextDocument.URI, params.TextDocument.Text)
17	}
18	if file == nil {
19		return errors.New("Error creating file")
20	}
21	s.publishDiagnostics(ctx, file)
22	return nil
23}
24
25func (s *Server) textDocumentDidChange(ctx *glsp.Context, params *protocol.DidChangeTextDocumentParams) error {
26	file := s.getFile(params.TextDocument.URI)
27	if file == nil {
28		return nil
29	}
30	for _, change := range params.ContentChanges {
31		if change, ok := change.(protocol.TextDocumentContentChangeEventWhole); ok {
32			before := time.Now()
33			newFile := parser.New(change.Text).ParseFile()
34			s.log.Debugf("Reparse duration: %s", time.Since(before).String())
35			file.Block = newFile.Block
36			file.LineBreaks = newFile.LineBreaks
37			file.Diagnostics = newFile.Diagnostics
38			s.environment.CheckFilePhase1(file)
39			s.publishDiagnostics(ctx, file)
40		}
41	}
42	return nil
43}
44
45func (s *Server) textDocumentDidClose(ctx *glsp.Context, params *protocol.DidCloseTextDocumentParams) error {
46	// TODO: Remove file ASTs from memory
47	return nil
48}