Skip to content

Commit

Permalink
Apply automatic fixes (manually) (#1755)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andyleejordan authored Apr 13, 2022
1 parent aa221aa commit aa1c253
Show file tree
Hide file tree
Showing 102 changed files with 251 additions and 479 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ dotnet_diagnostic.CS4014.severity = suggestion
# RCS1102: Make class static
dotnet_diagnostic.RCS1102.severity = warning
# RCS1139: Add summary element to documentation comment
dotnet_diagnostic.RCS1139.severity = suggestion
dotnet_diagnostic.RCS1139.severity = silent
# RCS1194: Implement exception constructors
dotnet_diagnostic.RCS1194.severity = suggestion
# RCS1210: Return completed task instead of returning null
Expand All @@ -92,7 +92,7 @@ dotnet_diagnostic.VSTHRD110.severity = suggestion
# VSTHRD114: Avoid returning a null Task
dotnet_diagnostic.VSTHRD114.severity = suggestion
# VSTHRD200: Use "Async" suffix for awaitable methods
dotnet_diagnostic.VSTHRD200.severity = suggestion
dotnet_diagnostic.VSTHRD200.severity = silent

# xUnit2013: Do not use equality check to check for collection size
dotnet_diagnostic.xUnit2013.severity = warning
Expand Down
3 changes: 3 additions & 0 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ task CreateBuildInfo {
[string]$buildTime = [datetime]::Today.ToString("s", [System.Globalization.CultureInfo]::InvariantCulture)

$buildInfoContents = @"
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Globalization;
namespace Microsoft.PowerShell.EditorServices.Hosting
Expand Down
3 changes: 3 additions & 0 deletions src/PowerShellEditorServices.Hosting/BuildInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Globalization;

namespace Microsoft.PowerShell.EditorServices.Hosting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Reflection;
using SMA = System.Management.Automation;
Expand Down Expand Up @@ -304,7 +303,7 @@ private void RemovePSReadLineForStartup()
bool hasPSReadLine = pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Get-Module", typeof(GetModuleCommand)))
.AddParameter("Name", "PSReadLine")
.Invoke()
.Any();
.Count > 0;

if (hasPSReadLine)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.PowerShell.EditorServices.Hosting
{
Expand Down Expand Up @@ -67,7 +66,6 @@ private class Unsubscriber : IDisposable

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


public Unsubscriber(ConcurrentDictionary<IObserver<(PsesLogLevel, string)>, bool> subscribedObservers, IObserver<(PsesLogLevel, string)> thisSubscriber)
{
_subscribedObservers = subscribedObservers;
Expand Down Expand Up @@ -161,7 +159,7 @@ public void Log(PsesLogLevel logLevel, string message)
/// Convenience method for logging exceptions.
/// </summary>
/// <param name="message">The human-directed message to accompany the exception.</param>
/// <param name="exception">The actual execption to log.</param>
/// <param name="exception">The actual exception to log.</param>
/// <param name="callerName">The name of the calling method.</param>
/// <param name="callerSourceFile">The name of the file where this is logged.</param>
/// <param name="callerLineNumber">The line in the file where this is logged.</param>
Expand All @@ -171,7 +169,6 @@ public void LogException(
[CallerMemberName] string callerName = null,
[CallerFilePath] string callerSourceFile = null,
[CallerLineNumber] int callerLineNumber = -1) => Log(PsesLogLevel.Error, $"{message}. Exception logged in {callerSourceFile} on line {callerLineNumber} in {callerName}:\n{exception}");

}

/// <summary>
Expand Down Expand Up @@ -323,7 +320,7 @@ public void OnNext((PsesLogLevel logLevel, string message) value)
case PsesLogLevel.Error:
message = $"[ERR]: {value.message}";
break;
};
}

_messageQueue.Add(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public sealed class DuplexNamedPipeTransportConfig : ITransportConfig
/// Create a duplex named pipe transport config with an automatically generated pipe name.
/// </summary>
/// <returns>A new duplex named pipe transport configuration.</returns>

public static DuplexNamedPipeTransportConfig Create(HostLogger logger) => new(logger, NamedPipeUtils.GenerateValidNamedPipeName());

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
/// </summary>
public sealed class EditorServicesLoader : IDisposable
{

#if !CoreCLR
private const int Net461Version = 394254;

Expand Down Expand Up @@ -92,7 +91,7 @@ public static EditorServicesLoader Create(
};
}

AssemblyLoadContext.Default.Resolving += (AssemblyLoadContext defaultLoadContext, AssemblyName asmName) =>
AssemblyLoadContext.Default.Resolving += (AssemblyLoadContext _, AssemblyName asmName) =>
{
#if DEBUG
logger.Log(PsesLogLevel.Diagnostic, $"Assembly resolve event fired for {asmName}. Stacktrace:\n{new StackTrace()}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public Task RunUntilShutdown()
return runAndAwaitShutdown;
}

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

/// <summary>
Expand Down Expand Up @@ -165,7 +165,7 @@ private async Task CreateEditorServicesAndRunUntilShutdown()
Task<PsesDebugServer> debugServerCreation = null;
if (creatingDebugServer)
{
debugServerCreation = CreateDebugServerWithLanguageServerAsync(languageServer, usePSReadLine: _config.ConsoleRepl == ConsoleReplKind.PSReadLine);
debugServerCreation = CreateDebugServerWithLanguageServerAsync(languageServer);
}

Task languageServerStart = languageServer.StartAsync();
Expand Down Expand Up @@ -219,10 +219,10 @@ private async Task StartDebugServer(Task<PsesDebugServer> debugServerCreation)
await debugServer.StartAsync().ConfigureAwait(false);
}

private Task RestartDebugServerAsync(PsesDebugServer debugServer, bool usePSReadLine)
private Task RestartDebugServerAsync(PsesDebugServer debugServer)
{
_logger.Log(PsesLogLevel.Diagnostic, "Restarting debug server");
Task<PsesDebugServer> debugServerCreation = RecreateDebugServerAsync(debugServer, usePSReadLine);
Task<PsesDebugServer> debugServerCreation = RecreateDebugServerAsync(debugServer);
return StartDebugServer(debugServerCreation);
}

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

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

_logger.Log(PsesLogLevel.Diagnostic, "Creating debug adapter");
return _serverFactory.CreateDebugServerWithLanguageServer(inStream, outStream, languageServer, usePSReadLine);
return _serverFactory.CreateDebugServerWithLanguageServer(inStream, outStream, languageServer);
}

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

_logger.Log(PsesLogLevel.Diagnostic, "Recreating debug adapter");
return _serverFactory.RecreateDebugServer(inStream, outStream, debugServer, usePSReadLine);
return _serverFactory.RecreateDebugServer(inStream, outStream, debugServer);
}

