diff --git a/private/buf/buflsp/file.go b/private/buf/buflsp/file.go index f5e21c98b0..e9f614df68 100644 --- a/private/buf/buflsp/file.go +++ b/private/buf/buflsp/file.go @@ -854,36 +854,33 @@ func (f *file) RunChecks(ctx context.Context) { f.cancelChecks = cancel go func() { - image, diagnostics := buildImage(ctx, path, f.lsp.logger, opener) - if image == nil { - f.lsp.logger.DebugContext(ctx, "checks cancelled on image build", slog.String("uri", f.uri.Filename())) - return - } - - f.lsp.logger.DebugContext(ctx, "checks running lint", slog.String("uri", f.uri.Filename()), slog.String("module", module.OpaqueID())) var annotations []bufanalysis.FileAnnotation - if err := checkClient.Lint( - ctx, - workspace.GetLintConfigForOpaqueID(module.OpaqueID()), - image, - bufcheck.WithPluginConfigs(workspace.PluginConfigs()...), - bufcheck.WithPolicyConfigs(workspace.PolicyConfigs()...), - ); err != nil { - var fileAnnotationSet bufanalysis.FileAnnotationSet - if !errors.As(err, &fileAnnotationSet) { - if errors.Is(err, context.Canceled) { - f.lsp.logger.DebugContext(ctx, "checks cancelled", slog.String("uri", f.uri.Filename()), xslog.ErrorAttr(err)) - } else if errors.Is(err, context.DeadlineExceeded) { - f.lsp.logger.WarnContext(ctx, "checks deadline exceeded", slog.String("uri", f.uri.Filename()), xslog.ErrorAttr(err)) + image, diagnostics := buildImage(ctx, path, f.lsp.logger, opener) + if image != nil { + f.lsp.logger.DebugContext(ctx, "checks running lint", slog.String("uri", f.uri.Filename()), slog.String("module", module.OpaqueID())) + if err := checkClient.Lint( + ctx, + workspace.GetLintConfigForOpaqueID(module.OpaqueID()), + image, + bufcheck.WithPluginConfigs(workspace.PluginConfigs()...), + bufcheck.WithPolicyConfigs(workspace.PolicyConfigs()...), + ); err != nil { + var fileAnnotationSet bufanalysis.FileAnnotationSet + if !errors.As(err, &fileAnnotationSet) { + if errors.Is(err, context.Canceled) { + f.lsp.logger.DebugContext(ctx, "checks cancelled", slog.String("uri", f.uri.Filename()), xslog.ErrorAttr(err)) + } else if errors.Is(err, context.DeadlineExceeded) { + f.lsp.logger.WarnContext(ctx, "checks deadline exceeded", slog.String("uri", f.uri.Filename()), xslog.ErrorAttr(err)) + } else { + f.lsp.logger.WarnContext(ctx, "checks failed", slog.String("uri", f.uri.Filename()), xslog.ErrorAttr(err)) + } + return + } + if len(fileAnnotationSet.FileAnnotations()) == 0 { + f.lsp.logger.DebugContext(ctx, "checks lint passed", slog.String("uri", f.uri.Filename())) } else { - f.lsp.logger.WarnContext(ctx, "checks failed", slog.String("uri", f.uri.Filename()), xslog.ErrorAttr(err)) + annotations = append(annotations, fileAnnotationSet.FileAnnotations()...) } - return - } - if len(fileAnnotationSet.FileAnnotations()) == 0 { - f.lsp.logger.DebugContext(ctx, "checks lint passed", slog.String("uri", f.uri.Filename())) - } else { - annotations = append(annotations, fileAnnotationSet.FileAnnotations()...) } } diff --git a/private/buf/buflsp/image.go b/private/buf/buflsp/image.go index e96a2e9f55..6659bd0636 100644 --- a/private/buf/buflsp/image.go +++ b/private/buf/buflsp/image.go @@ -91,7 +91,7 @@ func buildImage( } } if len(compiled) == 0 || compiled[0] == nil { - return nil, nil // Image failed to build. + return nil, diagnostics // Image failed to build. } compiledFile := compiled[0]