Skip to content

Commit 119ce13

Browse files
More fixes before release
1 parent ec30963 commit 119ce13

17 files changed

Lines changed: 110 additions & 36 deletions

src/RustAnalyzer.TestAdapter.UnitTests/Cargo/ToolChainServiceExtensionsTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace KS.RustAnalyzer.TestAdapter.UnitTests.Cargo;
22

3+
using System;
4+
using System.Collections.Concurrent;
5+
using System.Collections.Generic;
36
using System.IO;
47
using System.Linq;
58
using System.Threading.Tasks;
@@ -60,4 +63,50 @@ public async Task TestGetTargetsAsync()
6063
.Should()
6164
.ContainInOrder(ToolchainServiceExtensions.CommonTargets.OrderBy(x => x));
6265
}
66+
67+
[Theory]
68+
[InlineData("/c echo success & echo error>&2", null, "success |finished", "error", true)]
69+
[InlineData("/c exit /b 1", null, "finished", null, false)]
70+
[InlineData("/c echo %cd% >&2", "WINDIR", "finished", null, true)]
71+
public async Task TestRunAsync(string args, string cwd, string eMessage, string eError, bool eRes)
72+
{
73+
var por = new TestPOR();
74+
var ret = await "cmd.exe".ToPath().RunAsync(args, (cwd ?? "USERPROFILE").GetEnvironmentValue().ToPath(), por, "finished", "cancelled", default);
75+
76+
ret.Should().Be(eRes);
77+
por.Messages.Should().ContainInConsecutiveOrder(eMessage.Split('|'));
78+
var cwdErr = cwd == null ? null : new[] { $"{cwd.GetEnvironmentValue()} " };
79+
por.Errors.Should().ContainInConsecutiveOrder(eError?.Split('|') ?? cwdErr ?? Array.Empty<string>());
80+
}
81+
82+
public sealed class TestPOR : ProcessOutputRedirector
83+
{
84+
private readonly ConcurrentQueue<string> _messages = new();
85+
86+
private readonly ConcurrentQueue<string> _errors = new();
87+
88+
public IEnumerable<string> Messages => _messages;
89+
90+
public IEnumerable<string> Errors => _errors;
91+
92+
public override void WriteErrorLine(string line)
93+
{
94+
_errors.Enqueue(line);
95+
}
96+
97+
public override void WriteErrorLineWithoutProcessing(string line)
98+
{
99+
_errors.Enqueue(line);
100+
}
101+
102+
public override void WriteLine(string line)
103+
{
104+
_messages.Enqueue(line);
105+
}
106+
107+
public override void WriteLineWithoutProcessing(string line)
108+
{
109+
_messages.Enqueue(line);
110+
}
111+
}
63112
}

src/RustAnalyzer.TestAdapter/Cargo/ToolChainService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public Task<bool> CleanAsync(BuildTargetInfo bti, BuildOutputSinks bos, Cancella
7979
profile: bti.Profile,
8080
outputPane: bos.OutputSink,
8181
buildMessageReporter: bos.BuildActionProgressReporter,
82-
outputPreprocessor: x => new[] { new StringBuildMessage { Message = x } },
82+
outputPreprocessor: OutputPreprocessorForCargoToolsWithoutJsonOutput,
8383
ts: _tl.T,
8484
l: _tl.L,
8585
ct: ct);
@@ -94,7 +94,7 @@ public Task<bool> RunClippyAsync(BuildTargetInfo bti, BuildOutputSinks bos, Canc
9494
profile: bti.Profile,
9595
outputPane: bos.OutputSink,
9696
buildMessageReporter: bos.BuildActionProgressReporter,
97-
outputPreprocessor: x => new[] { new StringBuildMessage { Message = x } },
97+
outputPreprocessor: OutputPreprocessorForCargoToolsWithoutJsonOutput,
9898
ts: _tl.T,
9999
l: _tl.L,
100100
ct: ct);
@@ -109,7 +109,7 @@ public Task<bool> RunFmtAsync(BuildTargetInfo bti, BuildOutputSinks bos, Cancell
109109
profile: bti.Profile,
110110
outputPane: bos.OutputSink,
111111
buildMessageReporter: bos.BuildActionProgressReporter,
112-
outputPreprocessor: x => new[] { new StringBuildMessage { Message = x } },
112+
outputPreprocessor: OutputPreprocessorForCargoToolsWithoutJsonOutput,
113113
ts: _tl.T,
114114
l: _tl.L,
115115
ct: ct);
@@ -200,6 +200,8 @@ public async Task<IEnumerable<Task<TestSuiteInfo>>> GetTestSuiteInfoAsync(PathEx
200200
}
201201
}
202202

