提交 d3517d19 编写于 作者: D Dustin Campbell

Fix C# "speculative T" completion to appear properly in linked document...

Fix C# "speculative T" completion to appear properly in linked document scenarios, fixing failing unit test

Additionally, this change audits calls to GetUnionItemsFromDocumentAndLinkedDocumentsAsync to avoid redundant awaits.
上级 72db13c4
......@@ -62,9 +62,9 @@ public override async Task ProduceCompletionListAsync(CompletionListContext cont
return;
}
var snippetCompletionItems = await document.GetUnionResultsFromDocumentAndLinks(
var snippetCompletionItems = await document.GetUnionItemsFromDocumentAndLinkedDocumentsAsync(
UnionCompletionItemComparer.Instance,
async (d, c) => await GetSnippetsForDocumentAsync(d, position, workspace, c).ConfigureAwait(false),
(d, c) => GetSnippetsForDocumentAsync(d, position, workspace, c),
cancellationToken).ConfigureAwait(false);
context.AddItems(snippetCompletionItems);
......
......@@ -31,7 +31,11 @@ public override async Task ProduceCompletionListAsync(CompletionListContext cont
var position = context.Position;
var cancellationToken = context.CancellationToken;
if (await ShouldShowSpeculativeTCompletionItem(document, position, cancellationToken).ConfigureAwait(false))
var showSpeculativeT = await document.IsValidContextForDocumentOrLinkedDocumentsAsync(
(doc, ct) => ShouldShowSpeculativeTCompletionItemAsync(doc, position, ct),
cancellationToken).ConfigureAwait(false);
if (showSpeculativeT)
{
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
var filterSpan = this.GetTextChangeSpan(text, position);
......@@ -41,7 +45,7 @@ public override async Task ProduceCompletionListAsync(CompletionListContext cont
}
}
private async Task<bool> ShouldShowSpeculativeTCompletionItem(Document document, int position, CancellationToken cancellationToken)
private async Task<bool> ShouldShowSpeculativeTCompletionItemAsync(Document document, int position, CancellationToken cancellationToken)
{
var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
if (syntaxTree.IsInNonUserCode(position, cancellationToken) ||
......
......@@ -54,9 +54,9 @@ public override async Task ProduceCompletionListAsync(CompletionListContext cont
using (Logger.LogBlock(FunctionId.Completion_KeywordCompletionProvider_GetItemsWorker, cancellationToken))
{
var keywords = await document.GetUnionResultsFromDocumentAndLinks(
var keywords = await document.GetUnionItemsFromDocumentAndLinkedDocumentsAsync(
s_comparer,
async (doc, ct) => await RecommendKeywordsAsync(doc, position, ct).ConfigureAwait(false),
(doc, ct) => RecommendKeywordsAsync(doc, position, ct),
cancellationToken).ConfigureAwait(false);
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
......
......@@ -35,7 +35,7 @@ public static bool ShouldHideAdvancedMembers(this Document document)
return document.WithSyntaxRoot(newRoot);
}
public static async Task<IEnumerable<T>> GetUnionResultsFromDocumentAndLinks<T>(
public static async Task<IEnumerable<T>> GetUnionItemsFromDocumentAndLinkedDocumentsAsync<T>(
this Document document,
IEqualityComparer<T> comparer,
Func<Document, CancellationToken, Task<IEnumerable<T>>> getItemsWorker,
......@@ -61,5 +61,28 @@ public static bool ShouldHideAdvancedMembers(this Document document)
return totalItems;
}
public static async Task<bool> IsValidContextForDocumentOrLinkedDocumentsAsync(
this Document document,
Func<Document, CancellationToken, Task<bool>> contextChecker,
CancellationToken cancellationToken)
{
if (await contextChecker(document, cancellationToken).ConfigureAwait(false))
{
return true;
}
var solution = document.Project.Solution;
foreach (var linkedDocumentId in document.GetLinkedDocumentIds())
{
var linkedDocument = solution.GetDocument(linkedDocumentId);
if (await contextChecker(linkedDocument, cancellationToken).ConfigureAwait(false))
{
return true;
}
}
return false;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册