Skip to content

Commit c5ec437

Browse files
committed
Updating latest ra.exe + wiring up RADownloader
1 parent 3b6b7dd commit c5ec437

11 files changed

Lines changed: 61 additions & 27 deletions

File tree

src/RustAnalyzer.TestAdapter/Cargo/ToolChainService.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Diagnostics;
66
using System.IO;
77
using System.Linq;
8-
using System.Reflection;
98
using System.Text;
109
using System.Text.RegularExpressions;
1110
using System.Threading;
@@ -46,12 +45,6 @@ public ToolChainService([Import] ITelemetryService t, [Import] ILogger l)
4645
return cargoExePath;
4746
}
4847

49-
public Task<PathEx> GetRustAnalyzerExePath()
50-
{
51-
var path = (PathEx)Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "rust-analyzer.exe");
52-
return path.ToTask();
53-
}
54-
5548
public async Task<bool> BuildAsync(BuildTargetInfo bti, BuildOutputSinks bos, CancellationToken ct)
5649
{
5750
var success = await ExecuteOperationAsync(

src/RustAnalyzer.TestAdapter/Common/IToolChainService.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public interface IToolChainService
99
{
1010
PathEx? GetCargoExePath();
1111

12-
Task<PathEx> GetRustAnalyzerExePath();
13-
1412
Task<bool> BuildAsync(BuildTargetInfo bti, BuildOutputSinks bos, CancellationToken ct);
1513

1614
Task<bool> CleanAsync(BuildTargetInfo bti, BuildOutputSinks bos, CancellationToken ct);

src/RustAnalyzer.UnitTests/RAExeRelease.cs renamed to src/RustAnalyzer.UnitTests/RAExeReleaseTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77

88
namespace KS.RustAnalyzer.UnitTests;
99

10-
public sealed class RAExeRelease
10+
public sealed class RAExeReleaseTests
1111
{
12-
private const string LastUpdatedRAExeVersion = "2023-12-18";
13-
1412
[Fact]
1513
public async Task LastUpdateShouldNotBeOlderThan30DaysAsync()
1614
{
17-
var ret = await RADownloader.GetLatestRAReleaseRedirectUriAsync();
15+
var ret = await RADownloaderService.GetLatestRAReleaseRedirectUriAsync();
1816

19-
var latestRelDate = DateTime.ParseExact(ret?.Version, RADownloader.RAVersionFormat, CultureInfo.InvariantCulture);
20-
var lastUpdateDate = DateTime.ParseExact(LastUpdatedRAExeVersion, RADownloader.RAVersionFormat, CultureInfo.InvariantCulture);
17+
var latestRelDate = DateTime.ParseExact(ret?.Version, RADownloaderService.RAVersionFormat, CultureInfo.InvariantCulture);
18+
var lastUpdateDate = DateTime.ParseExact(RADownloaderService.LatestInPackageRAVersion, RADownloaderService.RAVersionFormat, CultureInfo.InvariantCulture);
2119
lastUpdateDate.Should().NotBeBefore(latestRelDate.AddDays(-30), $"new rust-analyzer.exe is available https://github.com/rust-lang/rust-analyzer/releases/download/{ret?.Version}/rust-analyzer-x86_64-pc-windows-msvc.zip");
2220
}
2321
}

src/RustAnalyzer.UnitTests/RustAnalyzer.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</Compile>
6868
<Compile Include="Infrastructure\StringBuildMessagePreprocessorTests.cs" />
6969
<Compile Include="Infrastructure\StringExtensionsTests.cs" />
70-
<Compile Include="RAExeRelease.cs" />
70+
<Compile Include="RAExeReleaseTests.cs" />
7171
<Compile Include="Properties\AssemblyInfo.cs" />
7272
<Compile Include="Editor\FileContextProviderTests.cs" />
7373
<Compile Include="Editor\FileScannerTests.cs" />

src/RustAnalyzer/Infrastructure/RADownloader.cs renamed to src/RustAnalyzer/Infrastructure/RADownloaderService.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,55 @@
11
using System;
2+
using System.ComponentModel.Composition;
23
using System.Globalization;
4+
using System.IO;
35
using System.Linq;
46
using System.Net.Http;
7+
using System.Reflection;
58
using System.Threading;
69
using System.Threading.Tasks;
710
using KS.RustAnalyzer.TestAdapter.Common;
811

912
namespace KS.RustAnalyzer.Infrastructure;
1013

11-
public static class RADownloader
14+
public interface IRADownloaderService
1215
{
16+
Task<PathEx> GetRustAnalyzerExePathAsync();
17+
18+
Task DownloadLatestRAAsync();
19+
}
20+
21+
[Export(typeof(IRADownloaderService))]
22+
[PartCreationPolicy(CreationPolicy.Shared)]
23+
public class RADownloaderService : IRADownloaderService
24+
{
25+
public const string LatestInPackageRAVersion = "2024-01-15";
26+
1327
public const string RAVersionFormat = "yyyy-MM-dd";
28+
private readonly IRegistrySettingsService _regSettings;
29+
private readonly TL _tl;
30+
31+
[ImportingConstructor]
32+
public RADownloaderService(IRegistrySettingsService regSettings, [Import] ITelemetryService t, [Import] ILogger l)
33+
{
34+
_regSettings = regSettings;
35+
_tl = new TL
36+
{
37+
T = t,
38+
L = l,
39+
};
40+
}
41+
42+
public Task DownloadLatestRAAsync()
43+
{
44+
_tl.L.WriteLine("Initiating download of RA...");
45+
return Task.CompletedTask;
46+
}
47+
48+
public Task<PathEx> GetRustAnalyzerExePathAsync()
49+
{
50+
var path = (PathEx)Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), $"rust-analyzer.{LatestInPackageRAVersion}.exe");
51+
return path.ToTask();
52+
}
1453

1554
public static async Task<(Uri Uri, string Version)?> GetLatestRAReleaseRedirectUriAsync()
1655
{

src/RustAnalyzer/Infrastructure/RegistrySettingsService.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace KS.RustAnalyzer.Infrastructure;
1212
public interface IRegistrySettingsService
1313
{
1414
public bool InfoBarDismissedByUser { get; set; }
15+
16+
bool GetPackageRegistryRoot(out string packageRegistryRoot);
1517
}
1618

1719
[Export(typeof(IRegistrySettingsService))]
@@ -41,7 +43,7 @@ public bool InfoBarDismissedByUser
4143
{
4244
ThreadHelper.ThrowIfNotOnUIThread();
4345

44-
if (GetPackageRegistryRoot(_serviceProvider, out string regRoot))
46+
if (GetPackageRegistryRoot(out string regRoot))
4547
{
4648
return Registry.GetValue(regRoot, DismissedRegKeyName, null)?.ToString() == Vsix.Version;
4749
}
@@ -53,21 +55,21 @@ public bool InfoBarDismissedByUser
5355
{
5456
ThreadHelper.ThrowIfNotOnUIThread();
5557

56-
if (value && GetPackageRegistryRoot(_serviceProvider, out string regRoot))
58+
if (value && GetPackageRegistryRoot(out string regRoot))
5759
{
5860
Registry.SetValue(regRoot, DismissedRegKeyName, Vsix.Version);
5961
}
6062
}
6163
}
6264

63-
private static bool GetPackageRegistryRoot(IServiceProvider sp, out string packageRegistryRoot)
65+
public bool GetPackageRegistryRoot(out string packageRegistryRoot)
6466
{
6567
ThreadHelper.ThrowIfNotOnUIThread();
6668

6769
packageRegistryRoot = null;
68-
if (sp.GetService(typeof(SLocalRegistry)) is ILocalRegistry2 localReg && ErrorHandler.Succeeded(localReg.GetLocalRegistryRoot(out var localRegRoot)))
70+
if (_serviceProvider.GetService(typeof(SLocalRegistry)) is ILocalRegistry2 localReg && ErrorHandler.Succeeded(localReg.GetLocalRegistryRoot(out var localRegRoot)))
6971
{
70-
packageRegistryRoot = Path.Combine("HKEY_CURRENT_USER", localRegRoot, Vsix.Name);
72+
packageRegistryRoot = Path.Combine(Registry.CurrentUser.Name, localRegRoot, Vsix.Name);
7173
return true;
7274
}
7375

src/RustAnalyzer/LanguageService/LanguageClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using KS.RustAnalyzer.Infrastructure;
89
using KS.RustAnalyzer.TestAdapter;
910
using KS.RustAnalyzer.TestAdapter.Common;
1011
using Microsoft.VisualStudio.LanguageServer.Client;
@@ -36,7 +37,7 @@ public class LanguageClient : ILanguageClient, ILanguageClientCustomMessage2
3637
public ITelemetryService T { get; set; }
3738

3839
[Import]
39-
public IToolChainService ToolChain { get; set; }
40+
public IRADownloaderService RADownloader { get; set; }
4041

4142
public JsonRpc Rpc { get; set; }
4243

@@ -62,7 +63,7 @@ public IEnumerable<string> ConfigurationSections
6263

6364
public async Task<Connection> ActivateAsync(CancellationToken token)
6465
{
65-
var rlsPath = await ToolChain.GetRustAnalyzerExePath();
66+
var rlsPath = await RADownloader.GetRustAnalyzerExePathAsync();
6667
L.WriteLine("Starting rust-analyzer from path: {0}.", rlsPath);
6768
ProcessStartInfo info = new ()
6869
{

src/RustAnalyzer/RustAnalyzer.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<WarningLevel>4</WarningLevel>
4646
</PropertyGroup>
4747
<ItemGroup>
48-
<Compile Include="Infrastructure\RADownloader.cs" />
48+
<Compile Include="Infrastructure\RADownloaderService.cs" />
4949
<Compile Include="Infrastructure\RegistrySettingsService.cs" />
5050
<Compile Include="Infrastructure\SettingsInfo.cs" />
5151
<Compile Include="LanguageService\CommentHelper.cs" />
@@ -95,8 +95,8 @@
9595
</Compile>
9696
</ItemGroup>
9797
<ItemGroup>
98-
<Content Include="..\external\rust-analyzer.exe">
99-
<Link>rust-analyzer.exe</Link>
98+
<Content Include="..\external\rust-analyzer.2024-01-15.exe">
99+
<Link>rust-analyzer.2024-01-15.exe</Link>
100100
<IncludeInVSIX>true</IncludeInVSIX>
101101
</Content>
102102
<Content Include="..\external\rust_analyzer.pdb">

src/RustAnalyzer/RustAnalyzerPackage.cs

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

4041
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
4142
{
@@ -51,6 +52,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
5152
};
5253
_regSettings = cmServiceProvider?.GetService<IRegistrySettingsService>();
5354
_preReqs = cmServiceProvider?.GetService<IPreReqsCheckService>();
55+
_raDownloader = cmServiceProvider?.GetService<IRADownloaderService>();
5456
}
5557

5658
protected override async Task OnAfterPackageLoadedAsync(CancellationToken cancellationToken)
@@ -62,6 +64,7 @@ protected override async Task OnAfterPackageLoadedAsync(CancellationToken cancel
6264
await ReleaseSummaryNotification.ShowAsync(_regSettings, _tl);
6365
await SearchAndDisableIncompatibleExtensionsAsync();
6466
await _preReqs.SatisfyAsync();
67+
await _raDownloader.DownloadLatestRAAsync();
6568
}
6669

6770
#region Handling incompatible extensions

0 commit comments

Comments
 (0)