-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove an enumerator allocation in SymbolCompletionItem.CreateWorker #76375
Merged
ToddGrun
merged 1 commit into
dotnet:main
from
ToddGrun:dev/toddgrun/RemoveEnumeratorAllocationInSymbolCompletionItem.CreateWorker
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,17 +22,17 @@ internal static class SymbolCompletionItem | |
{ | ||
private const string InsertionTextProperty = "InsertionText"; | ||
|
||
private static readonly Action<IReadOnlyList<ISymbol>, ArrayBuilder<KeyValuePair<string, string>>> s_addSymbolEncoding = AddSymbolEncoding; | ||
private static readonly Action<IReadOnlyList<ISymbol>, ArrayBuilder<KeyValuePair<string, string>>> s_addSymbolInfo = AddSymbolInfo; | ||
private static readonly Action<ImmutableArray<ISymbol>, ArrayBuilder<KeyValuePair<string, string>>> s_addSymbolEncoding = AddSymbolEncoding; | ||
private static readonly Action<ImmutableArray<ISymbol>, ArrayBuilder<KeyValuePair<string, string>>> s_addSymbolInfo = AddSymbolInfo; | ||
private static readonly char[] s_projectSeperators = [';']; | ||
|
||
private static CompletionItem CreateWorker( | ||
string displayText, | ||
string? displayTextSuffix, | ||
IReadOnlyList<ISymbol> symbols, | ||
ImmutableArray<ISymbol> symbols, | ||
CompletionItemRules rules, | ||
int contextPosition, | ||
Action<IReadOnlyList<ISymbol>, ArrayBuilder<KeyValuePair<string, string>>> symbolEncoder, | ||
Action<ImmutableArray<ISymbol>, ArrayBuilder<KeyValuePair<string, string>>> symbolEncoder, | ||
string? sortText = null, | ||
string? insertionText = null, | ||
string? filterText = null, | ||
|
@@ -50,16 +50,14 @@ private static CompletionItem CreateWorker( | |
builder.AddRange(properties); | ||
|
||
if (insertionText != null) | ||
{ | ||
builder.Add(KeyValuePairUtil.Create(InsertionTextProperty, insertionText)); | ||
} | ||
|
||
builder.Add(KeyValuePairUtil.Create("ContextPosition", contextPosition.ToString())); | ||
AddSupportedPlatforms(builder, supportedPlatforms); | ||
symbolEncoder(symbols, builder); | ||
|
||
tags = tags.NullToEmpty(); | ||
if (symbols.All(symbol => symbol.IsObsolete()) && !tags.Contains(WellKnownTags.Deprecated)) | ||
if (!tags.Contains(WellKnownTags.Deprecated) && symbols.All(static symbol => symbol.IsObsolete())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
tags = tags.Add(WellKnownTags.Deprecated); | ||
|
||
var firstSymbol = symbols[0]; | ||
|
@@ -80,10 +78,10 @@ private static CompletionItem CreateWorker( | |
return item; | ||
} | ||
|
||
private static void AddSymbolEncoding(IReadOnlyList<ISymbol> symbols, ArrayBuilder<KeyValuePair<string, string>> properties) | ||
private static void AddSymbolEncoding(ImmutableArray<ISymbol> symbols, ArrayBuilder<KeyValuePair<string, string>> properties) | ||
=> properties.Add(KeyValuePairUtil.Create("Symbols", EncodeSymbols(symbols))); | ||
|
||
private static void AddSymbolInfo(IReadOnlyList<ISymbol> symbols, ArrayBuilder<KeyValuePair<string, string>> properties) | ||
private static void AddSymbolInfo(ImmutableArray<ISymbol> symbols, ArrayBuilder<KeyValuePair<string, string>> properties) | ||
{ | ||
var symbol = symbols[0]; | ||
var isGeneric = symbol.GetArity() > 0; | ||
|
@@ -107,13 +105,13 @@ public static bool GetShouldProvideParenthesisCompletion(CompletionItem item) | |
return false; | ||
} | ||
|
||
public static string EncodeSymbols(IReadOnlyList<ISymbol> symbols) | ||
public static string EncodeSymbols(ImmutableArray<ISymbol> symbols) | ||
{ | ||
if (symbols.Count > 1) | ||
if (symbols.Length > 1) | ||
{ | ||
return string.Join("|", symbols.Select(EncodeSymbol)); | ||
} | ||
else if (symbols.Count == 1) | ||
else if (symbols.Length == 1) | ||
{ | ||
return EncodeSymbol(symbols[0]); | ||
} | ||
|
@@ -270,7 +268,7 @@ public static bool TryGetInsertionText(CompletionItem item, [NotNullWhen(true)] | |
// COMPAT OVERLOAD: This is used by IntelliCode. | ||
public static CompletionItem CreateWithSymbolId( | ||
string displayText, | ||
IReadOnlyList<ISymbol> symbols, | ||
ImmutableArray<ISymbol> symbols, | ||
CompletionItemRules rules, | ||
int contextPosition, | ||
string? sortText = null, | ||
|
@@ -302,7 +300,7 @@ public static CompletionItem CreateWithSymbolId( | |
public static CompletionItem CreateWithSymbolId( | ||
string displayText, | ||
string? displayTextSuffix, | ||
IReadOnlyList<ISymbol> symbols, | ||
ImmutableArray<ISymbol> symbols, | ||
CompletionItemRules rules, | ||
int contextPosition, | ||
string? sortText = null, | ||
|
@@ -326,7 +324,7 @@ public static CompletionItem CreateWithSymbolId( | |
public static CompletionItem CreateWithNameAndKind( | ||
string displayText, | ||
string displayTextSuffix, | ||
IReadOnlyList<ISymbol> symbols, | ||
ImmutableArray<ISymbol> symbols, | ||
CompletionItemRules rules, | ||
int contextPosition, | ||
string? sortText = null, | ||
|
@@ -357,12 +355,12 @@ internal static bool GetSymbolIsGeneric(CompletionItem item) | |
=> item.TryGetProperty("IsGeneric", out var v) && bool.TryParse(v, out var isGeneric) && isGeneric; | ||
|
||
public static async Task<CompletionDescription> GetDescriptionAsync( | ||
CompletionItem item, IReadOnlyList<ISymbol> symbols, Document document, SemanticModel semanticModel, SymbolDescriptionOptions options, CancellationToken cancellationToken) | ||
CompletionItem item, ImmutableArray<ISymbol> symbols, Document document, SemanticModel semanticModel, SymbolDescriptionOptions options, CancellationToken cancellationToken) | ||
{ | ||
var position = GetDescriptionPosition(item); | ||
var supportedPlatforms = GetSupportedPlatforms(item, document.Project.Solution); | ||
|
||
if (symbols.Count != 0) | ||
if (symbols.Length != 0) | ||
{ | ||
return await CommonCompletionUtilities.CreateDescriptionAsync(document.Project.Solution.Services, semanticModel, position, symbols, options, supportedPlatforms, cancellationToken).ConfigureAwait(false); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
using Microsoft.CodeAnalysis.LanguageService; | ||
using Microsoft.CodeAnalysis.Shared.Utilities; | ||
using Microsoft.CodeAnalysis.Text; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Pythia.Api; | ||
|
||
|
@@ -42,7 +43,7 @@ public static CompletionItem CreateSymbolCompletionItem( | |
SupportedPlatformData? supportedPlatforms = null, | ||
ImmutableDictionary<string, string>? properties = null, | ||
ImmutableArray<string> tags = default) | ||
=> SymbolCompletionItem.CreateWithSymbolId(displayText, displayTextSuffix: null, symbols, rules, contextPosition, sortText, insertionText, | ||
=> SymbolCompletionItem.CreateWithSymbolId(displayText, displayTextSuffix: null, symbols.ToImmutableArray(), rules, contextPosition, sortText, insertionText, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
filterText, displayTextPrefix: null, inlineDescription: null, glyph: null, supportedPlatforms, properties.AsImmutableOrNull(), tags); | ||
|
||
public static ImmutableArray<SymbolDisplayPart> CreateRecommendedKeywordDisplayParts(string keyword, string toolTip) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These don't appear to be used anymore.