Skip to content
Draft
Show file tree
Hide file tree
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
10 changes: 1 addition & 9 deletions src/PowerShellEditorServices/Server/PsesLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using Microsoft.PowerShell.EditorServices.Services.Extension;
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Protocol.General;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using OmniSharp.Extensions.LanguageServer.Server;
Expand Down Expand Up @@ -107,14 +106,7 @@ public async Task StartAsync()
.WithHandler<PsesCodeLensHandlers>()
.WithHandler<PsesCodeActionHandler>()
.WithHandler<InvokeExtensionCommandHandler>()
// If PsesCompletionHandler is not marked as serial, then DidChangeTextDocument
// notifications will end up cancelling completion. So quickly typing `Get-`
// would result in no completions.
//
// This also lets completion requests interrupt time consuming background tasks
// like the references code lens.
.WithHandler<PsesCompletionHandler>(
new JsonRpcHandlerOptions() { RequestProcessType = RequestProcessType.Serial })
.WithHandler<PsesCompletionHandler>()
.WithHandler<PsesHoverHandler>()
.WithHandler<PsesSignatureHelpHandler>()
.WithHandler<PsesDefinitionHandler>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,30 @@ public override async Task<CompletionItem> Handle(CompletionItem request, Cancel
return request;
}

// Get the documentation for the function
CommandInfo commandInfo = await CommandHelpers.GetCommandInfoAsync(
request.Label,
_runspaceContext.CurrentRunspace,
_executionService,
cancellationToken).ConfigureAwait(false);

if (commandInfo is not null)
try
{
return request with
// Get the documentation for the function
CommandInfo commandInfo = await CommandHelpers.GetCommandInfoAsync(
request.Label,
_runspaceContext.CurrentRunspace,
_executionService,
cancellationToken).ConfigureAwait(false);

if (commandInfo is not null)
{
Documentation = await CommandHelpers.GetCommandSynopsisAsync(
commandInfo,
_executionService,
cancellationToken).ConfigureAwait(false)
};
return request with
{
Documentation = await CommandHelpers.GetCommandSynopsisAsync(
commandInfo,
_executionService,
cancellationToken).ConfigureAwait(false)
};
}
}
// Ignore canceled requests (logging will pollute the output).
catch (TaskCanceledException)
{
return request;
}

return request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ public async Task CompletesFilePath()
Assert.All(results, r => Assert.True(r.Kind is CompletionItemKind.File or CompletionItemKind.Folder));
}

[Fact]
public async Task CompletionResolveHandlesTaskCanceledException()
{
using CancellationTokenSource cancellationTokenSource = new();
#if NET5_0_OR_GREATER
await cancellationTokenSource.CancelAsync();
#else
cancellationTokenSource.Cancel();
#endif
CompletionItem request = new()
{
Kind = CompletionItemKind.Function,
Label = "Get-ChildItem",
Detail = "Microsoft.PowerShell.Management"
};

CompletionItem actual = await completionHandler.Handle(request, cancellationTokenSource.Token);

Assert.Equal(request, actual);
}

// TODO: These should be an integration tests at a higher level if/when https://github.com/PowerShell/PowerShell/pull/25108 is merged. As of today, we can't actually test this in the PS engine currently.
[Fact]
public void CanExtractTypeAndDescriptionFromTooltip()
Expand Down
Loading