提交 5331a978 编写于 作者: G Gen Lu

Use the new `GetChangeAsync` with `completionListSpan`

上级 d18962b2
...@@ -2744,7 +2744,7 @@ public override void M(in int x) ...@@ -2744,7 +2744,7 @@ public override void M(in int x)
var completionList = await GetCompletionListAsync(service, document, testDocument.CursorPosition.Value, CompletionTrigger.Invoke); var completionList = await GetCompletionListAsync(service, document, testDocument.CursorPosition.Value, CompletionTrigger.Invoke);
var completionItem = completionList.Items.Where(c => c.DisplayText == "M(in int x)").Single(); var completionItem = completionList.Items.Where(c => c.DisplayText == "M(in int x)").Single();
var commit = await service.GetChangeAsync(document, completionItem, commitKey: null, CancellationToken.None); var commit = await service.GetChangeAsync(document, completionItem, completionList.Span, commitKey: null, CancellationToken.None);
var text = await document.GetTextAsync(); var text = await document.GetTextAsync();
var newText = text.WithChanges(commit.TextChange); var newText = text.WithChanges(commit.TextChange);
......
...@@ -339,7 +339,8 @@ private async Task VerifyCustomCommitProviderCheckResultsAsync(Document document ...@@ -339,7 +339,8 @@ private async Task VerifyCustomCommitProviderCheckResultsAsync(Document document
var textBuffer = WorkspaceFixture.CurrentDocument.TextBuffer; var textBuffer = WorkspaceFixture.CurrentDocument.TextBuffer;
var service = GetCompletionService(workspace); var service = GetCompletionService(workspace);
var items = (await GetCompletionListAsync(service, document, position, RoslynCompletion.CompletionTrigger.Invoke)).Items; var completionLlist = await GetCompletionListAsync(service, document, position, RoslynCompletion.CompletionTrigger.Invoke);
var items = completionLlist.Items;
var firstItem = items.First(i => CompareItems(i.DisplayText, itemToCommit)); var firstItem = items.First(i => CompareItems(i.DisplayText, itemToCommit));
if (service.GetTestAccessor().ExclusiveProviders?[0] is ICustomCommitCompletionProvider customCommitCompletionProvider) if (service.GetTestAccessor().ExclusiveProviders?[0] is ICustomCommitCompletionProvider customCommitCompletionProvider)
...@@ -350,7 +351,7 @@ private async Task VerifyCustomCommitProviderCheckResultsAsync(Document document ...@@ -350,7 +351,7 @@ private async Task VerifyCustomCommitProviderCheckResultsAsync(Document document
} }
else else
{ {
await VerifyCustomCommitWorkerAsync(service, document, firstItem, codeBeforeCommit, expectedCodeAfterCommit, commitChar); await VerifyCustomCommitWorkerAsync(service, document, firstItem, completionLlist.Span, codeBeforeCommit, expectedCodeAfterCommit, commitChar);
} }
} }
...@@ -362,6 +363,7 @@ protected virtual void SetWorkspaceOptions(TestWorkspace workspace) ...@@ -362,6 +363,7 @@ protected virtual void SetWorkspaceOptions(TestWorkspace workspace)
CompletionServiceWithProviders service, CompletionServiceWithProviders service,
Document document, Document document,
RoslynCompletion.CompletionItem completionItem, RoslynCompletion.CompletionItem completionItem,
TextSpan completionListSpan,
string codeBeforeCommit, string codeBeforeCommit,
string expectedCodeAfterCommit, string expectedCodeAfterCommit,
char? commitChar = null) char? commitChar = null)
...@@ -379,7 +381,7 @@ protected virtual void SetWorkspaceOptions(TestWorkspace workspace) ...@@ -379,7 +381,7 @@ protected virtual void SetWorkspaceOptions(TestWorkspace workspace)
// changes to document, so the cursor position is tracked correctly. // changes to document, so the cursor position is tracked correctly.
var textView = WorkspaceFixture.CurrentDocument.GetTextView(); var textView = WorkspaceFixture.CurrentDocument.GetTextView();
var commit = await service.GetChangeAsync(document, completionItem, commitChar, CancellationToken.None); var commit = await service.GetChangeAsync(document, completionItem, completionListSpan, commitChar, CancellationToken.None);
var text = await document.GetTextAsync(); var text = await document.GetTextAsync();
var newText = text.WithChanges(commit.TextChange); var newText = text.WithChanges(commit.TextChange);
...@@ -452,7 +454,8 @@ protected virtual void SetWorkspaceOptions(TestWorkspace workspace) ...@@ -452,7 +454,8 @@ protected virtual void SetWorkspaceOptions(TestWorkspace workspace)
var textSnapshot = textBuffer.CurrentSnapshot.AsText(); var textSnapshot = textBuffer.CurrentSnapshot.AsText();
var service = GetCompletionService(workspace); var service = GetCompletionService(workspace);
var items = (await GetCompletionListAsync(service, document, position, RoslynCompletion.CompletionTrigger.Invoke)).Items; var completionList = await GetCompletionListAsync(service, document, position, RoslynCompletion.CompletionTrigger.Invoke);
var items = completionList.Items;
var firstItem = items.First(i => CompareItems(i.DisplayText + i.DisplayTextSuffix, itemToCommit)); var firstItem = items.First(i => CompareItems(i.DisplayText + i.DisplayTextSuffix, itemToCommit));
var completionRules = GetCompletionHelper(document); var completionRules = GetCompletionHelper(document);
...@@ -463,7 +466,7 @@ protected virtual void SetWorkspaceOptions(TestWorkspace workspace) ...@@ -463,7 +466,7 @@ protected virtual void SetWorkspaceOptions(TestWorkspace workspace)
if (commitChar == '\t' || if (commitChar == '\t' ||
CommitManager.IsCommitCharacter(service.GetRules(), firstItem, commitChar, textTypedSoFar + commitChar)) CommitManager.IsCommitCharacter(service.GetRules(), firstItem, commitChar, textTypedSoFar + commitChar))
{ {
var textChange = (await service.GetChangeAsync(document, firstItem, commitChar, CancellationToken.None)).TextChange; var textChange = (await service.GetChangeAsync(document, firstItem, completionList.Span, commitChar, CancellationToken.None)).TextChange;
// Adjust TextChange to include commit character, so long as it isn't TAB. // Adjust TextChange to include commit character, so long as it isn't TAB.
if (commitChar != '\t') if (commitChar != '\t')
......
...@@ -157,7 +157,7 @@ private HashSet<string> GetNamespacesInScope(Document document, SyntaxContext sy ...@@ -157,7 +157,7 @@ private HashSet<string> GetNamespacesInScope(Document document, SyntaxContext sy
return namespacesInScope; return namespacesInScope;
} }
public override async Task<CompletionChange> GetChangeAsync(Document document, CompletionItem completionItem, char? commitKey = default, CancellationToken cancellationToken = default) internal override async Task<CompletionChange> GetChangeAsync(Document document, CompletionItem completionItem, TextSpan completionListSpan, char? commitKey, CancellationToken cancellationToken)
{ {
var containingNamespace = TypeImportCompletionItem.GetContainingNamespace(completionItem); var containingNamespace = TypeImportCompletionItem.GetContainingNamespace(completionItem);
Debug.Assert(containingNamespace != null); Debug.Assert(containingNamespace != null);
...@@ -167,7 +167,7 @@ public override async Task<CompletionChange> GetChangeAsync(Document document, C ...@@ -167,7 +167,7 @@ public override async Task<CompletionChange> GetChangeAsync(Document document, C
// Find context node so we can use it to decide where to insert using/imports. // Find context node so we can use it to decide where to insert using/imports.
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false); var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);
var addImportContextNode = root.FindToken(completionItem.Span.Start, findInsideTrivia: true).Parent; var addImportContextNode = root.FindToken(completionListSpan.Start, findInsideTrivia: true).Parent;
// Add required using/imports directive. // Add required using/imports directive.
var addImportService = document.GetLanguageService<IAddImportsService>(); var addImportService = document.GetLanguageService<IAddImportsService>();
...@@ -198,7 +198,7 @@ public override async Task<CompletionChange> GetChangeAsync(Document document, C ...@@ -198,7 +198,7 @@ public override async Task<CompletionChange> GetChangeAsync(Document document, C
// above, we will get a TextChange of "AsnEncodedDat" with 0 length span, instead of a change of // above, we will get a TextChange of "AsnEncodedDat" with 0 length span, instead of a change of
// the full display text with a span of length 1. This will later mess up span-tracking and end up // the full display text with a span of length 1. This will later mess up span-tracking and end up
// with "AsnEncodedDatasd" in the code. // with "AsnEncodedDatasd" in the code.
builder.Add(new TextChange(completionItem.Span, completionItem.DisplayText)); builder.Add(new TextChange(completionListSpan, completionItem.DisplayText));
// Then get the combined change // Then get the combined change
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
...@@ -211,7 +211,7 @@ public override async Task<CompletionChange> GetChangeAsync(Document document, C ...@@ -211,7 +211,7 @@ public override async Task<CompletionChange> GetChangeAsync(Document document, C
// For workspace that doesn't support document change, e.g. DebuggerIntellisense // For workspace that doesn't support document change, e.g. DebuggerIntellisense
// we complete the type name in its fully qualified form instead. // we complete the type name in its fully qualified form instead.
var fullyQualifiedName = containingNamespace + completionItem.DisplayText; var fullyQualifiedName = containingNamespace + completionItem.DisplayText;
var change = new TextChange(completionItem.Span, fullyQualifiedName); var change = new TextChange(completionListSpan, fullyQualifiedName);
return CompletionChange.Create(change); return CompletionChange.Create(change);
} }
......
...@@ -153,7 +153,7 @@ private async Task CheckTokenAsync(CodeFixContext context, Document document, Sy ...@@ -153,7 +153,7 @@ private async Task CheckTokenAsync(CodeFixContext context, Document document, Sy
continue; continue;
} }
var insertionText = await GetInsertionTextAsync(document, item, cancellationToken: cancellationToken).ConfigureAwait(false); var insertionText = await GetInsertionTextAsync(document, item, completionList.Span, cancellationToken: cancellationToken).ConfigureAwait(false);
results.Add(matchCost, insertionText); results.Add(matchCost, insertionText);
} }
...@@ -178,10 +178,10 @@ private async Task CheckTokenAsync(CodeFixContext context, Document document, Sy ...@@ -178,10 +178,10 @@ private async Task CheckTokenAsync(CodeFixContext context, Document document, Sy
} }
} }
private async Task<string> GetInsertionTextAsync(Document document, CompletionItem item, CancellationToken cancellationToken) private async Task<string> GetInsertionTextAsync(Document document, CompletionItem item, TextSpan completionListSpan, CancellationToken cancellationToken)
{ {
var service = CompletionService.GetService(document); var service = CompletionService.GetService(document);
var change = await service.GetChangeAsync(document, item, null, cancellationToken).ConfigureAwait(false); var change = await service.GetChangeAsync(document, item, completionListSpan, commitCharacter: null, cancellationToken).ConfigureAwait(false);
return change.TextChange.NewText; return change.TextChange.NewText;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册