Skip to content

Commit b63ea7b

Browse files
committed
[release] notify use to restart VS if RLS has been updated.
1 parent 3f0124d commit b63ea7b

File tree

7 files changed

+71
-11
lines changed

7 files changed

+71
-11
lines changed

src/RustAnalyzer.UnitTests/RAExeReleaseTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public sealed class RAExeReleaseTests
1212
[Fact]
1313
public async Task LastUpdateShouldNotBeOlderThan30DaysAsync()
1414
{
15-
var ret = await RAInstallerService.GetLatestRAReleaseRedirectUriAsync();
15+
var ret = await RlsInstallerService.GetLatestRAReleaseRedirectUriAsync();
1616

17-
var latestRelDate = DateTime.ParseExact(ret?.Version, RAInstallerService.RAVersionFormat, CultureInfo.InvariantCulture);
18-
var lastUpdateDate = DateTime.ParseExact(RAInstallerService.LatestInPackageRAVersion, RAInstallerService.RAVersionFormat, CultureInfo.InvariantCulture);
17+
var latestRelDate = DateTime.ParseExact(ret?.Version, RlsInstallerService.RAVersionFormat, CultureInfo.InvariantCulture);
18+
var lastUpdateDate = DateTime.ParseExact(RlsInstallerService.LatestInPackageRAVersion, RlsInstallerService.RAVersionFormat, CultureInfo.InvariantCulture);
1919
lastUpdateDate.Should().NotBeBefore(latestRelDate.AddDays(-120), $"new rust-analyzer.exe is available {ret?.Uri}");
2020
}
2121
}

src/RustAnalyzer/Editor/BuildFileContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public async Task<bool> ExecuteBuildAsync(IBuildActionProgress progress, Cancell
4949
OutputSink = _outputPane,
5050
};
5151

52+
await RlsUpdatedNotification.ShowAsync();
5253
return await _commandFunc(BuildTargetInfo, bos, cancellationToken);
5354
}
5455
}

src/RustAnalyzer/Infrastructure/RAInstallerService.cs renamed to src/RustAnalyzer/Infrastructure/RlsInstallerService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414

1515
namespace KS.RustAnalyzer.Infrastructure;
1616

17-
public interface IRAInstallerService
17+
public interface IRlsInstallerService
1818
{
1919
Task<PathEx> GetRustAnalyzerExePathAsync();
2020

2121
Task InstallLatestRAAsync();
2222
}
2323

