From 1077299177eae45b9b9ce9d69f85d19e7ca4c021 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sat, 11 May 2024 14:41:06 +0200 Subject: [PATCH] feat: rework diagnostics --- internal/adapter/yamlls/documentSync.go | 2 +- internal/handler/text_document.go | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/adapter/yamlls/documentSync.go b/internal/adapter/yamlls/documentSync.go index 1d566b58..9c10e054 100644 --- a/internal/adapter/yamlls/documentSync.go +++ b/internal/adapter/yamlls/documentSync.go @@ -91,7 +91,7 @@ func (yamllsConnector Connector) DocumentDidChangeFullSync(doc *lsplocal.Documen return } - logger.Println("Sending DocumentDidChange with full sync, current content:", doc.Content) + logger.Debug("Sending DocumentDidChange with full sync, current content:", doc.Content) trimmedText := lsplocal.TrimTemplate(doc.Ast.Copy(), doc.Content) params.ContentChanges = []lsp.TextDocumentContentChangeEvent{ diff --git a/internal/handler/text_document.go b/internal/handler/text_document.go index d8c75a8e..2ec2d4c5 100644 --- a/internal/handler/text_document.go +++ b/internal/handler/text_document.go @@ -28,9 +28,16 @@ func (h *langHandler) DidOpen(ctx context.Context, params *lsp.DidOpenTextDocume if err != nil { logger.Error("Error getting chart info for file", doc.URI, err) } - notification := lsplocal.GetDiagnosticsNotification(chart, doc) + notifications := lsplocal.GetDiagnosticsNotifications(chart, doc) - return h.client.PublishDiagnostics(ctx, notification) + defer func() { + for _, notification := range notifications { + logger.Println("Publishing", notification) + h.client.PublishDiagnostics(ctx, ¬ification) + } + }() + + return nil } func (h *langHandler) DidClose(ctx context.Context, params *lsp.DidCloseTextDocumentParams) (err error) { @@ -48,9 +55,16 @@ func (h *langHandler) DidSave(ctx context.Context, params *lsp.DidSaveTextDocume } h.yamllsConnector.DocumentDidSave(doc, *params) - notification := lsplocal.GetDiagnosticsNotification(chart, doc) + notifications := lsplocal.GetDiagnosticsNotifications(chart, doc) - return h.client.PublishDiagnostics(ctx, notification) + defer func() { + for _, notification := range notifications { + logger.Println("Publishing", notification) + h.client.PublishDiagnostics(ctx, ¬ification) + } + }() + + return nil } func (h *langHandler) DidChange(ctx context.Context, params *lsp.DidChangeTextDocumentParams) (err error) {