Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have a NET_CORE or DESKTOP or something like that already in the codebase? Just be consistent @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use the repo’s existing CoreCLR compilation symbol for consistency in CompletionResolveHandlesTaskCanceledException (61e5d9e).

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