PowerShellEditorServices
PowerShellEditorServices copied to clipboard
.NET 6 Compiler Warning Cleanup
PR to follow to clean up a lot of these compiler warning errors
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\DebugAdapter\Handlers\DebugEvaluateHandler.cs(50,17): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\TextDocument\Handlers\CodeActionHandler.cs(41,48): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\Workspace\Handlers\ConfigurationHandler.cs(34,22): warning CS0649: Field 'PsesConfigurationHandler._extensionServiceInitialized' is never assigned to, and will always have its default value false [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Extensions\FileContext.cs(266,35): warning VSTHRD110: Observe the awaitable result of this method call by awaiting it, assigning to a variable, or passing it to another method. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Extensions\FileContext.cs(244,35): warning VSTHRD110: Observe the awaitable result of this method call by awaiting it, assigning to a variable, or passing it to another method. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Server\PsesServiceCollectionExtensions.cs(52,42): warning VSTHRD110: Observe the awaitable result of this method call by awaiting it, assigning to a variable, or passing it to another method. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Utility\AsyncUtils.cs(43,23): warning VSTHRD003: Avoid awaiting or returning a Task representing work that was not started within your context as that can lead to deadlocks. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\DebugAdapter\Handlers\ConfigurationDoneHandler.cs(83,22): warning VSTHRD110: Observe the awaitable result of this method call by awaiting it, assigning to a variable, or passing it to another method. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\Workspace\RemoteFileManagerService.cs(280,48): warning VSTHRD110: Observe the awaitable result of this method call by awaiting it, assigning to a variable, or passing it to another method. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShell\Handlers\EvaluateHandler.cs(41,18): warning VSTHRD110: Observe the awaitable result of this method call by awaiting it, assigning to a variable, or passing it to another method. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\DebugAdapter\Handlers\StackTraceHandler.cs(33,31): warning VSTHRD103: GetStackFrames synchronously blocks. Await GetStackFramesAsync instead. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\Workspace\RemoteFileManagerService.cs(578,28): warning VSTHRD100: Avoid "async void" methods, because any exceptions not handled by the method will crash the process. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\DebugAdapter\Handlers\LaunchAndAttachHandler.cs(402,23): warning VSTHRD003: Avoid awaiting or returning a Task representing work that was not started within your context as that can lead to deadlocks. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\DebugAdapter\Handlers\LaunchAndAttachHandler.cs(369,18): warning VSTHRD105: Avoid method overloads that assume TaskScheduler.Current. Use an overload that accepts a TaskScheduler and specify TaskScheduler.Default (or any other) explicitly. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\TextDocument\Handlers\FoldingRangeHandler.cs(44,85): warning VSTHRD114: Avoid returning null from a Task-returning method. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\TextDocument\Handlers\FoldingRangeHandler.cs(51,110): warning VSTHRD114: Avoid returning null from a Task-returning method. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\DebugAdapter\DebugService.cs(874,29): warning VSTHRD100: Avoid "async void" methods, because any exceptions not handled by the method will crash the process. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs(881,50): warning VSTHRD110: Observe the awaitable result of this method call by awaiting it, assigning to a variable, or passing it to another method. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShell\Console\UnixConsoleOperations.cs(259,39): warning VSTHRD105: Avoid method overloads that assume TaskScheduler.Current. Use an overload that accepts a TaskScheduler and specify TaskScheduler.Default (or any other) explicitly. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShell\Debugging\DscBreakpointCapability.cs(98,24): warning VSTHRD114: Avoid returning null from a Task-returning method. [c:\Users\JGrote\Projects\PowerShellEditorServices\src\PowerShellEditorServices\PowerShellEditorServices.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\test\PowerShellEditorServices.Test.E2E\DebugAdapterProtocolMessageTests.cs(93,13): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [c:\Users\JGrote\Projects\PowerShellEditorServices\test\PowerShellEditorServices.Test.E2E\PowerShellEditorServices.Test.E2E.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\test\PowerShellEditorServices.Test.E2E\DebugAdapterProtocolMessageTests.cs(203,17): warning CS0618: 'SetBreakpointsArguments.Lines' is obsolete: 'Deprecated' [c:\Users\JGrote\Projects\PowerShellEditorServices\test\PowerShellEditorServices.Test.E2E\PowerShellEditorServices.Test.E2E.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\test\PowerShellEditorServices.Test.E2E\DebugAdapterProtocolMessageTests.cs(93,13): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [c:\Users\JGrote\Projects\PowerShellEditorServices\test\PowerShellEditorServices.Test.E2E\PowerShellEditorServices.Test.E2E.csproj]
c:\Users\JGrote\Projects\PowerShellEditorServices\test\PowerShellEditorServices.Test.E2E\DebugAdapterProtocolMessageTests.cs(203,17): warning CS0618: 'SetBreakpointsArguments.Lines' is obsolete: 'Deprecated' [c:\Users\JGrote\Projects\PowerShellEditorServices\test\PowerShellEditorServices.Test.E2E\PowerShellEditorServices.Test.E2E.csproj]
https://github.com/OmniSharp/csharp-language-server-protocol/issues/682 https://github.com/PowerShell/PowerShellEditorServices/blob/18ad303fa027705f9643fc7799558c900b65a520/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs#L203-L204
@andschwa @SeeminglyScience there's lots of "fire and forget" async calls in the code base. Should I work on handling these or should we add a suppression to the warnings and consider them common practice?

Omg, thank you @JustinGrote. I have a stashed branch somewhere that probably fixes some of this, but I never got those changes in (and there's also a number of other warnings I'd love to turn on, especially the one around dead code!). To your question, the and forget async calls should each be double-checked. If there's really nothing else to do, they should be suppressed individually with a comment explaining it, but Rob had also started adding a "WhenDone" handler to those that captured errors and I think caused the warning not to crop up, and that's the best way to handle it.
We still have a lot of warnings to clean up 🙃
Hey @JustinGrote! Would you say we've pretty much resolved this? I ran dotnet format and roslynator fix (and will soon be adding those to CI to check that everything is snazzy).
I just fixed more.
I'm gonna close this as I feel the warnings are in a good state. I went through and carefully enabled or ignored just about everything.
Thank you for your comment, but please note that this issue has been closed for over a week. For better visibility, consider opening a new issue with a link to this instead.