Skip to content

Commit 5872caf

Browse files
committed
Treat unforwarded CancellationToken as error (and fix)
1 parent 8c8940d commit 5872caf

File tree

6 files changed

+9
-7
lines changed

6 files changed

+9
-7
lines changed

.editorconfig

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ dotnet_diagnostic.CS0169.severity = error
2121
dotnet_diagnostic.CS0219.severity = error
2222
# CS0414: The private field 'field' is assigned but its value is never used
2323
dotnet_diagnostic.CS0414.severity = error
24-
# CA2007: Do not directly await a Task
25-
dotnet_diagnostic.CA2007.severity = error
2624
# CA1068: CancellationToken parameters must come last
2725
dotnet_diagnostic.CA1068.severity = error
2826
# CA1822: Mark members as static
2927
dotnet_diagnostic.CA1822.severity = error
3028
# CA1823: Avoid unused private fields
3129
dotnet_diagnostic.CA1823.severity = error
30+
# CA2007: Do not directly await a Task
31+
dotnet_diagnostic.CA2007.severity = error
32+
# CA2016: Forward the CancellationToken parameter to methods that take one
33+
dotnet_diagnostic.CA2016.severity = error
3234
# All maintainability issues (dead code etc.)
3335
# See: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/maintainability-warnings
3436
dotnet_analyzer_diagnostic.category-Maintainability.severity = error

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DisconnectHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public async Task<DisconnectResponse> Handle(DisconnectArguments request, Cancel
7575

7676
#pragma warning disable CS4014
7777
// Trigger the clean up of the debugger. No need to wait for it.
78-
Task.Run(_psesDebugServer.OnSessionEnded);
78+
Task.Run(_psesDebugServer.OnSessionEnded, cancellationToken);
7979
#pragma warning restore CS4014
8080

8181
return new DisconnectResponse();

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/StackTraceHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public StackTraceHandler(
3030
public Task<StackTraceResponse> Handle(StackTraceArguments request, CancellationToken cancellationToken)
3131
{
3232
StackFrameDetails[] stackFrameDetails =
33-
_debugService.GetStackFrames();
33+
_debugService.GetStackFrames(cancellationToken);
3434

3535
// Handle a rare race condition where the adapter requests stack frames before they've
3636
// begun building.

src/PowerShellEditorServices/Services/PowerShellContext/Console/ConsoleReadLine.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ internal async Task<string> InvokeLegacyReadLineAsync(bool isCommandLine, Cancel
216216
}
217217
else
218218
{
219-
using (RunspaceHandle runspaceHandle = await this.powerShellContext.GetRunspaceHandleAsync().ConfigureAwait(false))
219+
using (RunspaceHandle runspaceHandle = await this.powerShellContext.GetRunspaceHandleAsync(cancellationToken) .ConfigureAwait(false))
220220
using (PowerShell powerShell = PowerShell.Create())
221221
{
222222
powerShell.Runspace = runspaceHandle.Runspace;

src/PowerShellEditorServices/Services/PowerShellContext/Console/UnixConsoleOperations.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private static Task<bool> SpinUntilKeyAvailableAsync(int millisecondsTimeout, Ca
264264
s_waitHandle.Wait(ShortWaitForKeySpinUntilSleepTime, cancellationToken);
265265
return IsKeyAvailable(cancellationToken);
266266
},
267-
millisecondsTimeout));
267+
millisecondsTimeout), cancellationToken);
268268
}
269269

270270
private static bool IsKeyAvailable(CancellationToken cancellationToken)

src/PowerShellEditorServices/Services/Symbols/Vistors/AstOperations.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static async Task<CommandCompletion> GetCompletionsAsync(
6262
ILogger logger,
6363
CancellationToken cancellationToken)
6464
{
65-
if (!s_completionHandle.Wait(0))
65+
if (!s_completionHandle.Wait(0, cancellationToken))
6666
{
6767
return null;
6868
}

0 commit comments

Comments
 (0)