24-
[Export(typeof(IRAInstallerService))]
24+
[Export(typeof(IRlsInstallerService))]
2525
[PartCreationPolicy(CreationPolicy.Shared)]
26-
public class RAInstallerService : IRAInstallerService
26+
public class RlsInstallerService : IRlsInstallerService
2727
{
2828
public const string LatestInPackageRAVersion = "2024-01-08";
2929
public const string RAVersionFormat = "yyyy-MM-dd";
@@ -32,7 +32,7 @@ public class RAInstallerService : IRAInstallerService
3232
private readonly TL _tl;
3333

3434
[ImportingConstructor]
35-
public RAInstallerService(IRegistrySettingsService regSettings, [Import] ITelemetryService t, [Import] ILogger l)
35+
public RlsInstallerService(IRegistrySettingsService regSettings, [Import] ITelemetryService t, [Import] ILogger l)
3636
{
3737
_regSettings = regSettings;
3838
_tl = new TL
@@ -124,6 +124,7 @@ private async Task CommitAsync((Uri Uri, string Version)? latestRel)
124124
}
125125

126126
Registry.SetValue(regRoot, InstalledRAVersionKey, latestRel?.Version);
127+
RlsUpdatedNotification.Enabled = true;
127128
_tl.L.WriteLine($"Committed RA installation.");
128129
}
129130

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using KS.RustAnalyzer;
4+
using KS.RustAnalyzer.TestAdapter.Common;
5+
using Microsoft.VisualStudio.Imaging;
6+
using Microsoft.VisualStudio.Shell;
7+
using Microsoft.VisualStudio.Shell.Interop;
8+
using CommunityVS = Community.VisualStudio.Toolkit.VS;
9+
10+
public static class RlsUpdatedNotification
11+
{
12+
public const string RLSUPDATEDENVVARNAME = "RA.VS_RLS_UPDATED";
13+
14+
private static int _counter = 0;
15+
16+
public static bool Enabled
17+
{
18+
private get
19+
{
20+
return Environment.GetEnvironmentVariable(RLSUPDATEDENVVARNAME, EnvironmentVariableTarget.Process).IsNullOrEmpty();
21+
}
22+
23+
set
24+
{
25+
Environment.SetEnvironmentVariable(RLSUPDATEDENVVARNAME, true.ToString(), EnvironmentVariableTarget.Process);
26+
}
27+
}
28+
29+
public static async Task ShowAsync()
30+
{
31+
if (Enabled)
32+
{
33+
return;
34+
}
35+
36+
if (IsTimeToShowAgain())
37+
{
38+
return;
39+
}
40+
41+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
42+
43+
var model = new InfoBarModel(
44+
textSpans: new[] { new InfoBarTextSpan($"{Vsix.Name}: Rust Langugage Server was updated in the background. Restart VS to start using the new version. Using the old version may lead to degraded editor experience."), },
45+
Array.Empty<IVsInfoBarActionItem>(),
46+
image: KnownMonikers.StatusWarning,
47+
isCloseButtonVisible: true);
48+
var infoBar = await CommunityVS.InfoBar.CreateAsync(model);
49+
await infoBar.TryShowInfoBarUIAsync();
50+
}
51+
52+
private static bool IsTimeToShowAgain()
53+
{
54+
return _counter++ % 10 != 0;
55+
}
56+
}

src/RustAnalyzer/LanguageService/LanguageClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class LanguageClient : ILanguageClient, ILanguageClientCustomMessage2
3737
public ITelemetryService T { get; set; }
3838

3939
[Import]
40-
public IRAInstallerService RADownloader { get; set; }
40+
public IRlsInstallerService RADownloader { get; set; }
4141

4242
public JsonRpc Rpc { get; set; }
4343

src/RustAnalyzer/RustAnalyzer.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
<WarningLevel>4</WarningLevel>
4646
</PropertyGroup>
4747
<ItemGroup>
48-
<Compile Include="Infrastructure\RAInstallerService.cs" />
48+
<Compile Include="Infrastructure\RlsInstallerService.cs" />
49+
<Compile Include="Infrastructure\RlsUpdatedNotification.cs" />
4950
<Compile Include="Infrastructure\RegistrySettingsService.cs" />
5051
<Compile Include="Infrastructure\SettingsInfo.cs" />
5152
<Compile Include="LanguageService\CommentHelper.cs" />

src/RustAnalyzer/RustAnalyzerPackage.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public sealed class RustAnalyzerPackage : ToolkitPackage
3636
private TL _tl;
3737
private IRegistrySettingsService _regSettings;
3838
private IPreReqsCheckService _preReqs;
39-
private IRAInstallerService _raDownloader;
39+
private IRlsInstallerService _raDownloader;
4040

4141
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
4242
{
@@ -52,7 +52,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
5252
};
5353
_regSettings = cmServiceProvider?.GetService<IRegistrySettingsService>();
5454
_preReqs = cmServiceProvider?.GetService<IPreReqsCheckService>();
55-
_raDownloader = cmServiceProvider?.GetService<IRAInstallerService>();
55+
_raDownloader = cmServiceProvider?.GetService<IRlsInstallerService>();
5656
}
5757

5858
protected override async Task OnAfterPackageLoadedAsync(CancellationToken cancellationToken)
@@ -65,6 +65,7 @@ protected override async Task OnAfterPackageLoadedAsync(CancellationToken cancel
6565
await SearchAndDisableIncompatibleExtensionsAsync();
6666
await _preReqs.SatisfyAsync();
6767
await _raDownloader.InstallLatestRAAsync();
68+
await RlsUpdatedNotification.ShowAsync();
6869
}
6970

7071
#region Handling incompatible extensions

0 commit comments

Comments
 (0)