Skip to content

Commit 8c8940d

Browse files
committed
Treat CancellationToken parameter not last as error (and fix)
1 parent d2614cf commit 8c8940d

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

.editorconfig

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ dotnet_diagnostic.CS0219.severity = error
2323
dotnet_diagnostic.CS0414.severity = error
2424
# CA2007: Do not directly await a Task
2525
dotnet_diagnostic.CA2007.severity = error
26+
# CA1068: CancellationToken parameters must come last
27+
dotnet_diagnostic.CA1068.severity = error
2628
# CA1822: Mark members as static
2729
dotnet_diagnostic.CA1822.severity = error
2830
# CA1823: Avoid unused private fields

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ private void CleanupRunspace(RunspaceDetails runspaceDetails)
485485
/// <returns>A RunspaceHandle instance that gives access to the session's runspace.</returns>
486486
public Task<RunspaceHandle> GetRunspaceHandleAsync()
487487
{
488-
return this.GetRunspaceHandleImplAsync(CancellationToken.None, isReadLine: false);
488+
return this.GetRunspaceHandleImplAsync(false, CancellationToken.None);
489489
}
490490

491491
/// <summary>
@@ -497,7 +497,7 @@ public Task<RunspaceHandle> GetRunspaceHandleAsync()
497497
/// <returns>A RunspaceHandle instance that gives access to the session's runspace.</returns>
498498
public Task<RunspaceHandle> GetRunspaceHandleAsync(CancellationToken cancellationToken)
499499
{
500-
return this.GetRunspaceHandleImplAsync(cancellationToken, isReadLine: false);
500+
return this.GetRunspaceHandleImplAsync(false, cancellationToken);
501501
}
502502

503503
/// <summary>
@@ -1415,12 +1415,12 @@ public void Close()
14151415

14161416
private Task<RunspaceHandle> GetRunspaceHandleAsync(bool isReadLine)
14171417
{
1418-
return this.GetRunspaceHandleImplAsync(CancellationToken.None, isReadLine);
1418+
return this.GetRunspaceHandleImplAsync(isReadLine, CancellationToken.None);
14191419
}
14201420

1421-
private Task<RunspaceHandle> GetRunspaceHandleImplAsync(CancellationToken cancellationToken, bool isReadLine)
1421+
private Task<RunspaceHandle> GetRunspaceHandleImplAsync(bool isReadLine, CancellationToken cancellationToken)
14221422
{
1423-
return this.PromptNest.GetRunspaceHandleAsync(cancellationToken, isReadLine);
1423+
return this.PromptNest.GetRunspaceHandleAsync(isReadLine, cancellationToken);
14241424
}
14251425

14261426
private ExecutionTarget GetExecutionTarget(ExecutionOptions options = null)

