Skip to content

Commit aa1c253

Browse files
Apply automatic fixes (manually) (#1755)
These were available in code lens style "click to fix" but were not applied by the CLI tools. It was slow, but not horrible. Also silence two annoying suggestions around comments and naming.
1 parent aa221aa commit aa1c253

File tree

102 files changed

+251
-479
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+251
-479
lines changed

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ dotnet_diagnostic.CS4014.severity = suggestion
6565
# RCS1102: Make class static
6666
dotnet_diagnostic.RCS1102.severity = warning
6767
# RCS1139: Add summary element to documentation comment
68-
dotnet_diagnostic.RCS1139.severity = suggestion
68+
dotnet_diagnostic.RCS1139.severity = silent
6969
# RCS1194: Implement exception constructors
7070
dotnet_diagnostic.RCS1194.severity = suggestion
7171
# RCS1210: Return completed task instead of returning null
@@ -92,7 +92,7 @@ dotnet_diagnostic.VSTHRD110.severity = suggestion
9292
# VSTHRD114: Avoid returning a null Task
9393
dotnet_diagnostic.VSTHRD114.severity = suggestion
9494
# VSTHRD200: Use "Async" suffix for awaitable methods
95-
dotnet_diagnostic.VSTHRD200.severity = suggestion
95+
dotnet_diagnostic.VSTHRD200.severity = silent
9696

9797
# xUnit2013: Do not use equality check to check for collection size
9898
dotnet_diagnostic.xUnit2013.severity = warning

PowerShellEditorServices.build.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ task CreateBuildInfo {
128128
[string]$buildTime = [datetime]::Today.ToString("s", [System.Globalization.CultureInfo]::InvariantCulture)
129129

130130
$buildInfoContents = @"
131+
// Copyright (c) Microsoft Corporation.
132+
// Licensed under the MIT License.
133+
131134
using System.Globalization;
132135
133136
namespace Microsoft.PowerShell.EditorServices.Hosting

src/PowerShellEditorServices.Hosting/BuildInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
14
using System.Globalization;
25

36
namespace Microsoft.PowerShell.EditorServices.Hosting

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System;
66
using System.Collections.Generic;
77
using System.IO;
8-
using System.Linq;
98
using System.Management.Automation;
109
using System.Reflection;
1110
using SMA = System.Management.Automation;
@@ -304,7 +303,7 @@ private void RemovePSReadLineForStartup()
304303
bool hasPSReadLine = pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Get-Module", typeof(GetModuleCommand)))
305304
.AddParameter("Name", "PSReadLine")
306305
.Invoke()
307-
.Any();
306+
.Count > 0;
308307

309308
if (hasPSReadLine)
310309
{

src/PowerShellEditorServices.Hosting/Configuration/HostLogger.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Runtime.CompilerServices;
99
using System.Text;
1010
using System.Threading;
11-
using System.Threading.Tasks;
1211

1312
namespace Microsoft.PowerShell.EditorServices.Hosting
1413
{
@@ -67,7 +66,6 @@ private class Unsubscriber : IDisposable
6766

6867
private readonly IObserver<(PsesLogLevel, string)> _thisSubscriber;
6968

70-
7169
public Unsubscriber(ConcurrentDictionary<IObserver<(PsesLogLevel, string)>, bool> subscribedObservers, IObserver<(PsesLogLevel, string)> thisSubscriber)
7270
{
7371
_subscribedObservers = subscribedObservers;
@@ -161,7 +159,7 @@ public void Log(PsesLogLevel logLevel, string message)
161159
/// Convenience method for logging exceptions.
162160
/// </summary>
163161
/// <param name="message">The human-directed message to accompany the exception.</param>
164-
/// <param name="exception">The actual execption to log.</param>
162+
/// <param name="exception">The actual exception to log.</param>
165163
/// <param name="callerName">The name of the calling method.</param>
166164
/// <param name="callerSourceFile">The name of the file where this is logged.</param>
167165
/// <param name="callerLineNumber">The line in the file where this is logged.</param>
@@ -171,7 +169,6 @@ public void LogException(
171169
[CallerMemberName] string callerName = null,
172170
[CallerFilePath] string callerSourceFile = null,
173171
[CallerLineNumber] int callerLineNumber = -1) => Log(PsesLogLevel.Error, $"{message}. Exception logged in {callerSourceFile} on line {callerLineNumber} in {callerName}:\n{exception}");
174-
175172
}
176173

177174
/// <summary>
@@ -323,7 +320,7 @@ public void OnNext((PsesLogLevel logLevel, string message) value)
323320
case PsesLogLevel.Error:
324321
message = $"[ERR]: {value.message}";
325322
break;
326-
};
323+
}
327324

328325
_messageQueue.Add(message);
329326
}

src/PowerShellEditorServices.Hosting/Configuration/TransportConfig.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public sealed class DuplexNamedPipeTransportConfig : ITransportConfig
6767
/// Create a duplex named pipe transport config with an automatically generated pipe name.
6868
/// </summary>
6969
/// <returns>A new duplex named pipe transport configuration.</returns>
70-
7170
public static DuplexNamedPipeTransportConfig Create(HostLogger logger) => new(logger, NamedPipeUtils.GenerateValidNamedPipeName());
7271

7372
/// <summary>

src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
2828
/// </summary>
2929
public sealed class EditorServicesLoader : IDisposable
3030
{
31-
3231
#if !CoreCLR
3332
private const int Net461Version = 394254;
3433

@@ -92,7 +91,7 @@ public static EditorServicesLoader Create(
9291
};
9392
}
9493

95-
AssemblyLoadContext.Default.Resolving += (AssemblyLoadContext defaultLoadContext, AssemblyName asmName) =>
94+
AssemblyLoadContext.Default.Resolving += (AssemblyLoadContext _, AssemblyName asmName) =>
9695
{
9796
#if DEBUG
9897
logger.Log(PsesLogLevel.Diagnostic, $"Assembly resolve event fired for {asmName}. Stacktrace:\n{new StackTrace()}");

src/PowerShellEditorServices.Hosting/Internal/EditorServicesRunner.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ public Task RunUntilShutdown()
6868
return runAndAwaitShutdown;
6969
}
7070

71-
/// <remarks>
71+
/// <summary>
7272
/// TODO: This class probably should not be <see cref="IDisposable"/> as the primary
7373
/// intention of that interface is to provide cleanup of unmanaged resources, which the
7474
/// logger certainly is not. Nor is this class used with a <see langword="using"/>. It is
7575
/// only because of the use of <see cref="_serverFactory"/> that this class is also
7676
/// disposable, and instead that class should be fixed.
77-
/// </remarks>
77+
/// </summary>
7878
public void Dispose() => _serverFactory.Dispose();
7979

8080
/// <summary>
@@ -165,7 +165,7 @@ private async Task CreateEditorServicesAndRunUntilShutdown()
165165
Task<PsesDebugServer> debugServerCreation = null;
166166
if (creatingDebugServer)
167167
{
168-
debugServerCreation = CreateDebugServerWithLanguageServerAsync(languageServer, usePSReadLine: _config.ConsoleRepl == ConsoleReplKind.PSReadLine);
168+
debugServerCreation = CreateDebugServerWithLanguageServerAsync(languageServer);
169169
}
170170

171171
Task languageServerStart = languageServer.StartAsync();
@@ -219,10 +219,10 @@ private async Task StartDebugServer(Task<PsesDebugServer> debugServerCreation)
219219
await debugServer.StartAsync().ConfigureAwait(false);
220220
}
221221

