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

SLVS-1483 Implement apply fix suggestion #5726

Merged
merged 11 commits into from
Oct 7, 2024

Conversation

vnaskos-sonar
Copy link
Contributor

@vnaskos-sonar vnaskos-sonar commented Oct 3, 2024

Copy link
Contributor

@gabriela-trutan-sonarsource gabriela-trutan-sonarsource left a comment

Choose a reason for hiding this comment

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

I have a weird behavior when applying this quick fix multiple times in the src/CFamily/CMake/EnvironmentVarsProvider.cs class (https://sonarcloud.io/project/issues?issueStatuses=OPEN%2CCONFIRMED&id=sonarlint-visualstudio&open=AXvvZrcGMCXQ68kD9EcE&tab=suggested_fix&get-fix=true): a line is being removed each time the "View fix in IDE" button is clicked.

Also please see some feedback bellow,

try
{
var spanToUpdate = issueSpanCalculator.CalculateSpan(textView.TextSnapshot, changeDto.beforeLineRange.startLine, changeDto.beforeLineRange.endLine);
textView.Caret.MoveTo(spanToUpdate.Start);

Choose a reason for hiding this comment

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

We should not move the caret and make each change visible (lines 105-106). In doing so, we will affect performance and execute logic that is not really needed. E.g. If there are 20 changes for a fix, we don't have to always move the caret and ensure it is visible, only for the last one.

throw new NotImplementedException();
ideWindowService.BringToFront();
var textView = documentNavigator.Open(absoluteFilePath);
for (var i = changes.Count - 1; i >= 0; i--)

Choose a reason for hiding this comment

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

Because it is in descending order, the last change that is visible is actually the first change. Do you think it makes sense? Or should the last change be the visible one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There were two considerations behind this decision:

  1. The first change is what triggered the error, so it would make sense to bring the focus to that line.
  2. Sometimes, the last change is just a removal of the last empty line; bringing the focus to the first would make more sense than showing the last removed line.

Choose a reason for hiding this comment

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

I understand 1. But I don't think we can really judge that 2 is something that will always happen (it might be that the first change is removing a line).

Anyway, we can leave it like this and see the feedback from users. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same behavior applies to SLI, it focuses on the first change.

Copy link

sonarqubecloud bot commented Oct 7, 2024

var textView = MockOpenFile();
MockConfigScopeRoot();

testSubject.ApplyFixSuggestion(suggestionParams);

textView.ViewScroller.Received().EnsureSpanVisible(affectedSnapshot, EnsureSpanVisibleOptions.AlwaysCenter);
textView.ViewScroller.ReceivedWithAnyArgs(1).EnsureSpanVisible(Arg.Any<SnapshotSpan>(), default);
textView.ViewScroller.Received().EnsureSpanVisible(firstAffectedSnapshot, EnsureSpanVisibleOptions.AlwaysCenter);

Choose a reason for hiding this comment

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

Here it should also be Received(1).EnsureSpanVisible to ensure it is received once and not any amount of times (Received() will not check for the amount of times it is called)

textView.ViewScroller.EnsureSpanVisible(spanToUpdate, EnsureSpanVisibleOptions.AlwaysCenter);
if (i == 0)
{
textView.Caret.MoveTo(spanToUpdate.Start);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider extracting the lines 106-110 into a separate method. Clean code usually recommends to avoid having huge methods as this crowds the logic and makes it more difficult to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this particular case, I think that it's better not to extract the if to a separate method. If I had to move something for clarity I would consider reworking the try. I would leave it as is at the moment and come back for refactoring when all the tasks affecting this piece are done.

Choose a reason for hiding this comment

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

Will there be a coming back to the refactoring, though? There is no task for it...

@vnaskos-sonar vnaskos-sonar merged commit 8a65ee7 into feature/fix-suggestion Oct 7, 2024
8 checks passed
@vnaskos-sonar vnaskos-sonar deleted the gt/implement-fix-suggestion branch October 7, 2024 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants