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-1876 Mute Issue cleanup unused fields #6036

Merged
merged 3 commits into from
Feb 19, 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 @@ -47,7 +47,6 @@ public class ConnectedModeFeaturesConfiguration : IConnectedModeFeaturesConfigur
{
private readonly Version minimalSonarQubeVersionForHotspots = new Version(9, 7);
private readonly Version minimalSonarQubeVersionForNewTaxonomy = new Version(10, 2);
private readonly Version minimalSonarQubeVersionForAccept = new Version(10, 4);
private readonly ISonarQubeService sonarQubeService;

[ImportingConstructor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using Microsoft.VisualStudio.TestTools.UnitTesting;
using SonarLint.VisualStudio.Core.Binding;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Configuration;
using SonarLint.VisualStudio.Core.Binding;
using SonarLint.VisualStudio.Core.Transition;
using SonarLint.VisualStudio.Integration.Transition;
using SonarLint.VisualStudio.TestInfrastructure;
Expand All @@ -32,18 +30,12 @@ namespace SonarLint.VisualStudio.Integration.UnitTests.Transition
public class MuteIssuesWindowServiceTests
{
[TestMethod]
public void MefCtor_CheckIsExported()
{
public void MefCtor_CheckIsExported() =>
MefTestHelpers.CheckTypeCanBeImported<MuteIssuesWindowService, IMuteIssuesWindowService>(
MefTestHelpers.CreateExport<IConnectedModeFeaturesConfiguration>(),
MefTestHelpers.CreateExport<IActiveSolutionBoundTracker>(),
MefTestHelpers.CreateExport<IBrowserService>());
}

[TestMethod]
public void MefCtor_CheckIsSingleton()
{
MefTestHelpers.CheckIsSingletonMefComponent<MuteIssuesWindowService>();
}
public void MefCtor_CheckIsSingleton() => MefTestHelpers.CheckIsSingletonMefComponent<MuteIssuesWindowService>();
}
}
19 changes: 3 additions & 16 deletions src/Integration.Vsix.UnitTests/Analysis/IssueHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

using Microsoft.VisualStudio.Shell.TableManager;
using Microsoft.VisualStudio.Text;
using SonarLint.VisualStudio.ConnectedMode.Suppressions;
using SonarLint.VisualStudio.Core.Analysis;
using SonarLint.VisualStudio.Integration.Vsix;
using SonarLint.VisualStudio.Integration.Vsix.Analysis;
Expand Down Expand Up @@ -129,20 +128,13 @@ public void HandleNewIssues_IssuesGetMatchesIsNotCalled()
var inputIssues = new[] { CreateIssue("S111", startLine: 1, endLine: 1), CreateIssue("S222", startLine: 2, endLine: 2) };

var notificationHandler = new SnapshotChangeHandler();
var suppressedIssueMatcher = new Mock<ISuppressedIssueMatcher>();

var testSubject = CreateTestSubject(notificationHandler.OnSnapshotChanged, suppressedIssueMatcher.Object);
var testSubject = CreateTestSubject(notificationHandler.OnSnapshotChanged);

// Act
testSubject.HandleNewIssues(inputIssues);

// Assert

foreach (var issue in inputIssues)
{
suppressedIssueMatcher.Verify(x => x.SuppressionExists(issue), Times.Never);
}

notificationHandler.InvocationCount.Should().Be(1);

// Check the updated issues
Expand Down Expand Up @@ -292,39 +284,34 @@ private static ITextDocument CreateValidTextDocument(string filePath)

private static IssueHandler CreateTestSubject(
SnapshotChangedHandler notificationHandler,
ISuppressedIssueMatcher suppressedIssueMatcher = null,
TranslateSpans translator = null,
ITextDocument textDocument = null,
ILocalHotspotsStoreUpdater localHotspotsStoreUpdater = null) =>
CreateTestSubject(notificationHandler, "any project name", Guid.NewGuid(),
suppressedIssueMatcher, translator, textDocument, localHotspotsStoreUpdater);
CreateTestSubject(notificationHandler, "any project name", Guid.NewGuid(), translator, textDocument, localHotspotsStoreUpdater);

private static IssueHandler CreateTestSubject(
SnapshotChangedHandler notificationHandler,
string projectName,
Guid projectGuid,
string filePath,
ILocalHotspotsStoreUpdater localHotspotsStoreUpdater = null) =>
CreateTestSubject(notificationHandler, projectName, projectGuid, null, null, CreateValidTextDocument(filePath), localHotspotsStoreUpdater);
CreateTestSubject(notificationHandler, projectName, projectGuid, null, CreateValidTextDocument(filePath), localHotspotsStoreUpdater);

private static IssueHandler CreateTestSubject(
SnapshotChangedHandler notificationHandler,
string projectName,
Guid projectGuid,
ISuppressedIssueMatcher suppressedIssueMatcher = null,
TranslateSpans translator = null,
ITextDocument textDocument = null,
ILocalHotspotsStoreUpdater localHotspotsStoreUpdater = null)
{
suppressedIssueMatcher ??= Mock.Of<ISuppressedIssueMatcher>();
translator ??= PassthroughSpanTranslator;
textDocument ??= CreateValidTextDocument("any");

var testSubject = new IssueHandler(
textDocument,
projectName,
projectGuid,
suppressedIssueMatcher,
notificationHandler,
localHotspotsStoreUpdater ?? Mock.Of<ILocalHotspotsStoreUpdater>(),
// Override the un-testable "TranslateSpans" behaviour
Expand Down
4 changes: 1 addition & 3 deletions src/Integration.Vsix/Analysis/IssueConsumerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ IIssueConsumer Create(ITextDocument textDocument,
[PartCreationPolicy(CreationPolicy.Shared)]
internal partial class IssueConsumerFactory : IIssueConsumerFactory
{
private readonly ISuppressedIssueMatcher suppressedIssueMatcher;
private readonly IAnalysisIssueVisualizationConverter converter;
private readonly ILocalHotspotsStoreUpdater localHotspotsStore;

[ImportingConstructor]
internal IssueConsumerFactory(ISuppressedIssueMatcher suppressedIssueMatcher, IAnalysisIssueVisualizationConverter converter, ILocalHotspotsStoreUpdater localHotspotsStore)
{
this.suppressedIssueMatcher = suppressedIssueMatcher;
this.converter = converter;
this.localHotspotsStore = localHotspotsStore;
}
Expand All @@ -73,7 +71,7 @@ public IIssueConsumer Create(ITextDocument textDocument,
Guid projectGuid,
SnapshotChangedHandler onSnapshotChanged)
{
var issueHandler = new IssueHandler(textDocument, projectName, projectGuid, suppressedIssueMatcher, onSnapshotChanged, localHotspotsStore);
var issueHandler = new IssueHandler(textDocument, projectName, projectGuid, onSnapshotChanged, localHotspotsStore);
var issueConsumer = new IssueConsumer(analysisSnapshot, analysisFilePath, issueHandler, converter);

return issueConsumer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

using Microsoft.VisualStudio.Text;
using SonarLint.VisualStudio.ConnectedMode.Suppressions;
using SonarLint.VisualStudio.IssueVisualization.Models;
using SonarLint.VisualStudio.IssueVisualization.Security.Hotspots;

Expand All @@ -44,7 +43,6 @@ internal class IssueHandler : IIssueHandler
private readonly ITextDocument textDocument;
private readonly string projectName;
private readonly Guid projectGuid;
private readonly ISuppressedIssueMatcher suppressedIssueMatcher;
private readonly SnapshotChangedHandler onSnapshotChanged;
private readonly ILocalHotspotsStoreUpdater localHotspotsStore;

Expand All @@ -54,26 +52,23 @@ public IssueHandler(
ITextDocument textDocument,
string projectName,
Guid projectGuid,
ISuppressedIssueMatcher suppressedIssueMatcher,
SnapshotChangedHandler onSnapshotChanged,
ILocalHotspotsStoreUpdater localHotspotsStore)
: this(textDocument, projectName, projectGuid, suppressedIssueMatcher, onSnapshotChanged, localHotspotsStore, DoTranslateSpans)
: this(textDocument, projectName, projectGuid, onSnapshotChanged, localHotspotsStore, DoTranslateSpans)
{
}

internal /* for testing */ IssueHandler(
ITextDocument textDocument,
string projectName,
Guid projectGuid,
ISuppressedIssueMatcher suppressedIssueMatcher,
SnapshotChangedHandler onSnapshotChanged,
ILocalHotspotsStoreUpdater localHotspotsStore,
TranslateSpans translateSpans)
{
this.textDocument = textDocument;
this.projectName = projectName;
this.projectGuid = projectGuid;
this.suppressedIssueMatcher = suppressedIssueMatcher;
this.onSnapshotChanged = onSnapshotChanged;
this.localHotspotsStore = localHotspotsStore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using System.Windows.Forms;
using System.Windows.Input;
using Microsoft.VisualStudio.Shell;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Tagging;
using SonarLint.VisualStudio.CFamily.Analysis;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Analysis;
using SonarLint.VisualStudio.Integration.Vsix.ErrorList;
Expand Down
22 changes: 6 additions & 16 deletions src/Integration/Transition/MuteIssuesWindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,23 @@
using System.Windows;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Binding;
using SonarLint.VisualStudio.Core.Configuration;
using SonarLint.VisualStudio.Core.Transition;
using SonarQube.Client.Models;

namespace SonarLint.VisualStudio.Integration.Transition
{
[Export(typeof(IMuteIssuesWindowService))]
[PartCreationPolicy(CreationPolicy.Shared)]
internal class MuteIssuesWindowService : IMuteIssuesWindowService
[method: ImportingConstructor]
internal class MuteIssuesWindowService(IActiveSolutionBoundTracker activeSolutionBoundTracker, IBrowserService browserService) : IMuteIssuesWindowService
{
private readonly IConnectedModeFeaturesConfiguration connectedModeFeaturesConfiguration;
private readonly IActiveSolutionBoundTracker activeSolutionBoundTracker;
private readonly IBrowserService browserService;

[ImportingConstructor]
public MuteIssuesWindowService(IConnectedModeFeaturesConfiguration connectedModeFeaturesConfiguration, IActiveSolutionBoundTracker activeSolutionBoundTracker, IBrowserService browserService)
{
this.connectedModeFeaturesConfiguration = connectedModeFeaturesConfiguration;
this.activeSolutionBoundTracker = activeSolutionBoundTracker;
this.browserService = browserService;
}

[ExcludeFromCodeCoverage]
public MuteIssuesWindowResponse Show(IEnumerable<SonarQubeIssueTransition> allowedTransitions)
{
var dialog = new MuteWindowDialog(activeSolutionBoundTracker, browserService, allowedTransitions);
dialog.Owner = Application.Current.MainWindow;
var dialog = new MuteWindowDialog(activeSolutionBoundTracker, browserService, allowedTransitions)
{
Owner = Application.Current.MainWindow
};
var dialogResult = dialog.ShowDialog();

return new MuteIssuesWindowResponse
Expand Down