Skip to content

Commit 37fcf2e

Browse files
authored
feat: implement didChangeConfiguration and registration (#143)
1 parent 5328d64 commit 37fcf2e

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

internal/handler/configuration.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,31 @@ import (
44
"context"
55
"encoding/json"
66

7-
// "reflect"
8-
97
"github.com/mrjosh/helm-ls/internal/util"
108
lsp "go.lsp.dev/protocol"
119
)
1210

1311
func (h *ServerHandler) DidChangeConfiguration(ctx context.Context, params *lsp.DidChangeConfigurationParams) (err error) {
14-
// go h.retrieveWorkspaceConfiguration(ctx)
15-
logger.Println("Changing workspace config is not implemented")
12+
logger.Printf("Running DidChangeConfiguration with settings %+v \n", params.Settings)
13+
14+
// since the push based approach is deprecated, we always refresh the configuration
15+
h.retrieveWorkspaceConfiguration(ctx)
16+
1617
return nil
1718
}
1819

20+
func (h *ServerHandler) registerDidChangeConfiguration(ctx context.Context) {
21+
// For DidChangeConfiguration to be called on changes in the configuration we need to register
22+
h.client.RegisterCapability(ctx, &lsp.RegistrationParams{
23+
Registrations: []lsp.Registration{
24+
{
25+
ID: "helm-ls",
26+
Method: "workspace/didChangeConfiguration",
27+
},
28+
},
29+
})
30+
}
31+
1932
func (h *ServerHandler) retrieveWorkspaceConfiguration(ctx context.Context) {
2033
logger.Debug("Calling workspace/configuration")
2134
configurationParams := lsp.ConfigurationParams{
@@ -35,7 +48,7 @@ func (h *ServerHandler) retrieveWorkspaceConfiguration(ctx context.Context) {
3548
h.initializationWithConfig(ctx)
3649
}
3750

38-
func parseWorkspaceConfiguration(rawResult []interface{}, currentConfig util.HelmlsConfiguration) (result util.HelmlsConfiguration) {
51+
func parseWorkspaceConfiguration(rawResult []any, currentConfig util.HelmlsConfiguration) (result util.HelmlsConfiguration) {
3952
logger.Debug("Raw Workspace configuration:", rawResult)
4053

4154
if len(rawResult) == 0 {

internal/handler/initialization.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (h *ServerHandler) Initialize(ctx context.Context, params *lsp.InitializePa
5050
}
5151

5252
func (h *ServerHandler) Initialized(ctx context.Context, _ *lsp.InitializedParams) (err error) {
53+
h.registerDidChangeConfiguration(ctx)
5354
h.retrieveWorkspaceConfiguration(ctx)
5455
return nil
5556
}

internal/handler/text_document.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
func (h *ServerHandler) DidOpen(ctx context.Context, params *lsp.DidOpenTextDocumentParams) (err error) {
1414
handler := h.langHandlers[document.DocumentTypeForFile(params.TextDocument.LanguageID, params.TextDocument.URI)]
1515

16+
logger.Println("DidOpen: ", params.TextDocument.URI.Filename())
17+
1618
if handler == nil {
1719
message := fmt.Sprintf("Language or file not supported: %s, %v", params.TextDocument.LanguageID, params.TextDocument.URI)
1820
logger.Error(message)

0 commit comments

Comments
 (0)