-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtext_document.go
119 lines (95 loc) · 3.36 KB
/
text_document.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package handler
import (
"context"
"errors"
"fmt"
"path/filepath"
"github.com/mrjosh/helm-ls/internal/charts"
helmlint "github.com/mrjosh/helm-ls/internal/helm_lint"
lsplocal "github.com/mrjosh/helm-ls/internal/lsp"
lsp "go.lsp.dev/protocol"
)
func (h *langHandler) DidOpen(ctx context.Context, params *lsp.DidOpenTextDocumentParams) (err error) {
doc, err := h.documents.DidOpen(params, h.helmlsConfig)
if err != nil {
logger.Error(err)
return err
}
h.yamllsConnector.DocumentDidOpen(doc.Ast, *params)
doc, ok := h.documents.Get(params.TextDocument.URI)
if !ok {
return errors.New("Could not get document: " + params.TextDocument.URI.Filename())
}
chart, err := h.chartStore.GetChartOrParentForDoc(doc.URI)
if err != nil {
logger.Error("Error getting chart info for file", doc.URI, err)
}
notifications := helmlint.GetDiagnosticsNotifications(chart, doc)
defer h.publishDiagnostics(ctx, notifications)
return nil
}
func (h *langHandler) DidClose(_ context.Context, _ *lsp.DidCloseTextDocumentParams) (err error) {
return nil
}
func (h *langHandler) DidSave(ctx context.Context, params *lsp.DidSaveTextDocumentParams) (err error) {
doc, ok := h.documents.Get(params.TextDocument.URI)
if !ok {
return errors.New("Could not get document: " + params.TextDocument.URI.Filename())
}
chart, err := h.chartStore.GetChartOrParentForDoc(doc.URI)
if err != nil {
logger.Error("Error getting chart info for file", doc.URI, err)
}
h.yamllsConnector.DocumentDidSave(doc, *params)
notifications := helmlint.GetDiagnosticsNotifications(chart, doc)
defer h.publishDiagnostics(ctx, notifications)
return nil
}
func (h *langHandler) DidChange(_ context.Context, params *lsp.DidChangeTextDocumentParams) (err error) {
doc, ok := h.documents.Get(params.TextDocument.URI)
if !ok {
return errors.New("Could not get document: " + params.TextDocument.URI.Filename())
}
shouldSendFullUpdateToYamlls := false
// Synchronise changes into the doc's ContentChanges
doc.ApplyChanges(params.ContentChanges)
for _, change := range params.ContentChanges {
node := lsplocal.NodeAtPosition(doc.Ast, change.Range.Start)
if node.Type() != "text" {
shouldSendFullUpdateToYamlls = true
break
}
}
if shouldSendFullUpdateToYamlls {
h.yamllsConnector.DocumentDidChangeFullSync(doc, *params)
} else {
h.yamllsConnector.DocumentDidChange(doc, *params)
}
return nil
}
func (h *langHandler) DidCreateFiles(ctx context.Context, params *lsp.CreateFilesParams) (err error) {
logger.Error("DidCreateFiles unimplemented")
return nil
}
// DidDeleteFiles implements protocol.Server.
func (h *langHandler) DidDeleteFiles(ctx context.Context, params *lsp.DeleteFilesParams) (err error) {
logger.Error("DidDeleteFiles unimplemented")
return nil
}
// DidRenameFiles implements protocol.Server.
func (h *langHandler) DidRenameFiles(ctx context.Context, params *lsp.RenameFilesParams) (err error) {
logger.Error("DidRenameFiles unimplemented")
return nil
}
func (h *langHandler) LoadDocsOnNewChart(chart *charts.Chart) {
if chart.HelmChart == nil {
return
}
for _, file := range chart.HelmChart.Templates {
h.documents.Store(filepath.Join(chart.RootURI.Filename(), file.Name), file.Data, h.helmlsConfig)
}
for _, file := range chart.GetDependeciesTemplates() {
logger.Debug(fmt.Sprintf("Storing dependency %s", file.Path))
h.documents.Store(file.Path, file.Content, h.helmlsConfig)
}
}