private async Task<PsesDebugServer> CreateDebugServerForTempSessionAsync(HostStartupInfo hostDetails)
Expand Down Expand Up @@ -309,10 +309,7 @@ private void DebugServer_OnSessionEnded(object sender, EventArgs args)
PsesDebugServer oldServer = (PsesDebugServer)sender;
oldServer.Dispose();
_alreadySubscribedDebug = false;
Task.Run(() =>
{
RestartDebugServerAsync(oldServer, usePSReadLine: _config.ConsoleRepl == ConsoleReplKind.PSReadLine);
});
Task.Run(() => RestartDebugServerAsync(oldServer));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
Expand Down Expand Up @@ -79,8 +78,7 @@ internal static NamedPipeServerStream CreateNamedPipe(
/// <returns>A named pipe name or name suffix that is safe to you.</returns>
public static string GenerateValidNamedPipeName(IReadOnlyCollection<string> prefixes = null)
{
int tries = 0;
do
for (int i = 0; i < 10; i++)
{
string pipeName = $"PSES_{Path.GetRandomFileName()}";

Expand Down Expand Up @@ -111,8 +109,7 @@ public static string GenerateValidNamedPipeName(IReadOnlyCollection<string> pref
{
return pipeName;
}

} while (tries < 10);
}

throw new IOException("Unable to create named pipe; no available names");
}
Expand Down Expand Up @@ -146,7 +143,6 @@ public static string GetNamedPipePath(string pipeName)
return Path.Combine(Path.GetTempPath(), $"CoreFxPipe_{pipeName}");
}
#endif

return $@"\\.\pipe\{pipeName}";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ private void TrySetName(string name)
"_name",
BindingFlags.NonPublic | BindingFlags.Instance);

