Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions private/buf/buflsp/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()...)
}
}

Expand Down
2 changes: 1 addition & 1 deletion private/buf/buflsp/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down