Skip to content

Commit

Permalink
Prevent some notification from closing on solution close
Browse files Browse the repository at this point in the history
Some notifications are session scoped rather than solution scoped.
  • Loading branch information
vnaskos-sonar committed Oct 28, 2024
1 parent 92c4485 commit 1b1701c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void Show_GeneratesCorrectNotificationStructure()
notificationActions[1].CommandText.Should().Be(BindingStrings.SharedBindingSuggestionInfoOptionText);
notificationActions[1].ShouldDismissAfterAction.Should().BeFalse();
notificationActions[2].Should().BeSameAs(doNotShowAgainMock.Object);
notification.CloseOnSolutionClose.Should().Be(false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ public void Show(ServerType serverType, Action onConnectHandler)
var notification = new Notification(
id: string.Format(IdTemplate, solutionInfoProvider.GetSolutionName()),
message: string.Format(BindingStrings.SharedBindingSuggestionMainText, serverType),
actions: new INotificationAction[]
{
actions:
[
new NotificationAction(BindingStrings.SharedBindingSuggestionConnectOptionText, _ => onConnectHandler(), true),
new NotificationAction(BindingStrings.SharedBindingSuggestionInfoOptionText, _ => OnLearnMore(), false),
doNotShowAgainNotificationAction
});
],
// Prevent INotificationService from handling the on solution change events
// as this is exceptionally overriden by the SharedBindingSuggestionService
closeOnSolutionClose: false);

notificationService.ShowNotification(notification);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ public void ActiveSolutionChanged_SolutionIsOpened_ShowsGoldBarAndShowManageBind
showAction.Should().NotBeNull();
connectedModeManager.Received(1).ShowManageBindingDialog(true);
}

[TestMethod]
public void ActiveSolutionChanged_SolutionIsClosed_ClosesNotification()
{
RaiseActiveSolutionChanged(false);

suggestSharedBindingGoldBar.Received().Close();
}

private void RaiseActiveSolutionChanged(bool isSolutionOpened)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Integration/MefServices/SharedBindingSuggestionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
*/

using System.ComponentModel.Composition;
using System.Windows;
using SonarLint.VisualStudio.ConnectedMode.Binding.Suggestion;
using SonarLint.VisualStudio.ConnectedMode.Shared;
using SonarLint.VisualStudio.ConnectedMode.UI;
using SonarLint.VisualStudio.ConnectedMode.UI.ManageBinding;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Binding;

Expand Down Expand Up @@ -88,6 +86,10 @@ private void OnActiveSolutionChanged(object sender, ActiveSolutionChangedEventAr
{
Suggest();
}
else
{
suggestSharedBindingGoldBar.Close();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Notifications;
using SonarLint.VisualStudio.SLCore.NodeJS.Notifications;
using Language = SonarLint.VisualStudio.SLCore.Common.Models.Language;

namespace SonarLint.VisualStudio.SLCore.UnitTests.NodeJS.Notifications
{
Expand All @@ -37,11 +38,11 @@ public void MefCtor_CheckIsExported()
}

[DataTestMethod]
[DataRow(SLCore.Common.Models.Language.JS, "321", "123", "123")]
[DataRow(SLCore.Common.Models.Language.CSS, "99.00.11", "9876.5432", "9876.5432")]
[DataRow(SLCore.Common.Models.Language.JS, "321", null, "Not found")]
[DataRow(SLCore.Common.Models.Language.TS, "5.4.3.2.1", null, "Not found")]
public void Show_ShowsCorrectMessageAndNotificationId(SLCore.Common.Models.Language language, string expectedVersion, string actualVersion, string displayActualVersion)
[DataRow(Language.JS, "321", "123", "123")]
[DataRow(Language.CSS, "99.00.11", "9876.5432", "9876.5432")]
[DataRow(Language.JS, "321", null, "Not found")]
[DataRow(Language.TS, "5.4.3.2.1", null, "Not found")]
public void Show_ShowsCorrectMessageAndNotificationId(Language language, string expectedVersion, string actualVersion, string displayActualVersion)
{
INotification createdNotification = null;
var notificationService = CreateNotificationService(n => createdNotification = n);
Expand All @@ -60,6 +61,7 @@ public void Show_ShowsCorrectMessageAndNotificationId(SLCore.Common.Models.Langu
createdNotification.Id.Should().Be("sonarlint.nodejs.min.version.not.found");
createdNotification.Message.Should().Be($"SonarLint: {language} analysis failed. Could not find a Node.js runtime (required: >={expectedVersion}, actual: {displayActualVersion}) on your computer.");
createdNotification.Actions.Count().Should().Be(2);
createdNotification.CloseOnSolutionClose.Should().Be(false);
}

[TestMethod]
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.Linq;
using SonarLint.VisualStudio.Core.Notifications;
using SonarLint.VisualStudio.SLCore.Notification;

Expand Down Expand Up @@ -59,6 +58,7 @@ public void Show_CreatesNotificationAndCallsShow()
notification.Id.Should().Be("sonarlint.sloop.restart.failed");
notification.Message.Should().Be("SonarLint background service failed to start");
notification.Actions.Should().HaveCount(1);
notification.CloseOnSolutionClose.Should().Be(false);

notification.Actions.First().Action(notification);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ public void Show(string languageName, string minVersion, string currentVersion =
notificationService.ShowNotification(new VisualStudio.Core.Notifications.Notification(
id: NotificationId,
message: string.Format(NotificationStrings.NotificationUnsupportedNode, languageName, minVersion, currentVersion ?? NotificationStrings.NotificationNoneVersion),
actions: new INotificationAction[]
{
actions:
[
new NotificationAction(NotificationStrings.NotificationShowMoreInfoAction, _ => ShowMoreInfo(), false),
doNotShowAgainNotificationAction
}));
],
closeOnSolutionClose: false)
);
}

private void ShowMoreInfo()
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.ComponentModel.Composition;
using SonarLint.VisualStudio.Core.Notifications;

Expand Down Expand Up @@ -52,7 +51,8 @@ public void Show(Action act)
{
new NotificationAction(SLCoreStrings.SloopRestartFailedNotificationService_Restart, _ => act(), true)
},
showOncePerSession: false
showOncePerSession: false,
closeOnSolutionClose: false
);

notificationService.ShowNotification(notification);
Expand Down

0 comments on commit 1b1701c

Please sign in to comment.