-
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
Change SupportedPlatformData to use ImmutableArrays #76658
Merged
ToddGrun
merged 2 commits into
dotnet:main
from
ToddGrun:ImmutableDataStructuresInSupportedPlatformData2
Jan 7, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,8 +98,8 @@ private ImmutableArray<CompletionItem> CreateItems( | |
CompletionContext completionContext, | ||
ImmutableArray<SymbolAndSelectionInfo> symbols, | ||
Func<SymbolAndSelectionInfo, TSyntaxContext> contextLookup, | ||
Dictionary<ISymbol, List<ProjectId>>? invalidProjectMap, | ||
List<ProjectId>? totalProjects) | ||
Dictionary<ISymbol, ArrayBuilder<ProjectId>>? invalidProjectMap, | ||
ImmutableArray<ProjectId> totalProjects) | ||
{ | ||
// We might get symbol w/o name but CanBeReferencedByName is still set to true, | ||
// need to filter them out. | ||
|
@@ -197,21 +197,21 @@ protected static bool TryFindFirstSymbolMatchesTargetTypes( | |
private static SupportedPlatformData? ComputeSupportedPlatformData( | ||
CompletionContext completionContext, | ||
ImmutableArray<SymbolAndSelectionInfo> symbols, | ||
Dictionary<ISymbol, List<ProjectId>>? invalidProjectMap, | ||
List<ProjectId>? totalProjects) | ||
Dictionary<ISymbol, ArrayBuilder<ProjectId>>? invalidProjectMap, | ||
ImmutableArray<ProjectId> totalProjects) | ||
{ | ||
SupportedPlatformData? supportedPlatformData = null; | ||
if (invalidProjectMap != null) | ||
{ | ||
List<ProjectId>? invalidProjects = null; | ||
ArrayBuilder<ProjectId>? invalidProjects = null; | ||
foreach (var symbol in symbols) | ||
{ | ||
if (invalidProjectMap.TryGetValue(symbol.Symbol, out invalidProjects)) | ||
break; | ||
} | ||
|
||
if (invalidProjects != null) | ||
supportedPlatformData = new SupportedPlatformData(completionContext.Document.Project.Solution, invalidProjects, totalProjects); | ||
supportedPlatformData = new SupportedPlatformData(completionContext.Document.Project.Solution, invalidProjects.ToImmutable(), totalProjects); | ||
} | ||
|
||
return supportedPlatformData; | ||
|
@@ -299,7 +299,7 @@ private async Task<ImmutableArray<CompletionItem>> GetItemsAsync( | |
if (relatedDocumentIds.IsEmpty) | ||
{ | ||
var itemsForCurrentDocument = await GetSymbolsAsync(completionContext, syntaxContext, position, options, cancellationToken).ConfigureAwait(false); | ||
return CreateItems(completionContext, itemsForCurrentDocument, _ => syntaxContext, invalidProjectMap: null, totalProjects: null); | ||
return CreateItems(completionContext, itemsForCurrentDocument, _ => syntaxContext, invalidProjectMap: null, totalProjects: []); | ||
} | ||
|
||
using var _ = PooledDictionary<DocumentId, int>.GetInstance(out var documentIdToIndex); | ||
|
@@ -315,10 +315,15 @@ private async Task<ImmutableArray<CompletionItem>> GetItemsAsync( | |
|
||
var symbolToContextMap = UnionSymbols(contextAndSymbolLists); | ||
var missingSymbolsMap = FindSymbolsMissingInLinkedContexts(symbolToContextMap, contextAndSymbolLists); | ||
var totalProjects = contextAndSymbolLists.Select(t => t.documentId.ProjectId).ToList(); | ||
var totalProjects = contextAndSymbolLists.SelectAsArray(t => t.documentId.ProjectId); | ||
|
||
return CreateItems( | ||
var items = CreateItems( | ||
completionContext, [.. symbolToContextMap.Keys], symbol => symbolToContextMap[symbol], missingSymbolsMap, totalProjects); | ||
|
||
foreach (var (_, builder) in missingSymbolsMap) | ||
builder.Free(); | ||
|
||
return items; | ||
} | ||
|
||
protected virtual bool IsExclusive() | ||
|
@@ -395,17 +400,17 @@ protected async Task<ImmutableArray<SymbolAndSelectionInfo>> TryGetSymbolsForCon | |
/// <param name="symbolToContext">The symbols recommended in the active context.</param> | ||
/// <param name="linkedContextSymbolLists">The symbols recommended in linked documents</param> | ||
/// <returns>The list of projects each recommended symbol did NOT appear in.</returns> | ||
private static Dictionary<ISymbol, List<ProjectId>> FindSymbolsMissingInLinkedContexts( | ||
private static Dictionary<ISymbol, ArrayBuilder<ProjectId>> FindSymbolsMissingInLinkedContexts( | ||
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. Does the consumer return these? 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. caller (line 317) owns the freeing of these builders |
||
Dictionary<SymbolAndSelectionInfo, TSyntaxContext> symbolToContext, | ||
ImmutableArray<(DocumentId documentId, TSyntaxContext syntaxContext, ImmutableArray<SymbolAndSelectionInfo> symbols)> linkedContextSymbolLists) | ||
{ | ||
var missingSymbols = new Dictionary<ISymbol, List<ProjectId>>(LinkedFilesSymbolEquivalenceComparer.Instance); | ||
var missingSymbols = new Dictionary<ISymbol, ArrayBuilder<ProjectId>>(LinkedFilesSymbolEquivalenceComparer.Instance); | ||
|
||
foreach (var (documentId, syntaxContext, symbols) in linkedContextSymbolLists) | ||
{ | ||
var symbolsMissingInLinkedContext = symbolToContext.Keys.Except(symbols); | ||
foreach (var (symbol, _) in symbolsMissingInLinkedContext) | ||
missingSymbols.GetOrAdd(symbol, m => []).Add(documentId.ProjectId); | ||
missingSymbols.GetOrAdd(symbol, m => ArrayBuilder<ProjectId>.GetInstance()).Add(documentId.ProjectId); | ||
} | ||
|
||
return missingSymbols; | ||
|
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
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.
Preference is the using form for me
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.
Will change the other ones, I don't think this one can be changed as it doesn't own the builders.