|
5 | 5 | using System.Collections.Generic;
|
6 | 6 | using System.Collections.Immutable;
|
7 | 7 | using System.Linq;
|
| 8 | +using Microsoft.CodeAnalysis.PooledObjects; |
8 | 9 | using Microsoft.CodeAnalysis.Tags;
|
9 | 10 | using Roslyn.Utilities;
|
10 | 11 |
|
@@ -44,7 +45,7 @@ public static CompletionItem Create(
|
44 | 45 |
|
45 | 46 | if (!description.IsDefault && description.Length > 0)
|
46 | 47 | {
|
47 |
| - properties = properties.NullToEmpty().Add(KeyValuePair.Create(DescriptionProperty, EncodeDescription(description.ToTaggedText()))); |
| 48 | + properties = properties.NullToEmpty().Add(KeyValuePair.Create(DescriptionProperty, EncodeDescription(description.ToTagsAndText()))); |
48 | 49 | }
|
49 | 50 |
|
50 | 51 | return CompletionItem.CreateInternal(
|
@@ -77,8 +78,25 @@ public static CompletionDescription GetDescription(CompletionItem item)
|
77 | 78 |
|
78 | 79 | private static readonly char[] s_descriptionSeparators = ['|'];
|
79 | 80 |
|
80 |
| - private static string EncodeDescription(ImmutableArray<TaggedText> description) |
81 |
| - => string.Join("|", description.SelectMany(d => new[] { d.Tag, d.Text }).Select(t => t.Escape('\\', s_descriptionSeparators))); |
| 81 | + private static string EncodeDescription(ImmutableArray<(string tag, string text)> description) |
| 82 | + { |
| 83 | + using var _ = PooledStringBuilder.GetInstance(out var builder); |
| 84 | + |
| 85 | + foreach (var (tag, text) in description) |
| 86 | + { |
| 87 | + var escapedTag = tag.Escape('\\', s_descriptionSeparators); |
| 88 | + var escapedText = text.Escape('\\', s_descriptionSeparators); |
| 89 | + |
| 90 | + if (builder.Length > 0) |
| 91 | + builder.Append('|'); |
| 92 | + |
| 93 | + builder.Append(escapedTag); |
| 94 | + builder.Append('|'); |
| 95 | + builder.Append(escapedText); |
| 96 | + } |
| 97 | + |
| 98 | + return builder.ToString(); |
| 99 | + } |
82 | 100 |
|
83 | 101 | private static CompletionDescription DecodeDescription(string encoded)
|
84 | 102 | {
|
|
0 commit comments