222-
private Task RestartDebugServerAsync(PsesDebugServer debugServer, bool usePSReadLine)
222+
private Task RestartDebugServerAsync(PsesDebugServer debugServer)
223223
{
224224
_logger.Log(PsesLogLevel.Diagnostic, "Restarting debug server");
225-
Task<PsesDebugServer> debugServerCreation = RecreateDebugServerAsync(debugServer, usePSReadLine);
225+
Task<PsesDebugServer> debugServerCreation = RecreateDebugServerAsync(debugServer);
226226
return StartDebugServer(debugServerCreation);
227227
}
228228

@@ -235,22 +235,22 @@ private async Task<PsesLanguageServer> CreateLanguageServerAsync(HostStartupInfo
235235
return _serverFactory.CreateLanguageServer(inStream, outStream, hostDetails);
236236
}
237237

238-
private async Task<PsesDebugServer> CreateDebugServerWithLanguageServerAsync(PsesLanguageServer languageServer, bool usePSReadLine)
238+
private async Task<PsesDebugServer> CreateDebugServerWithLanguageServerAsync(PsesLanguageServer languageServer)
239239
{
240240
_logger.Log(PsesLogLevel.Verbose, $"Creating debug adapter transport with endpoint {_config.DebugServiceTransport.EndpointDetails}");
241241
(Stream inStream, Stream outStream) = await _config.DebugServiceTransport.ConnectStreamsAsync().ConfigureAwait(false);
242242

243243
_logger.Log(PsesLogLevel.Diagnostic, "Creating debug adapter");
244-
return _serverFactory.CreateDebugServerWithLanguageServer(inStream, outStream, languageServer, usePSReadLine);
244+
return _serverFactory.CreateDebugServerWithLanguageServer(inStream, outStream, languageServer);
245245
}
246246

