Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always finish progress in autofixing #478

Merged
merged 6 commits into from
Apr 2, 2024
10 changes: 7 additions & 3 deletions infrastructure/code/issue_enhancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package code
import (
"context"
"fmt"
"math"
"strconv"
"time"

Expand Down Expand Up @@ -134,9 +135,10 @@ func (b *IssueEnhancer) autofixFunc(ctx context.Context, issue snyk.Issue,
s := b.instrumentor.StartSpan(ctx, method)
defer b.instrumentor.Finish(s)

progress := progress.NewTracker(true)
p := progress.NewTracker(true)
fixMsg := "Attempting to fix " + issueTitle(issue) + " (Snyk)"
progress.BeginWithMessage(fixMsg, "")
p.BeginWithMessage(fixMsg, "")
defer p.End()
b.notifier.SendShowMessage(sglsp.Info, fixMsg)

relativePath, err := ToRelativeUnixPath(b.rootPath, issue.AffectedFilePath)
Expand Down Expand Up @@ -187,15 +189,18 @@ func (b *IssueEnhancer) autofixFunc(ctx context.Context, issue snyk.Issue,
defer pollingTicker.Stop()
timeoutTimer := time.NewTimer(2 * time.Minute)
defer timeoutTimer.Stop()
tries := 1.0
for {
select {
case <-timeoutTimer.C:
log.Error().Str("method", "GetAutofixSuggestions").Str("requestId", b.requestId).Msg("timeout requesting autofix")
b.notifier.SendShowMessage(sglsp.MTError, "Something went wrong. Please try again. Request ID: "+b.requestId)
return nil
case <-pollingTicker.C:
p.ReportWithMessage(int(math.Min(tries, 99)), "Polling for fix...")
fix, complete := pollFunc()
if !complete {
tries++
Comment on lines +200 to +203
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is going it be showing 99 until tries passes 99, right? We are not aiming to show a progress I understand

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, it's gonna show a progress up to the 99s limit - with Max it was only showing 99...

continue
}

Expand All @@ -204,7 +209,6 @@ func (b *IssueEnhancer) autofixFunc(ctx context.Context, issue snyk.Issue,
return nil
}

progress.End()
// send feedback asynchronously, so people can actually see the changes done by the fix
go func() {
actionCommandMap, err := b.autofixFeedbackActions(fix.FixId)
Expand Down
Loading