src/PowerShellEditorServices/Services/PowerShellContext/Session/InvocationEventQueue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ internal async Task InvokeOnPipelineThreadAsync(Action<PowerShell> invocationAct
113113
{
114114
var request = new InvocationRequest(pwsh =>
115115
{
116-
using (_promptNest.GetRunspaceHandle(CancellationToken.None, isReadLine: false))
116+
using (_promptNest.GetRunspaceHandle(false, CancellationToken.None))
117117
{
118118
pwsh.Runspace = _runspace;
119119
invocationAction(pwsh);

src/PowerShellEditorServices/Services/PowerShellContext/Session/PSReadLinePromptContext.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ public async Task AbortReadLineAsync() {
177177

178178
public void WaitForReadLineExit()
179179
{
180-
using (_promptNest.GetRunspaceHandle(CancellationToken.None, isReadLine: true))
180+
using (_promptNest.GetRunspaceHandle(true, CancellationToken.None))
181181
{ }
182182
}
183183

184184
public async Task WaitForReadLineExitAsync() {
185-
using (await _promptNest.GetRunspaceHandleAsync(CancellationToken.None, isReadLine: true).ConfigureAwait(false))
185+
using (await _promptNest.GetRunspaceHandleAsync(true, CancellationToken.None).ConfigureAwait(false))
186186
{ }
187187
}
188188

src/PowerShellEditorServices/Services/PowerShellContext/Session/PromptNest.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ internal PowerShell GetPowerShell(bool isReadLine = false)
253253
/// </param>
254254
/// <param name="isReadLine">Indicates whether this is for a PSReadLine command.</param>
255255
/// <returns>The <see cref="RunspaceHandle" /> for the current frame.</returns>
256-
internal RunspaceHandle GetRunspaceHandle(CancellationToken cancellationToken, bool isReadLine)
256+
internal RunspaceHandle GetRunspaceHandle(bool isReadLine, CancellationToken cancellationToken)
257257
{
258258
if (_isDisposed)
259259
{
@@ -264,10 +264,10 @@ internal RunspaceHandle GetRunspaceHandle(CancellationToken cancellationToken, b
264264
// is in process.
265265
if (isReadLine && !_powerShellContext.IsCurrentRunspaceOutOfProcess())
266266
{
267-
GetRunspaceHandleImpl(cancellationToken, isReadLine: false);
267+
GetRunspaceHandleImpl(false, cancellationToken);
268268
}
269269

270-
return GetRunspaceHandleImpl(cancellationToken, isReadLine);
270+
return GetRunspaceHandleImpl(isReadLine, cancellationToken);
271271
}
272272

273273

@@ -284,7 +284,7 @@ internal RunspaceHandle GetRunspaceHandle(CancellationToken cancellationToken, b
284284
/// The <see cref="Task{RunspaceHandle}.Result" /> property will return the
285285
/// <see cref="RunspaceHandle" /> for the current frame.
286286
/// </returns>
287-
internal async Task<RunspaceHandle> GetRunspaceHandleAsync(CancellationToken cancellationToken, bool isReadLine)
287+
internal async Task<RunspaceHandle> GetRunspaceHandleAsync(bool isReadLine, CancellationToken cancellationToken)
288288
{
289289
if (_isDisposed)
290290
{
@@ -295,10 +295,10 @@ internal async Task<RunspaceHandle> GetRunspaceHandleAsync(CancellationToken can
295295
// is in process.
296296
if (isReadLine && !_powerShellContext.IsCurrentRunspaceOutOfProcess())
297297
{
298-
await GetRunspaceHandleImplAsync(cancellationToken, isReadLine: false).ConfigureAwait(false);
298+
await GetRunspaceHandleImplAsync(false, cancellationToken).ConfigureAwait(false);
299299
}
300300

301-
return await GetRunspaceHandleImplAsync(cancellationToken, isReadLine).ConfigureAwait(false);
301+
return await GetRunspaceHandleImplAsync(isReadLine, cancellationToken).ConfigureAwait(false);
302302
}
303303

304304
/// <summary>
@@ -517,7 +517,7 @@ private AsyncQueue<RunspaceHandle> NewHandleQueue()
517517
return queue;
518518
}
519519

520-
private RunspaceHandle GetRunspaceHandleImpl(CancellationToken cancellationToken, bool isReadLine)
520+
private RunspaceHandle GetRunspaceHandleImpl(bool isReadLine, CancellationToken cancellationToken)
521521
{
522522
if (isReadLine)
523523
{
@@ -527,7 +527,7 @@ private RunspaceHandle GetRunspaceHandleImpl(CancellationToken cancellationToken
527527
return CurrentFrame.Queue.Dequeue(cancellationToken);
528528
}
529529

530-
private async Task<RunspaceHandle> GetRunspaceHandleImplAsync(CancellationToken cancellationToken, bool isReadLine)
530+
private async Task<RunspaceHandle> GetRunspaceHandleImplAsync(bool isReadLine, CancellationToken cancellationToken)
531531
{
532532
if (isReadLine)
533533
{

0 commit comments

Comments
 (0)