if (nameBackingField != null)
{
nameBackingField.SetValue(this, name);
}
nameBackingField?.SetValue(this, name);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

using System;
using System.Management.Automation;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Extensions;
using Microsoft.PowerShell.EditorServices.VSCode.CustomViews;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;

namespace Microsoft.PowerShell.EditorServices.VSCode
{
Expand Down Expand Up @@ -109,10 +106,12 @@ public class SetVSCodeHtmlContentViewCommand : PSCmdlet
///
protected override void BeginProcessing()
{
HtmlContent htmlContent = new();
htmlContent.BodyContent = HtmlBodyContent;
htmlContent.JavaScriptPaths = JavaScriptPaths;
htmlContent.StyleSheetPaths = StyleSheetPaths;
HtmlContent htmlContent = new()
{
BodyContent = HtmlBodyContent,
JavaScriptPaths = JavaScriptPaths,
StyleSheetPaths = StyleSheetPaths
};
try
{
HtmlContentView.SetContentAsync(htmlContent).GetAwaiter().GetResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ internal abstract class CustomViewBase : ICustomView

public Guid Id { get; private set; }

public string Title { get; private set; }
public string Title { get; }

protected CustomViewType ViewType { get; private set; }
protected CustomViewType ViewType { get; }

public CustomViewBase(
string viewTitle,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;

namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;

namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews
Expand Down
3 changes: 0 additions & 3 deletions src/PowerShellEditorServices.VSCode/CustomViews/ViewColumn.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;

namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public object GetServiceByAssemblyQualifiedName(string asmQualifiedTypeName)
/// <remarks>
/// This method is intended as a trapdoor and should not be used in the first instance.
/// Consider using the public extension services if possible.
///
/// Also note that services in PSES may live in a separate assembly load context,
/// meaning that a type of the seemingly correct name may fail to fetch to a service
/// that is known under a type of the same name but loaded in a different context.
Expand Down
9 changes: 4 additions & 5 deletions src/PowerShellEditorServices/Extensions/EditorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ public sealed class EditorCommand
/// <summary>
/// Gets the name which uniquely identifies the command.
/// </summary>
public string Name { get; private set; }
public string Name { get; }

/// <summary>
/// Gets the display name for the command.
/// </summary>
public string DisplayName { get; private set; }
public string DisplayName { get; }

/// <summary>
/// Gets the boolean which determines whether this command's
/// output should be suppressed.
/// </summary>
public bool SuppressOutput { get; private set; }
public bool SuppressOutput { get; }

/// <summary>
/// Gets the ScriptBlock which can be used to execute the command.
/// </summary>
public ScriptBlock ScriptBlock { get; private set; }
public ScriptBlock ScriptBlock { get; }

#endregion

Expand Down Expand Up @@ -84,4 +84,3 @@ public EditorCommand(
#endregion
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Microsoft.PowerShell.EditorServices.Extensions
[AttributeUsage(AttributeTargets.Class)]
public sealed class EditorCommandAttribute : Attribute
{

#region Properties

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/PowerShellEditorServices/Extensions/EditorContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public sealed class EditorContext
/// <summary>
/// Gets the FileContext for the active file.
/// </summary>
public FileContext CurrentFile { get; private set; }
public FileContext CurrentFile { get; }

/// <summary>
/// Gets the BufferRange representing the current selection in the file.
/// </summary>
public IFileRange SelectedRange { get; private set; }
public IFileRange SelectedRange { get; }

/// <summary>
/// Gets the FilePosition representing the current cursor position.
/// </summary>
public IFilePosition CursorPosition { get; private set; }
public IFilePosition CursorPosition { get; }

#endregion

Expand Down
2 changes: 0 additions & 2 deletions src/PowerShellEditorServices/Extensions/EditorFileRanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public static FileScriptPosition FromPosition(FileContext file, int lineNumber,

public static FileScriptPosition FromOffset(FileContext file, int offset)
{

int line = 1;
string fileText = file.Ast.Extent.Text;

Expand Down Expand Up @@ -407,7 +406,6 @@ public LspCurrentFileContext(ClientEditorContext editorContext)
/// </summary>
public static class FileObjectExtensionMethods
{

/// <summary>
/// Convert a 1-based file position to a 0-based file position.
/// </summary>
Expand Down
Loading

0 comments on commit aa1c253

Please sign in to comment.