private async Task VerifyProviderCommitCheckResultsAsync(Document document, int position, string itemToCommit, string expectedCodeAfterCommit, char?commitCharOpt, string textTypedSoFar) { var textBuffer = (await WorkspaceFixture.GetWorkspaceAsync()).Documents.Single().TextBuffer; var textSnapshot = textBuffer.CurrentSnapshot.AsText(); var items = (await GetCompletionListAsync(document, position, CompletionTrigger.Default)).Items; var firstItem = items.First(i => CompareItems(i.DisplayText, itemToCommit)); var completionRules = GetCompletionHelper(document); var commitChar = commitCharOpt ?? '\t'; var text = await document.GetTextAsync(); if (commitChar == '\t' || completionRules.IsCommitCharacter(firstItem, commitChar, textTypedSoFar)) { var textChange = CompletionHelper.GetTextChangeAsync(document, firstItem, commitChar).Result; // Adjust TextChange to include commit character, so long as it isn't TAB. if (commitChar != '\t') { textChange = new TextChange(textChange.Span, textChange.NewText.TrimEnd(commitChar) + commitChar); } text = text.WithChanges(textChange); } else { // nothing was committed, but we should insert the commit character. var textChange = new TextChange(new TextSpan(firstItem.Span.End, 0), commitChar.ToString()); text = text.WithChanges(textChange); } Assert.Equal(expectedCodeAfterCommit, text.ToString()); }
public override async Task <CompletionDescription> GetDescriptionAsync(Document document, CancellationToken cancellationToken) { var languageServices = document.Project.LanguageServices; var snippetService = languageServices.GetService <ISnippetInfoService>(); var description = await this.CompletionService.GetDescriptionAsync(document, this.Item, cancellationToken).ConfigureAwait(false); var parts = description.TaggedParts; var change = await CompletionHelper.GetTextChangeAsync(this.CompletionService, document, this.Item, '\t').ConfigureAwait(false); var insertionText = change.NewText; var note = string.Empty; if (snippetService != null && snippetService.SnippetShortcutExists_NonBlocking(insertionText)) { note = string.Format(FeaturesResources.NoteTabTwiceToInsertTheSnippet, insertionText); } if (!string.IsNullOrEmpty(note)) { if (parts.Any()) { parts = parts.Add(new TaggedText(TextTags.LineBreak, Environment.NewLine)); } parts = parts.Add(new TaggedText(TextTags.Text, note)); } return(description.WithTaggedParts(parts)); }