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-1532 Remove unreachable BindingUpdated code from ActiveSolutionBoundTracker #5939

Merged
merged 1 commit into from
Jan 8, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public async Task BindAsync_NotifiesBindingChanged()

activeSolutionChangedHandler
.Received(1)
.HandleBindingChange(false);
.HandleBindingChange();
}

[TestMethod]
Expand Down Expand Up @@ -126,7 +126,7 @@ public void Unbind_BindingDeletionSucceeded_HandlesBindingChangesAndDisconnects(
{
solutionBindingRepository.DeleteBinding(AnyBoundProject.LocalBindingKey);
sonarQubeService.Disconnect();
activeSolutionChangedHandler.HandleBindingChange(true);
activeSolutionChangedHandler.HandleBindingChange();
});
}

Expand All @@ -138,7 +138,7 @@ public void Unbind_BindingDeletionFailed_DoesNotCallHandleBindingChange()
testSubject.Unbind(AnyBoundProject.LocalBindingKey);

solutionBindingRepository.Received(1).DeleteBinding(AnyBoundProject.LocalBindingKey);
activeSolutionChangedHandler.DidNotReceive().HandleBindingChange(true);
activeSolutionChangedHandler.DidNotReceive().HandleBindingChange();
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions src/ConnectedMode/Binding/IUnintrusiveBindingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task BindAsync(BoundServerProject project, CancellationToken cancel
var connectionInformation = new ConnectionInformation(project.ServerConnection.ServerUri, project.ServerConnection.Credentials);
await sonarQubeService.ConnectAsync(connectionInformation, cancellationToken);
await BindAsync(project, null, cancellationToken);
activeSolutionChangedHandler.HandleBindingChange(false);
activeSolutionChangedHandler.HandleBindingChange();
}

