Skip to content

Commit b540e23

Browse files
Self-review fixes
1 parent af0d2ee commit b540e23

11 files changed

Lines changed: 49 additions & 47 deletions

File tree

src/DebugEngineHost.Common/HostLogChannel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ public interface ILogChannel
5050

5151
public class HostLogChannel : ILogChannel
5252
{
53-
private readonly Action<string> _log;
53+
private readonly Action<string>? _log;
5454
private StreamWriter? _logFile;
5555
private LogLevel _minLevelToBeLogged;
5656

5757
private readonly object _lock = new object();
5858

59-
private HostLogChannel() { _log = null!; }
59+
private HostLogChannel() { }
6060

61-
public HostLogChannel(Action<string> logAction, string? file, LogLevel logLevel)
61+
public HostLogChannel(Action<string>? logAction, string? file, LogLevel logLevel)
6262
{
6363
_log = logAction;
6464

src/DebugEngineHost.Stub/DebugEngineHost.ref.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public static class HostLogger
259259
/// </summary>
260260
/// <param name="callback">The callback to use to send the engine log.</param>
261261
/// <param name="level">The level of the log to filter the channel on.</param>
262-
public static void EnableHostLogging(Action<string> callback, LogLevel level = LogLevel.Verbose)
262+
public static void EnableHostLogging(Action<string>? callback, LogLevel level = LogLevel.Verbose)
263263
{
264264
throw new NotImplementedException();
265265
}
@@ -527,7 +527,7 @@ public static bool IsRunInTerminalAvailable()
527527
/// <returns>true if the message is sent, false if not.</returns>
528528
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "cwd")]
529529
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
530-
public static void RunInTerminal(string title, string workingDirectory, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string> environmentVariables, Action<int?> success, Action<string> failure)
530+
public static void RunInTerminal(string title, string workingDirectory, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string?> environmentVariables, Action<int?> success, Action<string> failure)
531531
{
532532
throw new NotImplementedException();
533533
}

src/DebugEngineHost.VSCode/HostLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void EnableNatvisDiagnostics(Action<string> callback, LogLevel lev
2121
}
2222
}
2323