247-
private async Task<PsesDebugServer> RecreateDebugServerAsync(PsesDebugServer debugServer, bool usePSReadLine)
247+
private async Task<PsesDebugServer> RecreateDebugServerAsync(PsesDebugServer debugServer)
248248
{
249249
_logger.Log(PsesLogLevel.Diagnostic, "Recreating debug adapter transport");
250250
(Stream inStream, Stream outStream) = await _config.DebugServiceTransport.ConnectStreamsAsync().ConfigureAwait(false);
251251

252252
_logger.Log(PsesLogLevel.Diagnostic, "Recreating debug adapter");
253-
return _serverFactory.RecreateDebugServer(inStream, outStream, debugServer, usePSReadLine);
253+
return _serverFactory.RecreateDebugServer(inStream, outStream, debugServer);
254254
}
255255

256256
private async Task<PsesDebugServer> CreateDebugServerForTempSessionAsync(HostStartupInfo hostDetails)
@@ -309,10 +309,7 @@ private void DebugServer_OnSessionEnded(object sender, EventArgs args)
309309
PsesDebugServer oldServer = (PsesDebugServer)sender;
310310
oldServer.Dispose();
311311
_alreadySubscribedDebug = false;
312-
Task.Run(() =>
313-
{
314-
RestartDebugServerAsync(oldServer, usePSReadLine: _config.ConsoleRepl == ConsoleReplKind.PSReadLine);
315-
});
312+
Task.Run(() => RestartDebugServerAsync(oldServer));
316313
}
317314
}
318315
}

src/PowerShellEditorServices.Hosting/Internal/NamedPipeUtils.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using System;
54
using System.Collections.Generic;
65
using System.IO;
76
using System.IO.Pipes;
@@ -79,8 +78,7 @@ internal static NamedPipeServerStream CreateNamedPipe(
7978
/// <returns>A named pipe name or name suffix that is safe to you.</returns>
8079
public static string GenerateValidNamedPipeName(IReadOnlyCollection<string> prefixes = null)
8180
{
82-
int tries = 0;
83-
do
81+
for (int i = 0; i < 10; i++)
8482
{
8583
string pipeName = $"PSES_{Path.GetRandomFileName()}";
8684

@@ -111,8 +109,7 @@ public static string GenerateValidNamedPipeName(IReadOnlyCollection<string> pref
111109
{
112110
return pipeName;
113111
}
114-
115-
} while (tries < 10);
112+
}
116113

117114
throw new IOException("Unable to create named pipe; no available names");
118115
}
@@ -146,7 +143,6 @@ public static string GetNamedPipePath(string pipeName)
146143
return Path.Combine(Path.GetTempPath(), $"CoreFxPipe_{pipeName}");
147144
}
148145
#endif
149-
150146
return $@"\\.\pipe\{pipeName}";
151147
}
152148
}

src/PowerShellEditorServices.Hosting/Internal/PsesLoadContext.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ private void TrySetName(string name)
6161
"_name",
6262
BindingFlags.NonPublic | BindingFlags.Instance);
6363

64-
if (nameBackingField != null)
65-
{
66-
nameBackingField.SetValue(this, name);
67-
}
64+
nameBackingField?.SetValue(this, name);
6865
}
6966
catch
7067
{

0 commit comments

Comments
 (0)