private async Task <Task <CompletionContext> > GetCompletionContextTaskAsync(LSP.CompletionContext requestContext, SnapshotPoint triggerLocation, CancellationToken token) { // TODO: Should this be using the ILanguageServiceBroker2 calls instead? That will include the necessary sync that the LanguageServiceBroker does if (token.IsCancellationRequested) { return(System.Threading.Tasks.Task.FromResult(CompletionContext.Empty)); } if (!triggerLocation.Snapshot.TextBuffer.IsReplBuffer()) { return(System.Threading.Tasks.Task.FromResult(CompletionContext.Empty)); } var itemBag = new ConcurrentBag <(ILanguageClient, LSP.CompletionItem, Func <LSP.CompletionItem, CancellationToken, Task <LSP.CompletionItem> >)>(); var isIncomplete = false; Func <(ILanguageClient client, LSP.CompletionList completionList), System.Threading.Tasks.Task> progressAction = (partialResults) => { if (!(partialResults.client is PythonLanguageClient clientInstance)) { return(System.Threading.Tasks.Task.CompletedTask); } Func <LSP.CompletionItem, CancellationToken, Task <LSP.CompletionItem> > resolveCompletionTask = (i, c) => clientInstance.InvokeResolveAsync(i, c); foreach (var completionItem in partialResults.completionList.Items) { itemBag.Add((clientInstance, completionItem, resolveCompletionTask)); } isIncomplete |= partialResults.completionList.IsIncomplete; return(System.Threading.Tasks.Task.CompletedTask); }; // The following call enqueues the RPC request. We may not yield (await) before this call. var requestTask = await GetCompletionRequestAsync(triggerLocation, triggerLocation.Snapshot.TextBuffer, requestContext, token, progressAction) .ConfigureAwait(false); return(this.CompletionResultsToContextAsync(requestTask, triggerLocation, itemBag, isIncomplete, token)); }
public async Task <Task <CompletionResults> > GetCompletionRequestAsync( SnapshotPoint triggerPoint, ITextBuffer documentBuffer, LSP.CompletionContext requestContext, CancellationToken token, Func <(ILanguageClient, LSP.CompletionList), System.Threading.Tasks.Task> progressAction = null)