diff --git a/internal/adapter/yamlls/documentSync.go b/internal/adapter/yamlls/documentSync.go index 59039138..dabbc25f 100644 --- a/internal/adapter/yamlls/documentSync.go +++ b/internal/adapter/yamlls/documentSync.go @@ -9,11 +9,11 @@ import ( lsp "go.lsp.dev/protocol" ) -func (yamllsConnector YamllsConnector) InitiallySyncOpenDocuments() { +func (yamllsConnector YamllsConnector) InitiallySyncOpenDocuments(docs []*lsplocal.Document) { if yamllsConnector.Conn == nil { return } - for _, doc := range yamllsConnector.documents.GetAllDocs() { + for _, doc := range docs { yamllsConnector.DocumentDidOpen(doc.Ast, lsp.DidOpenTextDocumentParams{ TextDocument: lsp.TextDocumentItem{ URI: doc.URI, diff --git a/internal/adapter/yamlls/yamlls.go b/internal/adapter/yamlls/yamlls.go index b753047c..f939d8e7 100644 --- a/internal/adapter/yamlls/yamlls.go +++ b/internal/adapter/yamlls/yamlls.go @@ -13,9 +13,8 @@ import ( var logger = log.GetLogger() type YamllsConnector struct { - Conn *jsonrpc2.Conn - documents *lsplocal.DocumentStore - config util.YamllsConfiguration + Conn *jsonrpc2.Conn + config util.YamllsConfiguration } func NewConnector(yamllsConfiguration util.YamllsConfiguration, clientConn jsonrpc2.Conn, documents *lsplocal.DocumentStore) *YamllsConnector { @@ -55,7 +54,6 @@ func NewConnector(yamllsConfiguration util.YamllsConfiguration, clientConn jsonr conn := jsonrpc2.NewConn(jsonrpc2.NewStream(readWriteCloser)) yamllsConnector.config = yamllsConfiguration conn.Go(context.Background(), yamllsConnector.yamllsHandler(clientConn, documents)) - yamllsConnector.documents = documents yamllsConnector.Conn = &conn return &yamllsConnector } diff --git a/internal/handler/configuration.go b/internal/handler/configuration.go index 09674d4f..151bc78e 100644 --- a/internal/handler/configuration.go +++ b/internal/handler/configuration.go @@ -10,7 +10,8 @@ import ( ) func (h *langHandler) handleWorkspaceDidChangeConfiguration(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request) (err error) { - go h.retrieveWorkspaceConfiguration(ctx) + // go h.retrieveWorkspaceConfiguration(ctx) + logger.Println("Changing workspace config is not implemented") return reply(ctx, nil, nil) } @@ -28,6 +29,11 @@ func (h *langHandler) retrieveWorkspaceConfiguration(ctx context.Context) { logger.Println("Workspace configuration:", result) } - h.helmlsConfig = result[0] + if len(result) == 0 { + logger.Println("Workspace configuration is empty") + return + } + + h.setConfig(result[0]) h.initializationWithConfig(ctx) } diff --git a/internal/handler/handler.go b/internal/handler/handler.go index 3fb6e813..cdd1e283 100644 --- a/internal/handler/handler.go +++ b/internal/handler/handler.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "sync" "github.com/mrjosh/helm-ls/internal/adapter/fs" "github.com/mrjosh/helm-ls/internal/adapter/yamlls" @@ -21,6 +22,7 @@ import ( var logger = log.GetLogger() type langHandler struct { + sync.RWMutex connPool jsonrpc2.Conn linterName string documents *lsplocal.DocumentStore @@ -33,6 +35,18 @@ type langHandler struct { helmlsConfig util.HelmlsConfiguration } +func (h *langHandler) setConfig(config util.HelmlsConfiguration) { + h.Lock() + defer h.Unlock() + h.helmlsConfig = config +} + +func (h *langHandler) getConfig() (config util.HelmlsConfiguration) { + h.Lock() + defer h.Unlock() + return h.helmlsConfig +} + func NewHandler(connPool jsonrpc2.Conn) jsonrpc2.Handler { fileStorage, _ := fs.NewFileStorage("") documents := lsplocal.NewDocumentStore(fileStorage) @@ -96,7 +110,7 @@ func (h *langHandler) handleTextDocumentDidOpen(ctx context.Context, reply jsonr return reply(ctx, nil, err) } - doc, err := h.documents.DidOpen(params, &h.helmlsConfig) + doc, err := h.documents.DidOpen(params, h.getConfig()) if err != nil { logger.Println(err) return reply(ctx, nil, err) diff --git a/internal/handler/initialization.go b/internal/handler/initialization.go index c3605c07..826cf53c 100644 --- a/internal/handler/initialization.go +++ b/internal/handler/initialization.go @@ -74,15 +74,16 @@ func (h *langHandler) handleInitialize(ctx context.Context, reply jsonrpc2.Repli } func (h *langHandler) initializationWithConfig(ctx context.Context) { - configureLogLevel(h.helmlsConfig) + configureLogLevel(h.getConfig()) configureYamlls(h) } func configureYamlls(h *langHandler) { - if h.helmlsConfig.YamllsConfiguration.Enabled { - h.yamllsConnector = yamlls.NewConnector(h.helmlsConfig.YamllsConfiguration, h.connPool, h.documents) + config := h.getConfig() + if config.YamllsConfiguration.Enabled { + h.yamllsConnector = yamlls.NewConnector(config.YamllsConfiguration, h.connPool, h.documents) h.yamllsConnector.CallInitialize(h.projectFiles.RootURI) - h.yamllsConnector.InitiallySyncOpenDocuments() + h.yamllsConnector.InitiallySyncOpenDocuments(h.documents.GetAllDocs()) } } diff --git a/internal/lsp/diagnostics_cache.go b/internal/lsp/diagnostics_cache.go index 1140db82..c0f4deac 100644 --- a/internal/lsp/diagnostics_cache.go +++ b/internal/lsp/diagnostics_cache.go @@ -8,12 +8,12 @@ import ( type diagnosticsCache struct { YamlDiagnostics []lsp.Diagnostic HelmDiagnostics []lsp.Diagnostic - helmlsConfig *util.HelmlsConfiguration + helmlsConfig util.HelmlsConfiguration gotYamlDiagnosticsTimes int yamlDiagnosticsCountReduced bool } -func NewDiagnosticsCache(helmlsConfig *util.HelmlsConfiguration) diagnosticsCache { +func NewDiagnosticsCache(helmlsConfig util.HelmlsConfiguration) diagnosticsCache { return diagnosticsCache{ []lsp.Diagnostic{}, []lsp.Diagnostic{}, diff --git a/internal/lsp/diagnostics_cache_test.go b/internal/lsp/diagnostics_cache_test.go index 3c218829..f2e83e1e 100644 --- a/internal/lsp/diagnostics_cache_test.go +++ b/internal/lsp/diagnostics_cache_test.go @@ -9,7 +9,7 @@ import ( ) func TestDiagnosticsCache_SetYamlDiagnostics(t *testing.T) { - helmlsConfig := &util.HelmlsConfiguration{} + helmlsConfig := util.HelmlsConfiguration{} cache := NewDiagnosticsCache(helmlsConfig) diagnostics := []lsp.Diagnostic{ @@ -34,7 +34,7 @@ func TestDiagnosticsCache_SetYamlDiagnostics(t *testing.T) { } func TestDiagnosticsCache_GetMergedDiagnostics(t *testing.T) { - helmlsConfig := &util.DefaultConfig + helmlsConfig := util.DefaultConfig cache := NewDiagnosticsCache(helmlsConfig) yamlDiagnostics := []lsp.Diagnostic{ @@ -72,7 +72,7 @@ func TestDiagnosticsCache_GetMergedDiagnostics(t *testing.T) { } func TestDiagnosticsCache_ShouldShowDiagnosticsOnNewYamlDiagnostics(t *testing.T) { - helmlsConfig := &util.HelmlsConfiguration{} + helmlsConfig := util.HelmlsConfiguration{} cache := NewDiagnosticsCache(helmlsConfig) yamlDiagnostics := []lsp.Diagnostic{ { @@ -102,7 +102,7 @@ func TestDiagnosticsCache_ShouldShowDiagnosticsOnNewYamlDiagnostics(t *testing.T } func TestDiagnosticsCache_ShouldShowDiagnosticsOnNewYamlDiagnosticsForInitialDiagnostics(t *testing.T) { - helmlsConfig := &util.HelmlsConfiguration{} + helmlsConfig := util.HelmlsConfiguration{} cache := NewDiagnosticsCache(helmlsConfig) yamlDiagnostics := []lsp.Diagnostic{ { diff --git a/internal/lsp/document.go b/internal/lsp/document.go index 9e84abfa..ea4bbc0a 100644 --- a/internal/lsp/document.go +++ b/internal/lsp/document.go @@ -32,7 +32,7 @@ func (s *DocumentStore) GetAllDocs() []*Document { return docs } -func (s *DocumentStore) DidOpen(params lsp.DidOpenTextDocumentParams,helmlsConfig *util.HelmlsConfiguration) (*Document, error) { +func (s *DocumentStore) DidOpen(params lsp.DidOpenTextDocumentParams,helmlsConfig util.HelmlsConfiguration) (*Document, error) { //langID := params.TextDocument.LanguageID //if langID != "markdown" && langID != "vimwiki" && langID != "pandoc" { //return nil, nil