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

+2-2
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

+3
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

+3
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

+1-2
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

+2-5
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

-1
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

+1-2
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

+10-13
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

+2-6
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

+1-4
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
{

src/PowerShellEditorServices.VSCode/Cmdlets/VSCodeHtmlContentViewCommands.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33

44
using System;
55
using System.Management.Automation;
6-
using Microsoft.Extensions.DependencyInjection;
7-
using Microsoft.Extensions.Logging;
86
using Microsoft.PowerShell.EditorServices.Extensions;
97
using Microsoft.PowerShell.EditorServices.VSCode.CustomViews;
10-
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
118

129
namespace Microsoft.PowerShell.EditorServices.VSCode
1310
{
@@ -109,10 +106,12 @@ public class SetVSCodeHtmlContentViewCommand : PSCmdlet
109106
///
110107
protected override void BeginProcessing()
111108
{
112-
HtmlContent htmlContent = new();
113-
htmlContent.BodyContent = HtmlBodyContent;
114-
htmlContent.JavaScriptPaths = JavaScriptPaths;
115-
htmlContent.StyleSheetPaths = StyleSheetPaths;
109+
HtmlContent htmlContent = new()
110+
{
111+
BodyContent = HtmlBodyContent,
112+
JavaScriptPaths = JavaScriptPaths,
113+
StyleSheetPaths = StyleSheetPaths
114+
};
116115
try
117116
{
118117
HtmlContentView.SetContentAsync(htmlContent).GetAwaiter().GetResult();

src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ internal abstract class CustomViewBase : ICustomView
1313

1414
public Guid Id { get; private set; }
1515

16-
public string Title { get; private set; }
16+
public string Title { get; }
1717

18-
protected CustomViewType ViewType { get; private set; }
18+
protected CustomViewType ViewType { get; }
1919

2020
public CustomViewBase(
2121
string viewTitle,

src/PowerShellEditorServices.VSCode/CustomViews/IHtmlContentView.cs

-1
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.Threading.Tasks;
65

76
namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews

src/PowerShellEditorServices.VSCode/CustomViews/IHtmlContentViews.cs

-1
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.Threading.Tasks;
65

76
namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews

src/PowerShellEditorServices.VSCode/CustomViews/ViewColumn.cs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using System;
5-
using System.Threading.Tasks;
6-
74
namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews
85
{
96
/// <summary>

src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ public object GetServiceByAssemblyQualifiedName(string asmQualifiedTypeName)
141141
/// <remarks>
142142
/// This method is intended as a trapdoor and should not be used in the first instance.
143143
/// Consider using the public extension services if possible.
144-
///
145144
/// Also note that services in PSES may live in a separate assembly load context,
146145
/// meaning that a type of the seemingly correct name may fail to fetch to a service
147146
/// that is known under a type of the same name but loaded in a different context.

src/PowerShellEditorServices/Extensions/EditorCommand.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ public sealed class EditorCommand
1616
/// <summary>
1717
/// Gets the name which uniquely identifies the command.
1818
/// </summary>
19-
public string Name { get; private set; }
19+
public string Name { get; }
2020

2121
/// <summary>
2222
/// Gets the display name for the command.
2323
/// </summary>
24-
public string DisplayName { get; private set; }
24+
public string DisplayName { get; }
2525

2626
/// <summary>
2727
/// Gets the boolean which determines whether this command's
2828
/// output should be suppressed.
2929
/// </summary>
30-
public bool SuppressOutput { get; private set; }
30+
public bool SuppressOutput { get; }
3131

3232
/// <summary>
3333
/// Gets the ScriptBlock which can be used to execute the command.
3434
/// </summary>
35-
public ScriptBlock ScriptBlock { get; private set; }
35+
public ScriptBlock ScriptBlock { get; }
3636

3737
#endregion
3838

@@ -84,4 +84,3 @@ public EditorCommand(
8484
#endregion
8585
}
8686
}
87-

src/PowerShellEditorServices/Extensions/EditorCommandAttribute.cs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace Microsoft.PowerShell.EditorServices.Extensions
1212
[AttributeUsage(AttributeTargets.Class)]
1313
public sealed class EditorCommandAttribute : Attribute
1414
{
15-
1615
#region Properties
1716

1817
/// <summary>

src/PowerShellEditorServices/Extensions/EditorContext.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ public sealed class EditorContext
2121
/// <summary>
2222
/// Gets the FileContext for the active file.
2323
/// </summary>
24-
public FileContext CurrentFile { get; private set; }
24+
public FileContext CurrentFile { get; }
2525

2626
/// <summary>
2727
/// Gets the BufferRange representing the current selection in the file.
2828
/// </summary>
29-
public IFileRange SelectedRange { get; private set; }
29+
public IFileRange SelectedRange { get; }
3030

3131
/// <summary>
3232
/// Gets the FilePosition representing the current cursor position.
3333
/// </summary>
34-
public IFilePosition CursorPosition { get; private set; }
34+
public IFilePosition CursorPosition { get; }
3535

3636
#endregion
3737

src/PowerShellEditorServices/Extensions/EditorFileRanges.cs

-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public static FileScriptPosition FromPosition(FileContext file, int lineNumber,
3131

3232
public static FileScriptPosition FromOffset(FileContext file, int offset)
3333
{
34-
3534
int line = 1;
3635
string fileText = file.Ast.Extent.Text;
3736

@@ -407,7 +406,6 @@ public LspCurrentFileContext(ClientEditorContext editorContext)
407406
/// </summary>
408407
public static class FileObjectExtensionMethods
409408
{
410-
411409
/// <summary>
412410
/// Convert a 1-based file position to a 0-based file position.
413411
/// </summary>

0 commit comments

Comments
 (0)