Skip to content

Apply automatic fixes (manually) #1755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
@@ -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
3 changes: 3 additions & 0 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
@@ -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
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
Original file line number Diff line number Diff line change
@@ -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;
@@ -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)
{
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.PowerShell.EditorServices.Hosting
{
@@ -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;
@@ -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>
@@ -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>
@@ -323,7 +320,7 @@ public void OnNext((PsesLogLevel logLevel, string message) value)
case PsesLogLevel.Error:
message = $"[ERR]: {value.message}";
break;
};
}

_messageQueue.Add(message);
}
Original file line number Diff line number Diff line change
@@ -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>
3 changes: 1 addition & 2 deletions src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
/// </summary>
public sealed class EditorServicesLoader : IDisposable
{

#if !CoreCLR
private const int Net461Version = 394254;

@@ -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()}");
Original file line number Diff line number Diff line change
@@ -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>
@@ -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();
@@ -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);
}

@@ -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)
@@ -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;
@@ -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()}";

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

} while (tries < 10);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was never incrementing tries and therefore had actually been an infinite loop.

}

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

return $@"\\.\pipe\{pipeName}";
}
}
Original file line number Diff line number Diff line change
@@ -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
{
Original file line number Diff line number Diff line change
@@ -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
{
@@ -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();
Original file line number Diff line number Diff line change
@@ -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,
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
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
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>
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 4 additions & 5 deletions src/PowerShellEditorServices/Extensions/EditorCommand.cs
Original file line number Diff line number Diff line change
@@ -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

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

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

#region Properties

/// <summary>
6 changes: 3 additions & 3 deletions src/PowerShellEditorServices/Extensions/EditorContext.cs
Original file line number Diff line number Diff line change
@@ -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

2 changes: 0 additions & 2 deletions src/PowerShellEditorServices/Extensions/EditorFileRanges.cs
Original file line number Diff line number Diff line change
@@ -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;

@@ -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>
Loading