-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.go
52 lines (46 loc) · 1.79 KB
/
sync.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package handlers
import (
"fmt"
"github.com/DDP-Projekt/DDPLS/documents"
"github.com/tliron/glsp"
protocol "github.com/tliron/glsp/protocol_3_16"
)
func CreateTextDocumentDidOpen(dm *documents.DocumentManager, sendDiagnostics DiagnosticSender) protocol.TextDocumentDidOpenFunc {
return func(context *glsp.Context, params *protocol.DidOpenTextDocumentParams) error {
err := dm.AddAndParse(params.TextDocument.URI, params.TextDocument.Text)
if err != nil {
return fmt.Errorf("error while parsing module %s: %s", params.TextDocument.URI, err)
}
sendDiagnostics(dm, context.Notify, params.TextDocument.URI, false)
return nil
}
}
func CreateTextDocumentDidChange(dm *documents.DocumentManager, sendDiagnostics DiagnosticSender) protocol.TextDocumentDidChangeFunc {
return func(context *glsp.Context, params *protocol.DidChangeTextDocumentParams) error {
doc, ok := dm.Get(params.TextDocument.URI)
if !ok {
return fmt.Errorf("%s not in document map", params.TextDocument.URI)
}
for _, change := range params.ContentChanges {
switch change := change.(type) {
case protocol.TextDocumentContentChangeEvent:
startIndex, endIndex := change.Range.IndexesIn(doc.Content)
doc.Content = doc.Content[:startIndex] + change.Text + doc.Content[endIndex:]
case protocol.TextDocumentContentChangeEventWhole:
doc.Content = change.Text
}
doc.NeedReparse.Store(true)
}
sendDiagnostics(dm, context.Notify, string(doc.Uri), true)
return nil
}
}
func TextDocumentDidSave(*glsp.Context, *protocol.DidSaveTextDocumentParams) error {
return nil
}
func CreateTextDocumentDidClose(dm *documents.DocumentManager) protocol.TextDocumentDidCloseFunc {
return func(context *glsp.Context, params *protocol.DidCloseTextDocumentParams) error {
dm.Delete(params.TextDocument.URI)
return nil
}
}