diff --git a/cmds/lint.go b/cmds/lint.go index 6319aa0f..03ba3f05 100644 --- a/cmds/lint.go +++ b/cmds/lint.go @@ -26,10 +26,7 @@ func newLintCmd() *cobra.Command { return err } - msgs, err := locallsp.GetDiagnostics(rootPath, chart.ValuesFiles.MainValuesFile.Values) - if err != nil { - return err - } + msgs := locallsp.GetDiagnostics(rootPath, chart.ValuesFiles.MainValuesFile.Values) for _, msg := range msgs { fmt.Println(msg) diff --git a/internal/adapter/yamlls/yamlls.go b/internal/adapter/yamlls/yamlls.go index c9e5b4f7..9349f0b2 100644 --- a/internal/adapter/yamlls/yamlls.go +++ b/internal/adapter/yamlls/yamlls.go @@ -23,7 +23,7 @@ type Connector struct { client protocol.Client } -func NewConnector(yamllsConfiguration util.YamllsConfiguration, client protocol.Client, documents *lsplocal.DocumentStore) *Connector { +func NewConnector(ctx context.Context, yamllsConfiguration util.YamllsConfiguration, client protocol.Client, documents *lsplocal.DocumentStore) *Connector { yamllsCmd := exec.Command(yamllsConfiguration.Path, "--stdio") stdin, err := yamllsCmd.StdinPipe() @@ -43,12 +43,6 @@ func NewConnector(yamllsConfiguration util.YamllsConfiguration, client protocol. return &Connector{} } - go func() { - for { - io.Copy(os.Stderr, strderr) - } - }() - readWriteCloser := readWriteCloseSubprocess{ stout, stdin, @@ -68,11 +62,15 @@ func NewConnector(yamllsConfiguration util.YamllsConfiguration, client protocol. return &Connector{} } } + + go func() { + io.Copy(os.Stderr, strderr) + }() + yamllsConnector := Connector{documents: documents, config: yamllsConfiguration, client: client} - ctx := context.Background() zapLogger, _ := zap.NewProduction() - ctx, _, server := protocol.NewClient(ctx, yamllsConnector, jsonrpc2.NewStream(readWriteCloser), zapLogger) + _, _, server := protocol.NewClient(ctx, yamllsConnector, jsonrpc2.NewStream(readWriteCloser), zapLogger) yamllsConnector.server = server return &yamllsConnector diff --git a/internal/handler/initialization.go b/internal/handler/initialization.go index b388d610..d1b7bd26 100644 --- a/internal/handler/initialization.go +++ b/internal/handler/initialization.go @@ -63,7 +63,7 @@ func (h *langHandler) initializationWithConfig(ctx context.Context) { func configureYamlls(ctx context.Context, h *langHandler) { config := h.helmlsConfig if config.YamllsConfiguration.Enabled { - h.yamllsConnector = yamlls.NewConnector(config.YamllsConfiguration, h.client, h.documents) + h.yamllsConnector = yamlls.NewConnector(ctx, config.YamllsConfiguration, h.client, h.documents) err := h.yamllsConnector.CallInitialize(ctx, h.chartStore.RootURI) if err != nil { logger.Error("Error initializing yamlls", err) diff --git a/internal/handler/text_document.go b/internal/handler/text_document.go index bc9e1283..be3a64a0 100644 --- a/internal/handler/text_document.go +++ b/internal/handler/text_document.go @@ -31,11 +31,9 @@ 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, err := lsplocal.NotificationFromLint(ctx, h.connPool, chart, doc) + notification := lsplocal.NotificationFromLint(ctx, h.connPool, chart, doc) - h.client.PublishDiagnostics(ctx, notification) - - return err + return h.client.PublishDiagnostics(ctx, notification) } func (h *langHandler) DidClose(ctx context.Context, params *lsp.DidCloseTextDocumentParams) (err error) { @@ -53,10 +51,9 @@ func (h *langHandler) DidSave(ctx context.Context, params *lsp.DidSaveTextDocume } h.yamllsConnector.DocumentDidSave(doc, *params) - notification, err := lsplocal.NotificationFromLint(ctx, h.connPool, chart, doc) + notification := lsplocal.NotificationFromLint(ctx, h.connPool, chart, doc) - h.client.PublishDiagnostics(ctx, notification) - return nil + return h.client.PublishDiagnostics(ctx, notification) } func (h *langHandler) DidChange(ctx context.Context, params *lsp.DidChangeTextDocumentParams) (err error) { diff --git a/internal/lsp/lint.go b/internal/lsp/lint.go index 5950a1d2..32526b71 100644 --- a/internal/lsp/lint.go +++ b/internal/lsp/lint.go @@ -23,27 +23,24 @@ import ( var logger = log.GetLogger() -func NotificationFromLint(ctx context.Context, conn jsonrpc2.Conn, chart *charts.Chart, doc *Document) (*lsp.PublishDiagnosticsParams, error) { +func NotificationFromLint(_ context.Context, conn jsonrpc2.Conn, chart *charts.Chart, doc *Document) *lsp.PublishDiagnosticsParams { vals := chart.ValuesFiles.MainValuesFile.Values if chart.ValuesFiles.OverlayValuesFile != nil { vals = chartutil.CoalesceTables(chart.ValuesFiles.OverlayValuesFile.Values, chart.ValuesFiles.MainValuesFile.Values) } - diagnostics, err := GetDiagnostics(doc.URI, vals) - if err != nil { - return nil, err - } + diagnostics := GetDiagnostics(doc.URI, vals) doc.DiagnosticsCache.HelmDiagnostics = diagnostics return &lsp.PublishDiagnosticsParams{ URI: doc.URI, Diagnostics: doc.DiagnosticsCache.GetMergedDiagnostics(), - }, nil + } } // GetDiagnostics will run helm linter against the currect document URI using the given values // and converts the helm.support.Message to lsp.Diagnostics -func GetDiagnostics(uri uri.URI, vals chartutil.Values) ([]lsp.Diagnostic, error) { +func GetDiagnostics(uri uri.URI, vals chartutil.Values) []lsp.Diagnostic { var ( filename = uri.Filename() paths = strings.Split(filename, "/") @@ -60,7 +57,6 @@ func GetDiagnostics(uri uri.URI, vals chartutil.Values) ([]lsp.Diagnostic, error } } - logger.Println(dir) client := action.NewLint() result := client.Run([]string{dir}, vals) @@ -77,7 +73,7 @@ func GetDiagnostics(uri uri.URI, vals chartutil.Values) ([]lsp.Diagnostic, error diagnostics = append(diagnostics, *d) } - return diagnostics, nil + return diagnostics } func GetDiagnosticFromLinterErr(supMsg support.Message) (*lsp.Diagnostic, string, error) {