203+
private BuildMessage[] OutputPreprocessorForCargoToolsWithoutJsonOutput(string msg) => new[] { new StringBuildMessage { Message = msg } };
204+
203205
private async Task<TestSuiteInfo> GetTestSuiteInfoFromOneTestExeAsync(TestContainer container, PathEx testExePath, CancellationToken ct)
204206
{
205207
var workspaceRoot = container.TargetDir.GetDirectoryName();

src/RustAnalyzer.TestAdapter/Common/EnvironmentExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public static class EnvironmentExtensions
1111
private static readonly char[] NullSep = new[] { '\0' };
1212
private static readonly char[] EqSep = new[] { '=' };
1313

14+
public static string GetEnvironmentValue(this string name) => Environment.GetEnvironmentVariable(name);
15+
1416
public static IDictionary<string, string> OverrideProcessEnvironment(this string @this)
1517
{
1618
return @this.ToNullSeparatedDictionary()

src/RustAnalyzer.TestAdapter/Common/IBuildOutputSink.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Threading.Tasks;
34

45
namespace KS.RustAnalyzer.TestAdapter.Common;
@@ -14,11 +15,13 @@ public abstract class BuildMessage
1415
{
1516
}
1617

18+
[DebuggerDisplay("{Message}")]
1719
public class StringBuildMessage : BuildMessage
1820
{
1921
public string Message { get; set; }
2022
}
2123

24+
[DebuggerDisplay("{Type} {Code} {File}:{LineNumber}{ColumnNumber}: {LogMessage} ({ProjectFile})")]
2225
public class DetailedBuildMessage : BuildMessage
2326
{
2427
public enum Level

src/RustAnalyzer.TestAdapter/Common/PathExExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public static class PathExExtensions
88
{
99
public static readonly string[] LineSeperators = new[] { "\r", "\n", "\r\n" };
1010

11+
public static PathEx ToPath(this string @this) => (PathEx)@this;
12+
1113
public static bool FileExists(this PathEx @this) => File.Exists(@this);
1214

1315
public static void FileDelete(this PathEx @this) => File.Delete(@this);

src/RustAnalyzer.TestAdapter/Common/TelemetryService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public class DefaultPropertiesTelemetryInitializer : ITelemetryInitializer
7171

7272
public void Initialize(ITelemetry telemetry)
7373
{
74+
new[]
75+
{
76+
Constants.RAVsVersion,
77+
"VisualStudioEdition",
78+
}.ForEach(x => telemetry.Context.GlobalProperties.Add(x, Environment.GetEnvironmentVariable(x)));
7479
telemetry.Context.Component.Version = Vsix.Version;
7580
telemetry.Context.User.Id = Environment.ExpandEnvironmentVariables("%USERNAME%@%COMPUTERNAME%.%USERDOMAIN%");
7681
telemetry.Context.Session.Id = SessionId;

src/RustAnalyzer.TestAdapter/Constants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace KS.RustAnalyzer.TestAdapter;
55

66
public static class Constants
77
{
8-
public const string ReleaseSummary = $"Bunch of usability fixes for Rust Integration tests experience. Please report any issues you face. Consider giving 5⭐ if you find this extension useful.";
8+
public const string ReleaseSummary = "Toolchain install / switch & other utilities under Tools > Rust Tools + Rust Toolbar + Build / clean entire workspace + Bug fixes. Please report any issues you face. Consider giving 5⭐ if you find this extension useful.";
99
public const string ReleaseNotesUrl = $"https://github.com/kitamstudios/rust-analyzer.vs/releases/{Vsix.Version}";
1010
public const string DiscordUrl = "https://discord.gg/JyK55EsACr";
1111
public const string TestExperienceDemoUrl = "https://youtu.be/pE1Vr2zVCbg?t=170";
@@ -23,6 +23,7 @@ public static class Constants
2323
public const string CargoExe = "cargo.exe";
2424

2525
public const string ConfigurationSectionName = "rust-analyzer.vs";
26+
public const string RAVsVersion = "RAVsVersion";
2627

2728
public const string ExecutorUriString = "executor://RustTestExecutor/v1";
2829

src/RustAnalyzer/Infrastructure/BuildOutputSink.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public void WriteLine(PathEx rootPath, Func<BuildMessage, Task> buildOutputTaskR
3131
{
3232
await RustAnalyzerPackage.JTF.SwitchToMainThreadAsync();
3333
Initialize();
34+
_buildOutputPane.Activate();
3435

3536
if (message is StringBuildMessage sm)
3637
{
@@ -39,7 +40,6 @@ public void WriteLine(PathEx rootPath, Func<BuildMessage, Task> buildOutputTaskR
3940
return;
4041
}
4142

42-
_buildOutputPane.Activate();
4343
foreach (var msg in SbmPreprocessor.Preprocess(rootPath, sm.Message))
4444
{
4545
var hr = _buildOutputPane.OutputStringThreadSafe(msg + Environment.NewLine);
@@ -83,10 +83,12 @@ private void Initialize()
8383
{
8484
ThreadHelper.ThrowIfNotOnUIThread();
8585

86-
if (!IsInitialized())
86+
if (IsInitialized())
8787
{
88-
_buildOutputPane = InitializeOutputPane("Rust (cargo)", BuildOutputPaneGuid);
88+
return;
8989
}
90+
91+
_buildOutputPane = InitializeOutputPane(Vsix.Name, BuildOutputPaneGuid);
9092
}
9193

9294
private IVsOutputWindowPane InitializeOutputPane(string title, Guid paneId)

src/RustAnalyzer/RustAnalyzerPackage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public static JoinableTaskFactory JTF
4848

4949
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
5050
{
51+
Environment.SetEnvironmentVariable(Constants.RAVsVersion, (await CommunityVS.Shell.GetVsVersionAsync()).ToString(), EnvironmentVariableTarget.Process);
5152
JTF = JoinableTaskFactory;
5253

5354
await this.RegisterCommandsAsync();

src/RustAnalyzer/Shell/CmdServices.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
5+
using AutoMapper;
56
using KS.RustAnalyzer.Infrastructure;
67
using KS.RustAnalyzer.TestAdapter.Common;
78
using Microsoft.VisualStudio;
89
using Microsoft.VisualStudio.ComponentModelHost;
910
using Microsoft.VisualStudio.Shell;
11+
using Microsoft.VisualStudio.Workspace;
12+
using Microsoft.VisualStudio.Workspace.VSIntegration.Contracts;
1013
using ShellInterop = Microsoft.VisualStudio.Shell.Interop;
14+
using WorkspaceBuildMessage = Microsoft.VisualStudio.Workspace.Build.BuildMessage;
1115

1216
namespace KS.RustAnalyzer.Shell;
1317

@@ -21,8 +25,9 @@ public sealed class CmdServices
2125
private ShellInterop.IVsSolution _solution;
2226
private ShellInterop.IVsDebugger _debugger;
2327
private ShellInterop.IVsUIShell _vsUIShell;
24-
private IToolchainService _toolChainService;
28+
private IToolchainService _toolchainService;
2529
private IBuildOutputSink _buildOutputSink;
30+
private IVsFolderWorkspaceService _folderWorkspaceService;
2631

2732
public CmdServices(Func<AsyncPackage> getPackage)
2833
{
@@ -45,21 +50,27 @@ public CmdServices(Func<AsyncPackage> getPackage)
4550

4651
private ShellInterop.IVsDebugger Debugger => _debugger ??= GetPackage().GetService<ShellInterop.SVsShellDebugger, ShellInterop.IVsDebugger>(false);
4752

48-
private IToolchainService ToolChainService => _toolChainService ??= Mef?.GetService<IToolchainService>();
53+
private IToolchainService ToolchainService => _toolchainService ??= Mef?.GetService<IToolchainService>();
54+
55+
private IVsFolderWorkspaceService FolderWorkspaceService => _folderWorkspaceService ??= Mef?.GetService<IVsFolderWorkspaceService>();
56+
57+
private readonly IMapper _buildMessageMapper = new MapperConfiguration(cfg => cfg.CreateMap<DetailedBuildMessage, WorkspaceBuildMessage>()).CreateMapper();
4958

5059
public async Task ExecuteToolchainOperationAsync(ToolchainOperation op, PathEx manifestPath, Func<Options, string> getOpts)
5160
{
5261
var profile = Mef.GetProfile(manifestPath);
5362
var opts = await Options.GetLiveInstanceAsync();
54-
await op(ToolChainService)(
63+
64+
var bms = await FolderWorkspaceService.CurrentWorkspace.GetBuildMessageServiceAsync();
65+
await op(ToolchainService)(
5566
new BuildTargetInfo
5667
{
5768
ManifestPath = manifestPath,
5869
AdditionalBuildArgs = getOpts(opts),
5970
Profile = profile,
6071
WorkspaceRoot = manifestPath.GetDirectoryName(),
6172
},
62-
new BuildOutputSinks { OutputSink = BuildOutputSink, BuildActionProgressReporter = bm => Task.CompletedTask },
73+
new BuildOutputSinks { OutputSink = BuildOutputSink, BuildActionProgressReporter = bm => bms.ReportBuildMessages(new[] { _buildMessageMapper.Map<WorkspaceBuildMessage>(bm) }) },
6374
default);
6475
}
6576

0 commit comments

Comments
 (0)