z_mirror/luapls
git clone https://git.raiguard.me/z_mirror/luapls
2a9160e
main
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 { 14file := s .getFile (params .TextDocument .URI ) 15if file == nil { 16file = s .environment .AddTransientFile (params .TextDocument .URI ,params .TextDocument .Text ) 17 } 18if file == nil { 19return errors .New ("Error creating file" ) 20 } 21s .publishDiagnostics (ctx ,file ) 22return nil 23} 24 25func (s * Server )textDocumentDidChange (ctx * glsp.Context ,params * protocol.DidChangeTextDocumentParams )error { 26file := s .getFile (params .TextDocument .URI ) 27if file == nil { 28return nil 29 } 30for _ ,change := range params .ContentChanges { 31if change ,ok := change .(protocol.TextDocumentContentChangeEventWhole );ok { 32before := time .Now () 33newFile := parser .New (change .Text ).ParseFile () 34s .log .Debugf ("Reparse duration: %s" ,time .Since (before ).String ()) 35file .Block = newFile .Block 36file .LineBreaks = newFile .LineBreaks 37file .Diagnostics = newFile .Diagnostics 38s .environment .CheckFilePhase1 (file ) 39s .publishDiagnostics (ctx ,file ) 40 } 41 } 42return nil 43} 44 45func (s * Server )textDocumentDidClose (ctx * glsp.Context ,params * protocol.DidCloseTextDocumentParams )error { 46// TODO: Remove file ASTs from memory 47return nil 48}