24-
public static void EnableHostLogging(Action<string> callback, LogLevel level = LogLevel.Verbose)
24+
public static void EnableHostLogging(Action<string>? callback, LogLevel level = LogLevel.Verbose)
2525
{
2626
if (s_engineLogChannel is null)
2727
{

src/DebugEngineHost.VSCode/HostRunInTerminal.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.DebugEngineHost
99
{
1010
public static class HostRunInTerminal
1111
{
12-
private static Action<string, string, bool, List<string>, Dictionary<string, object>, Action<int?>, Action<string>>? s_runInTerminalCallback;
12+
private static Action<string, string, bool, List<string>, Dictionary<string, object?>, Action<int?>, Action<string>>? s_runInTerminalCallback;
1313

1414
/// <summary>
1515
/// Checks to see if RunInTerminal is available
@@ -23,11 +23,11 @@ public static bool IsRunInTerminalAvailable()
2323
/// <summary>
2424
/// Passes the call to the UI to attempt to RunInTerminal if possible.
2525
/// </summary>
26-
public static void RunInTerminal(string title, string cwd, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string> environmentVars, Action<int?> success, Action<string> failure)
26+
public static void RunInTerminal(string title, string cwd, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string?> environmentVars, Action<int?> success, Action<string> failure)
2727
{
2828
if (s_runInTerminalCallback is not null)
2929
{
30-
Dictionary<string, object> env = new Dictionary<string, object>();
30+
Dictionary<string, object?> env = new Dictionary<string, object?>();
3131
foreach (var item in environmentVars)
3232
{
3333
env.Add(item.Key, item.Value);
@@ -41,7 +41,7 @@ public static void RunInTerminal(string title, string cwd, bool useExternalConso
4141
/// Registers callback to call when RunInTerminal is called
4242
/// </summary>
4343
/// <param name="runInTerminalCallback">Callback for RunInTerminal</param>
44-
public static void RegisterRunInTerminalCallback(Action<string, string, bool, List<string>, Dictionary<string, object>, Action<int?>, Action<string>> runInTerminalCallback)
44+
public static void RegisterRunInTerminalCallback(Action<string, string, bool, List<string>, Dictionary<string, object?>, Action<int?>, Action<string>> runInTerminalCallback)
4545
{
4646
Debug.Assert(runInTerminalCallback != null, "Callback should not be null.");
4747
s_runInTerminalCallback = runInTerminalCallback;

src/DebugEngineHost/HostLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class HostLogger
1919
private static FeedbackLogBuffer? s_circularBuffer;
2020
private static VSFeedbackLogger? s_feedbackLogger;
2121

22-
public static void EnableHostLogging(Action<string> callback, LogLevel level = LogLevel.Verbose)
22+
public static void EnableHostLogging(Action<string>? callback, LogLevel level = LogLevel.Verbose)
2323
{
2424
if (s_engineLogChannel is null)
2525
{

src/DebugEngineHost/HostRunInTerminal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static bool IsRunInTerminalAvailable()
2222

2323
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "cwd")]
2424
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
25-
public static void RunInTerminal(string title, string workingDirectory, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string> environmentVariables, Action<int?> success, Action<string> failure)
25+
public static void RunInTerminal(string title, string workingDirectory, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string?> environmentVariables, Action<int?> success, Action<string> failure)
2626
{
2727
throw new NotImplementedException();
2828
}

src/MICore/JsonLaunchOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Globalization;
7-
using System.Runtime.CompilerServices;
87
using System.Runtime.Serialization;
98
using Newtonsoft.Json;
109
using Newtonsoft.Json.Converters;

src/MICore/LaunchOptions.cs

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,14 @@ public EnvironmentEntry(Xml.LaunchOptions.EnvironmentEntry xmlEntry)
300300

301301
public EnvironmentEntry(Json.LaunchOptions.Environment jsonEntry)
302302
{
303-
this.Name = LaunchOptions.RequireAttribute(jsonEntry.Name, nameof(jsonEntry.Name));
304-
this.Value = jsonEntry.Value ?? string.Empty;
303+
this.Name = LaunchOptions.RequireAttribute(jsonEntry.Name, "environment.name");
304+
this.Value = jsonEntry.Value;
305305
}
306306

307307
public EnvironmentEntry(string name, string? value)
308308
{
309309
this.Name = name;
310-
this.Value = value ?? string.Empty;
310+
this.Value = value;
311311
}
312312

313313
/// <summary>
@@ -316,9 +316,9 @@ public EnvironmentEntry(string name, string? value)
316316
public string Name { get; private set; }
317317

318318
/// <summary>
319-
/// [Required] Value of the environment variable
319+
/// Value of the environment variable, or null to delete it
320320
/// </summary>
321-
public string Value { get; private set; }
321+
public string? Value { get; private set; }
322322
}
323323

324324
public sealed class SourceMapEntry
@@ -380,9 +380,14 @@ public static ReadOnlyCollection<SourceMapEntry> CreateCollection(Xml.LaunchOpti
380380

381381
public static ReadOnlyCollection<SourceMapEntry> CreateCollection(Dictionary<string, object>? source)
382382
{
383-
var sourceMaps = new List<SourceMapEntry>(source?.Keys.Count ?? 0);
383+
int count = source?.Keys.Count ?? 0;
384+
if (count == 0)
385+
{
386+
return new ReadOnlyCollection<SourceMapEntry>(Array.Empty<SourceMapEntry>());
387+
}
384388

385-
foreach (var item in source ?? new Dictionary<string, object>())
389+
var sourceMaps = new List<SourceMapEntry>();
390+
foreach (var item in source!)
386391
{
387392
string compileTimePath = item.Key;
388393
string? editorPath = null;
@@ -880,7 +885,7 @@ protected set
880885
private string? _exePath;
881886

882887
/// <summary>
883-
/// [Required] Path to the executable file. This could be a path on the remote machine (for Pipe transport)
888+
/// Path to the executable file. This could be a path on the remote machine (for Pipe transport)
884889
/// or the local machine (Local transport).
885890
/// </summary>
886891
public virtual string? ExePath
@@ -1383,19 +1388,25 @@ public static LaunchOptions GetInstance(HostConfigurationStore? configStore, str
13831388

13841389
// if the customLauncher element is present then try using the custom launcher implementation from the config store
13851390
JToken? customLauncherToken = parsedOptions["customLauncher"];
1386-
if (customLauncherToken is not null && !IsNullOrWhiteSpace(customLauncherToken.Value<string>()))
1391+
if (customLauncherToken is not null && customLauncherToken.Value<string>() is string customLauncherName && !IsNullOrWhiteSpace(customLauncherName))
13871392
{
1388-
string customLauncherName = customLauncherToken.Value<string>() ?? string.Empty;
1389-
var jsonLauncher = configStore?.GetCustomLauncher(customLauncherName);
1393+
if (configStore is null || eventCallback is null)
1394+
{
1395+
throw new InvalidLaunchOptionsException(MICoreResources.Error_UnknownLaunchOptions);
1396+
}
1397+
1398+
var jsonLauncher = configStore.GetCustomLauncher(customLauncherName);
13901399
if (jsonLauncher == null)
13911400
{
13921401
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, MICoreResources.Error_UnknownCustomLauncher, customLauncherName));
13931402
}
1394-
if (jsonLauncher as IPlatformAppLauncher == null)
1403+
1404+
if (jsonLauncher is not IPlatformAppLauncher platformAppLauncher)
13951405
{
13961406
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, MICoreResources.Error_LauncherNotFound, customLauncherName));
13971407
}
1398-
launchOptions = ExecuteLauncher(configStore, (IPlatformAppLauncher)jsonLauncher, exePath, args, dir, parsedOptions, eventCallback, targetEngine, logger);
1408+
1409+
launchOptions = ExecuteLauncher(configStore, platformAppLauncher, exePath, args, dir, parsedOptions, eventCallback, targetEngine, logger);
13991410
}
14001411
else if (parsedOptions["pipeTransport"] is JToken pipeTransportToken && pipeTransportToken.HasValues)
14011412
{
@@ -1508,7 +1519,7 @@ public static LaunchOptions GetInstance(HostConfigurationStore? configStore, str
15081519

15091520
if (clsidLauncher != Guid.Empty)
15101521
{
1511-
if (launcherXmlOptions is null)
1522+
if (launcherXmlOptions is null || configStore is null)
15121523
{
15131524
throw new InvalidLaunchOptionsException(MICoreResources.Error_UnknownLaunchOptions);
15141525
}
@@ -1517,7 +1528,7 @@ public static LaunchOptions GetInstance(HostConfigurationStore? configStore, str
15171528
}
15181529
else if (launcher != null)
15191530
{
1520-
if (launcherXmlOptions is null)
1531+
if (launcherXmlOptions is null || configStore is null || eventCallback is null)
15211532
{
15221533
throw new InvalidLaunchOptionsException(MICoreResources.Error_UnknownLaunchOptions);
15231534
}
@@ -1560,8 +1571,8 @@ public static LaunchOptions CreateForAttachRequest(Microsoft.VisualStudio.Debugg
15601571
Logger logger)
15611572
{
15621573
var suppOptions = GetOptionsFromFile(logger);
1563-
string connection;
1564-
((IDebugPort2)unixPort).GetPortName(out connection!);
1574+
string? connection;
1575+
((IDebugPort2)unixPort).GetPortName(out connection);
15651576
AttachOptionsForConnection? attachOptions = null;
15661577
if (suppOptions != null && suppOptions.AttachOptions != null)
15671578
{
@@ -2175,13 +2186,8 @@ public static int RequirePortAttribute(int attributeValue, string attributeName)
21752186
return attributeValue;
21762187
}
21772188

2178-
private static LaunchOptions ExecuteLauncher(HostConfigurationStore? configStore, Guid clsidLauncher, string exePath, string? args, string? dir, object launcherXmlOptions, IDeviceAppLauncherEventCallback? eventCallback, TargetEngine targetEngine, Logger? logger)
2189+
private static LaunchOptions ExecuteLauncher(HostConfigurationStore configStore, Guid clsidLauncher, string exePath, string? args, string? dir, object launcherXmlOptions, IDeviceAppLauncherEventCallback? eventCallback, TargetEngine targetEngine, Logger? logger)
21792190
{
2180-
if (configStore is null)
2181-
{
2182-
throw new ArgumentNullException(nameof(configStore));
2183-
}
2184-
21852191
var deviceAppLauncher = HostLoader.VsCoCreateManagedObject(configStore, clsidLauncher) as IPlatformAppLauncher;
21862192
if (deviceAppLauncher == null)
21872193
{
@@ -2190,15 +2196,15 @@ private static LaunchOptions ExecuteLauncher(HostConfigurationStore? configStore
21902196
return ExecuteLauncher(configStore, deviceAppLauncher, exePath, args, dir, launcherXmlOptions, eventCallback, targetEngine, logger);
21912197
}
21922198

2193-
private static LaunchOptions ExecuteLauncher(HostConfigurationStore? configStore, IPlatformAppLauncher deviceAppLauncher, string exePath, string? args, string? dir, object launcherOptions, IDeviceAppLauncherEventCallback? eventCallback, TargetEngine targetEngine, Logger? logger)
2199+
private static LaunchOptions ExecuteLauncher(HostConfigurationStore configStore, IPlatformAppLauncher deviceAppLauncher, string exePath, string? args, string? dir, object launcherOptions, IDeviceAppLauncherEventCallback eventCallback, TargetEngine targetEngine, Logger? logger)
21942200
{
21952201
bool success = false;
21962202

21972203
try
21982204
{
21992205
try
22002206
{
2201-
deviceAppLauncher.Initialize(configStore ?? throw new ArgumentNullException(nameof(configStore)), eventCallback ?? throw new ArgumentNullException(nameof(eventCallback)));
2207+
deviceAppLauncher.Initialize(configStore, eventCallback);
22022208
deviceAppLauncher.SetLaunchOptions(exePath, args ?? string.Empty, dir ?? string.Empty, launcherOptions, targetEngine);
22032209
}
22042210
catch (Exception e) when (!(e is InvalidLaunchOptionsException) && ExceptionHelper.BeforeCatch(e, logger, reportOnlyCorrupting: true))

src/MICore/Logger.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ public static void LoadMIDebugLogger()
8484
{ // command configured log file
8585
HostLogger.Reset();
8686
HostLogger.SetEngineLogFile(CmdLogInfo.logFile);
87-
if (CmdLogInfo.logToOutput != null)
88-
{
89-
HostLogger.EnableHostLogging(CmdLogInfo.logToOutput);
90-
}
87+
HostLogger.EnableHostLogging(CmdLogInfo.logToOutput);
9188
}
9289

9390
s_isEnabled = true;

src/MICore/PlatformUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static bool IsLinux()
7373
}
7474

7575
// Abstract API call to add an environment variable to a new process
76-
public static void SetEnvironmentVariable(this ProcessStartInfo processStartInfo, string key, string value)
76+
public static void SetEnvironmentVariable(this ProcessStartInfo processStartInfo, string key, string? value)
7777
{
7878
processStartInfo.Environment[key] = value;
7979
}

0 commit comments

Comments
 (0)