private TextSpan ComputeReplacementSpan(CompletionItem completionItem, SourceText text) { var currentSpan = completionItem.Span; var beforeCaretText = XmlDocCommentCompletionItem.GetBeforeCaretText(completionItem); return(TextSpan.FromBounds(text[currentSpan.Start - 1] == '<' && beforeCaretText[0] == '<' ? currentSpan.Start - 1 : currentSpan.Start, currentSpan.End)); }
public override async Task <CompletionChange> GetChangeAsync(Document document, CompletionItem item, char?commitChar = default(char?), CancellationToken cancellationToken = default(CancellationToken)) { var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var beforeCaretText = XmlDocCommentCompletionItem.GetBeforeCaretText(item); var afterCaretText = XmlDocCommentCompletionItem.GetAfterCaretText(item); var itemSpan = item.Span; var replacementSpan = TextSpan.FromBounds(text[itemSpan.Start - 1] == '<' && beforeCaretText[0] == '<' ? itemSpan.Start - 1 : itemSpan.Start, itemSpan.End); var replacementText = beforeCaretText; var newPosition = replacementSpan.Start + beforeCaretText.Length; if (commitChar.HasValue && !char.IsWhiteSpace(commitChar.Value) && commitChar.Value != replacementText[replacementText.Length - 1]) { // include the commit character replacementText += commitChar.Value; // The caret goes after whatever commit character we spit. newPosition++; } replacementText += afterCaretText; return(CompletionChange.Create(ImmutableArray.Create(new TextChange(replacementSpan, replacementText)), newPosition, includesCommitCharacter: true)); }
protected CompletionItem CreateCompletionItem(TextSpan span, string displayText, string beforeCaretText, string afterCaretText) { return(XmlDocCommentCompletionItem.Create( span, displayText, beforeCaretText, afterCaretText, rules: GetCompletionItemRules(displayText))); }