public async Task BindAsync(BoundServerProject project, IProgress<FixedStepsProgress> progress, CancellationToken token)
Expand All @@ -81,7 +81,7 @@ public bool Unbind(string localBindingKey)
if (bindingDeleted)
{
sonarQubeService.Disconnect();
activeSolutionChangedHandler.HandleBindingChange(true);
activeSolutionChangedHandler.HandleBindingChange();
}
return bindingDeleted;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Binding/IActiveSolutionBoundTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace SonarLint.VisualStudio.Core.Binding
{
public interface IActiveSolutionChangedHandler
{
void HandleBindingChange(bool isBindingCleared);
void HandleBindingChange();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void ActiveSolutionBoundTracker_UnBoundProject_NullPassedToConfigScopeUpd
configScopeUpdaterMock.Verify(x => x.UpdateConfigScopeForCurrentSolution(null));
configScopeUpdaterMock.VerifyNoOtherCalls();
}

[TestMethod]
public void ActiveSolutionBoundTracker_Changes()
{
Expand Down Expand Up @@ -220,7 +220,7 @@ public void ActiveSolutionBoundTracker_Changes()
activeSolutionTracker.CurrentSolutionName = "solution1";

// Act
testSubject.HandleBindingChange(true);
testSubject.HandleBindingChange();

// Assert
testSubject.CurrentConfiguration.Mode.Should().Be(SonarLintMode.Standalone, "Unbound solution should report false activation");
Expand All @@ -237,7 +237,7 @@ public void ActiveSolutionBoundTracker_Changes()
// Case 2: Set bound project
ConfigureSolutionBinding(boundSonarQubeProject);
// Act
testSubject.HandleBindingChange(false);
testSubject.HandleBindingChange();

// Assert
testSubject.CurrentConfiguration.Mode.Should().Be(SonarLintMode.Connected, "Bound solution should report true activation");
Expand Down Expand Up @@ -309,7 +309,7 @@ public void ActiveSolutionBoundTracker_Changes()
// Act
testSubject.Dispose();
ConfigureSolutionBinding(boundSonarQubeProject);
testSubject.HandleBindingChange(true);
testSubject.HandleBindingChange();

// Assert
eventCounter.PreSolutionBindingChangedCount.Should().Be(5, "Once disposed should stop raising the event");
Expand Down Expand Up @@ -420,14 +420,14 @@ public void UpdateConnection_Disconnect_ServiceDisconnectedIsCalled()
}

[TestMethod]
public void HandleBindingChange_WhenClearBoundProject_NotRaised()
public void HandleBindingChange_WhenSameProject_NotRaised()
{
// Arrange
using var testSubject = CreateTestSubject(activeSolutionTracker, configProvider, loggerMock.Object);
var eventCounter = new EventCounter(testSubject);

// Act
testSubject.HandleBindingChange(true);
testSubject.HandleBindingChange();

// Assert
eventCounter.PreSolutionBindingUpdatedCount.Should().Be(0);
Expand All @@ -437,24 +437,21 @@ public void HandleBindingChange_WhenClearBoundProject_NotRaised()
}

[TestMethod]
public void HandleBindingChange_WhenSetBoundProject_EventsRaisedInExpectedOrder()
public void HandleBindingChange_WhenProjectChanged_RaisedChangedEvents()
{
// Arrange
using var testSubject = CreateTestSubject(activeSolutionTracker, configProvider, loggerMock.Object);
var eventCounter = new EventCounter(testSubject);
ConfigureSolutionBinding(boundSonarQubeProject);

// Act
testSubject.HandleBindingChange(false);
testSubject.HandleBindingChange();

// Assert
eventCounter.PreSolutionBindingUpdatedCount.Should().Be(1);
eventCounter.SolutionBindingUpdatedCount.Should().Be(1);
eventCounter.PreSolutionBindingChangedCount.Should().Be(0);
eventCounter.SolutionBindingChangedCount.Should().Be(0);

eventCounter.RaisedEventNames.Should().HaveCount(2);
eventCounter.RaisedEventNames[0].Should().Be(nameof(testSubject.PreSolutionBindingUpdated));
eventCounter.RaisedEventNames[1].Should().Be(nameof(testSubject.SolutionBindingUpdated));
eventCounter.PreSolutionBindingUpdatedCount.Should().Be(0);
eventCounter.SolutionBindingUpdatedCount.Should().Be(0);
eventCounter.PreSolutionBindingChangedCount.Should().Be(1);
eventCounter.SolutionBindingChangedCount.Should().Be(1);
}

[TestMethod]
Expand Down
11 changes: 3 additions & 8 deletions src/Integration/MefServices/ActiveSolutionBoundTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public ActiveSolutionBoundTracker([Import(typeof(SVsServiceProvider))] IServiceP
this.gitEventsMonitor.HeadChanged += GitEventsMonitor_HeadChanged;
}

public void HandleBindingChange(bool isBindingCleared)
public void HandleBindingChange()
{
if (disposed)
{
return;
}

this.RaiseAnalyzersChangedIfBindingChanged(GetBindingConfiguration(), isBindingCleared);
this.RaiseAnalyzersChangedIfBindingChanged(GetBindingConfiguration());
}

private BindingConfiguration GetBindingConfiguration()
Expand Down Expand Up @@ -162,7 +162,7 @@ private async Task<bool> UpdateConnectionAsync(BindingConfiguration bindingConfi
return isConnected;
}

private void RaiseAnalyzersChangedIfBindingChanged(BindingConfiguration newBindingConfiguration, bool? isBindingCleared = null)
private void RaiseAnalyzersChangedIfBindingChanged(BindingConfiguration newBindingConfiguration)
{
configScopeUpdater.UpdateConfigScopeForCurrentSolution(newBindingConfiguration.Project);

Expand All @@ -174,11 +174,6 @@ private void RaiseAnalyzersChangedIfBindingChanged(BindingConfiguration newBindi
PreSolutionBindingChanged?.Invoke(this, args);
SolutionBindingChanged?.Invoke(this, args);
}
else if (isBindingCleared == false)
{ // todo remove unreachable code & cleanup https://sonarsource.atlassian.net/browse/SLVS-1532
PreSolutionBindingUpdated?.Invoke(this, EventArgs.Empty);
SolutionBindingUpdated?.Invoke(this, EventArgs.Empty);
}

SetBoundSolutionUIContext();
}
Expand Down
Loading