Skip to content

Commit e16ca88

Browse files
committed
Pass CancellationToken through SymbolDetails.CreateAsync()
1 parent a4bc2a1 commit e16ca88

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

src/PowerShellEditorServices/Services/Symbols/SymbolDetails.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Diagnostics;
55
using System.Management.Automation;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
89
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Runspace;
@@ -34,11 +35,11 @@ internal class SymbolDetails
3435

3536
#region Constructors
3637

37-
// TODO: This should take a cancellation token!
3838
internal static async Task<SymbolDetails> CreateAsync(
3939
SymbolReference symbolReference,
4040
IRunspaceInfo currentRunspace,
41-
IInternalPowerShellExecutionService executionService)
41+
IInternalPowerShellExecutionService executionService,
42+
CancellationToken cancellationToken)
4243
{
4344
SymbolDetails symbolDetails = new()
4445
{
@@ -50,14 +51,16 @@ internal static async Task<SymbolDetails> CreateAsync(
5051
CommandInfo commandInfo = await CommandHelpers.GetCommandInfoAsync(
5152
symbolReference.Id,
5253
currentRunspace,
53-
executionService).ConfigureAwait(false);
54+
executionService,
55+
cancellationToken).ConfigureAwait(false);
5456

5557
if (commandInfo is not null)
5658
{
5759
symbolDetails.Documentation =
5860
await CommandHelpers.GetCommandSynopsisAsync(
5961
commandInfo,
60-
executionService).ConfigureAwait(false);
62+
executionService,
63+
cancellationToken).ConfigureAwait(false);
6164

6265
if (commandInfo.CommandType == CommandTypes.Application)
6366
{

src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,16 @@ public static IEnumerable<SymbolReference> FindOccurrencesInFile(
222222
/// Finds the details of the symbol at the given script file location.
223223
/// </summary>
224224
public Task<SymbolDetails?> FindSymbolDetailsAtLocationAsync(
225-
ScriptFile scriptFile, int line, int column)
225+
ScriptFile scriptFile, int line, int column, CancellationToken cancellationToken)
226226
{
227227
SymbolReference? symbol = FindSymbolAtLocation(scriptFile, line, column);
228228
return symbol is null
229229
? Task.FromResult<SymbolDetails?>(null)
230-
: SymbolDetails.CreateAsync(symbol, _runspaceContext.CurrentRunspace, _executionService);
230+
: SymbolDetails.CreateAsync(
231+
symbol,
232+
_runspaceContext.CurrentRunspace,
233+
_executionService,
234+
cancellationToken);
231235
}
232236

233237
/// <summary>

src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public override async Task<Hover> Handle(HoverParams request, CancellationToken
5050
await _symbolsService.FindSymbolDetailsAtLocationAsync(
5151
scriptFile,
5252
request.Position.Line + 1,
53-
request.Position.Character + 1).ConfigureAwait(false);
53+
request.Position.Character + 1,
54+
cancellationToken).ConfigureAwait(false);
5455

5556
if (symbolDetails is null)
5657
{

test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@ public async Task FindsDetailsForBuiltInCommand()
755755
SymbolDetails symbolDetails = await symbolsService.FindSymbolDetailsAtLocationAsync(
756756
GetScriptFile(FindsDetailsForBuiltInCommandData.SourceDetails),
757757
FindsDetailsForBuiltInCommandData.SourceDetails.StartLineNumber,
758-
FindsDetailsForBuiltInCommandData.SourceDetails.StartColumnNumber).ConfigureAwait(true);
758+
FindsDetailsForBuiltInCommandData.SourceDetails.StartColumnNumber,
759+
CancellationToken.None).ConfigureAwait(true);
759760

760761
Assert.Equal("Gets the processes that are running on the local computer.", symbolDetails.Documentation);
761762
}

0 commit comments

Comments
 (0)