From 72d701e06271669a7eace4c70fe4561002d0080d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 Apr 2024 19:09:05 -0700 Subject: [PATCH 01/37] Switch to ToImmutableAndClear --- .../UseCollectionExpressionHelpers.cs | 2 +- .../ConvertToRecord/ConvertToRecordHelpers.cs | 4 ++-- .../PositionalParameterInfo.cs | 2 +- ...MisplacedUsingDirectivesCodeFixProvider.cs | 2 +- .../UseSimpleUsingStatementCodeFixProvider.cs | 2 +- .../UseCollectionExpressionForBuilderTests.cs | 18 ++++++++--------- ...bstractObjectCreationExpressionAnalyzer.cs | 2 +- .../Core/CodeFixes/AddExplicitCast/Fixer.cs | 2 +- .../AbstractAddParameterCodeFixProvider.cs | 4 ++-- ...derCodeFixProvider.CustomFixAllProvider.cs | 2 +- .../KnownSourcePasteProcessor.cs | 2 +- .../UnknownSourcePasteProcessor.cs | 2 +- .../Core.Wpf/Peek/PeekableItemFactory.cs | 2 +- ...ndentationAdornmentManager.VisibleBlock.cs | 2 +- .../DefinitionContextTracker.cs | 2 +- .../NavigationBar/WrappedNavigationBarItem.cs | 2 +- .../IntelliCode/IntentProcessor.cs | 2 +- .../IntelliSense/AsyncCompletion/FilterSet.cs | 4 ++-- ...igateToHighlightReferenceCommandHandler.cs | 2 +- .../CodeGeneration/CodeGenerationTests.cs | 2 +- .../Snippets/RoslynLSPSnippetConvertTests.cs | 2 +- ...actCurlyBraceOrBracketCompletionService.cs | 2 +- .../CSharpChangeSignatureService.cs | 2 +- .../CodeLens/CSharpCodeLensMemberFinder.cs | 2 +- .../DeclarationNameRecommender.cs | 2 +- .../ConvertProgramTransform_ProgramMain.cs | 2 +- ...vertProgramTransform_TopLevelStatements.cs | 2 +- .../CSharpDocumentHighlightsService.cs | 2 +- ...nerator.MultipleStatementsCodeGenerator.cs | 2 +- ...harpMethodExtractor.CSharpCodeGenerator.cs | 2 +- .../CSharpMethodExtractor.PostProcessor.cs | 2 +- ...SharpGenerateParameterizedMemberService.cs | 4 ++-- .../CSharpStructuralTypeDisplayService.cs | 2 +- .../CSharpLineSeparatorService.cs | 2 +- .../CSharpNavigationBarItemService.cs | 2 +- ...CSharpReplacePropertyWithMethodsService.cs | 2 +- .../CSharpForEachLoopSnippetProvider.cs | 2 +- .../CSharpStringIndentationService.cs | 2 +- ...ionBodyForLambdaCodeRefactoringProvider.cs | 2 +- ...emoveUnnecessaryPragmaSuppressionsTests.cs | 2 +- ...romMembersCodeRefactoringProvider.State.cs | 2 +- ...etersFromMembersCodeRefactoringProvider.cs | 4 ++-- ...actAddFileBannerCodeRefactoringProvider.cs | 2 +- .../AbstractAddImportFeatureService.cs | 8 ++++---- .../InstallPackageAndAddImportCodeAction.cs | 2 +- .../AddImport/SymbolReferenceFinder.cs | 2 +- .../ParentInstallPackageCodeAction.cs | 2 +- .../AbstractChangeSignatureService.cs | 4 ++-- .../DelegateInvokeMethodReferenceFinder.cs | 2 +- .../Configuration/ConfigurationUpdater.cs | 2 +- .../AbstractRefactoringHelpersService.cs | 2 +- ...actExtractMethodCodeRefactoringProvider.cs | 2 +- .../MoveType/AbstractMoveTypeService.cs | 2 +- .../AbstractChangeNamespaceService.cs | 2 +- .../AbstractProjectExtensionProvider.cs | 4 ++-- .../AbstractDocCommentCompletionProvider.cs | 2 +- .../AbstractKeywordCompletionProvider.cs | 2 +- .../AbstractSymbolCompletionProvider.cs | 4 ++-- .../AbstractImportCompletionProvider.cs | 2 +- ...odImportCompletionHelper.SymbolComputer.cs | 4 ++-- .../ExtensionMethodImportCompletionHelper.cs | 2 +- .../TypeImportCompletionCacheEntry.cs | 2 +- ...AbstractLoadDirectiveCompletionProvider.cs | 2 +- ...actReferenceDirectiveCompletionProvider.cs | 2 +- .../GlobalAssemblyCacheCompletionHelper.cs | 2 +- .../Providers/SymbolCompletionItem.cs | 2 +- ...ertTupleToStructCodeRefactoringProvider.cs | 6 +++--- .../DesignerAttributeDiscoveryService.cs | 2 +- .../AbstractEditAndContinueAnalyzer.cs | 2 +- .../EditAndContinue/ActiveStatementsMap.cs | 2 +- .../EditAndContinue/DebuggingSession.cs | 4 ++-- .../EditAndContinueCapabilities.cs | 2 +- .../EditAndContinueDocumentAnalysesCache.cs | 2 +- .../Portable/EditAndContinue/EditSession.cs | 2 +- .../EmitSolutionUpdateResults.cs | 4 ++-- .../EditAndContinue/ProjectDiagnostics.cs | 2 +- .../RemoteEditAndContinueServiceProxy.cs | 2 +- .../EmbeddedLanguages/Json/JsonLexer.cs | 2 +- .../EmbeddedLanguages/Json/JsonParser.cs | 2 +- .../RegularExpressions/RegexLexer.cs | 2 +- .../StackFrame/StackFrameLexer.cs | 2 +- .../AbstractEncapsulateFieldService.cs | 2 +- .../API/UnitTestingSearchHelpers.cs | 4 ++-- .../AbstractExtractInterfaceService.cs | 2 +- .../ExtractMethod/MethodExtractor.Analyzer.cs | 2 +- .../MethodExtractor.CodeGenerator.cs | 2 +- ...bstractFindUsagesService_FindReferences.cs | 2 +- ...parisonOperatorsCodeRefactoringProvider.cs | 2 +- ...uctorFromMembersCodeRefactoringProvider.cs | 4 ++-- ...tractGenerateDefaultConstructorsService.cs | 2 +- ...erateFromMembersCodeRefactoringProvider.cs | 2 +- .../AbstractGenerateConstructorService.cs | 2 +- .../AbstractGenerateMethodService.State.cs | 2 +- ...arameterizedMemberService.SignatureInfo.cs | 2 +- ...tractGenerateParameterizedMemberService.cs | 2 +- .../AbstractGenerateVariableService.cs | 2 +- ...ctGenerateTypeService.GenerateNamedType.cs | 2 +- .../AbstractGenerateTypeService.cs | 4 ++-- .../GoToDefinitionFeatureHelpers.cs | 2 +- .../ImplementAbstractClassData.cs | 2 +- ...actImplementInterfaceService.CodeAction.cs | 2 +- .../ImplementInterface/ImplementHelpers.cs | 2 +- ...bstractInheritanceMarginService_Helpers.cs | 8 ++++---- ...erCodeRefactoringProviderMemberCreation.cs | 4 ++-- .../InitializeParameterHelpersCore.cs | 2 +- ...AbstractInlineParameterNameHintsService.cs | 2 +- .../AbstractInlineTypeHintsService.cs | 2 +- ...efactoringProvider.MethodParametersInfo.cs | 2 +- ...AbstractInvertIfCodeRefactoringProvider.cs | 2 +- .../AbstractStructuralTypeDisplayService.cs | 4 ++-- ...dataAsSourceService.DocCommentFormatter.cs | 2 +- .../AbstractMoveToNamespaceCodeAction.cs | 2 +- ...stractNavigateToSearchService.InProcess.cs | 2 +- .../Portable/NavigateTo/NavigateToSearcher.cs | 2 +- .../DocumentDebugInfoReader.cs | 2 +- ...rceDocumentMetadataAsSourceFileProvider.cs | 2 +- ...thodWithPropertyCodeRefactoringProvider.cs | 2 +- ...pertyWithMethodsCodeRefactoringProvider.cs | 2 +- .../Shared/Utilities/ExtractTypeHelpers.cs | 4 ++-- .../AbstractSignatureHelpProvider.cs | 2 +- .../Snippets/AbstractSnippetService.cs | 2 +- .../AbstractSpellCheckSpanService.cs | 2 +- .../StackTraceExplorer/StackTraceAnalyzer.cs | 2 +- .../TaskList/AbstractTaskListService.cs | 2 +- .../UnusedReferencesRemover.cs | 6 +++--- .../Workspace/CompileTimeSolutionProvider.cs | 2 +- .../AbstractBinaryExpressionWrapper.cs | 2 +- .../BinaryExpressionCodeActionComputer.cs | 4 ++-- .../AbstractChainedExpressionWrapper.cs | 2 +- .../ChainedExpressionCodeActionComputer.cs | 4 ++-- .../SeparatedSyntaxListCodeActionComputer.cs | 6 +++--- .../Testing/TestDiscoverer.cs | 2 +- .../Features/CodeFixes/CodeFixService.cs | 4 ++-- ...ntalAnalyzer.StateManager.ProjectStates.cs | 2 +- ...crementalAnalyzer_GetDiagnosticsForSpan.cs | 2 +- ...IncrementalAnalyzer_IncrementalAnalyzer.cs | 2 +- .../UnifiedSuggestedActionsSource.cs | 2 +- .../Handler/CodeActions/CodeActionHelpers.cs | 4 ++-- ...dChangeConfigurationNotificationHandler.cs | 4 ++-- ...AbstractWorkspacePullDiagnosticsHandler.cs | 4 ++-- .../Handler/MapCode/MapCodeHandler.cs | 2 +- .../SpellCheck/WorkspaceSpellCheckHandler.cs | 2 +- .../Workspaces/LspWorkspaceManager.cs | 2 +- .../ActiveStatementsDescription.cs | 2 +- .../DocumentOutline/DocumentOutlineTests.cs | 2 +- .../RemoteCodeLensReferencesService.cs | 2 +- .../DocumentOutlineViewModel_Utilities.cs | 4 ++-- .../InheritanceMarginHelpers.cs | 2 +- .../ObjectBrowser/AbstractListItemFactory.cs | 20 +++++++++---------- .../PackageInstallerServiceFactory.cs | 2 +- .../Core/Def/Progression/GraphProvider.cs | 2 +- .../GraphQueries/CallsGraphQuery.cs | 2 +- .../Core/Def/Progression/SymbolContainment.cs | 2 +- .../Snippets/AbstractSnippetInfoService.cs | 2 +- ...ioDiagnosticListSuppressionStateService.cs | 2 +- .../VisualStudioSuppressionFixService.cs | 2 +- .../ExternalErrorDiagnosticUpdateSource.cs | 4 ++-- .../Services/ServiceHubServicesTests.cs | 2 +- .../CSharpRecommendationServiceRunner.cs | 2 +- .../CSharpRenameRewriterLanguageService.cs | 2 +- .../Core/MSBuild.BuildHost/BuildHost.cs | 2 +- .../MSBuild/ProjectFile/ProjectFile.cs | 2 +- .../MSBuild/MSBuildProjectLoader.Worker.cs | 4 ++-- ...dProjectLoader.Worker_ResolveReferences.cs | 4 ++-- .../FixAllOccurrences/BatchFixAllProvider.cs | 4 ++-- .../Diagnostics/DiagnosticAnalysisResult.cs | 2 +- .../Core/Portable/Diagnostics/Extensions.cs | 4 ++-- .../DeclarationFinder_AllDeclarations.cs | 2 +- .../DeclarationFinder_SourceDeclarations.cs | 4 ++-- .../DependentTypeFinder_Remote.cs | 2 +- .../FindReferences/FindReferenceCache.cs | 4 ++-- ...dOrPropertyOrEventSymbolReferenceFinder.cs | 2 +- .../Finders/AbstractReferenceFinder.cs | 10 +++++----- ...tractReferenceFinder_GlobalSuppressions.cs | 2 +- ...tractTypeParameterSymbolReferenceFinder.cs | 2 +- .../ConstructorSymbolReferenceFinder.cs | 4 ++-- ...ExplicitConversionSymbolReferenceFinder.cs | 2 +- .../Finders/NamedTypeSymbolReferenceFinder.cs | 4 ++-- .../Finders/NamespaceSymbolReferenceFinder.cs | 4 ++-- .../Finders/ParameterSymbolReferenceFinder.cs | 2 +- .../Finders/PropertySymbolReferenceFinder.cs | 2 +- .../FindSymbols/StreamingProgressCollector.cs | 2 +- ...SymbolFinder_Declarations_CustomQueries.cs | 2 +- .../AbstractReassignedVariableService.cs | 2 +- .../AbstractRecommendationServiceRunner.cs | 4 ++-- .../Core/Portable/Remote/RemoteUtilities.cs | 2 +- .../Rename/SymbolicRenameLocations.cs | 2 +- .../Extensions/IAsyncEnumerableExtensions.cs | 2 +- .../IFindReferencesResultExtensions.cs | 2 +- .../Extensions/ITypeSymbolExtensions.cs | 2 +- .../Extensions/SyntaxGeneratorExtensions.cs | 4 ++-- ...xGeneratorExtensions_CreateEqualsMethod.cs | 4 ++-- .../TaskList/TaskListItemDescriptor.cs | 2 +- .../AbstractSpanMappingService.cs | 2 +- .../DiagnosticAnalyzer/DiagnosticComputer.cs | 6 +++--- .../SymbolFinder/RemoteSymbolFinderService.cs | 2 +- .../SemanticFacts/CSharpSemanticFacts.cs | 2 +- .../Core/Extensions/ICollectionExtensions.cs | 2 +- .../TriviaEngine/AbstractTriviaFormatter.cs | 2 +- .../AbstractSelectedMembers.cs | 2 +- .../SymbolKey/SymbolKey.BodyLevelSymbolKey.cs | 2 +- .../SymbolKey/SymbolKey.ErrorTypeSymbolKey.cs | 2 +- .../CodeGeneration/ParameterGenerator.cs | 2 +- .../TypeDeclarationSyntaxExtensions.cs | 2 +- .../Core/Editing/AddParameterEditor.cs | 2 +- 205 files changed, 277 insertions(+), 277 deletions(-) diff --git a/src/Analyzers/CSharp/Analyzers/UseCollectionExpression/UseCollectionExpressionHelpers.cs b/src/Analyzers/CSharp/Analyzers/UseCollectionExpression/UseCollectionExpressionHelpers.cs index 30ce3438410cd..91530f6c07c7c 100644 --- a/src/Analyzers/CSharp/Analyzers/UseCollectionExpression/UseCollectionExpressionHelpers.cs +++ b/src/Analyzers/CSharp/Analyzers/UseCollectionExpression/UseCollectionExpressionHelpers.cs @@ -906,7 +906,7 @@ public static ImmutableArray> TryGetM return default; } - return matches.ToImmutable(); + return matches.ToImmutableAndClear(); } public static bool IsCollectionFactoryCreate( diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/ConvertToRecordHelpers.cs b/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/ConvertToRecordHelpers.cs index 6bbb4a68f93a3..7778a8ec53176 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/ConvertToRecordHelpers.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/ConvertToRecordHelpers.cs @@ -533,7 +533,7 @@ private static ImmutableArray GetEqualizedFields( value, successRequirement: true, type, fields, out var _2)) { // we're done, no more statements to check - return fields.ToImmutable(); + return fields.ToImmutableAndClear(); } // check for the first statement as an explicit cast to a variable declaration // like: var otherC = other as C; @@ -557,7 +557,7 @@ private static ImmutableArray GetEqualizedFields( return []; } - return fields.ToImmutable(); + return fields.ToImmutableAndClear(); } /// diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/PositionalParameterInfo.cs b/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/PositionalParameterInfo.cs index 67af4f91edf23..e474aaa85e96c 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/PositionalParameterInfo.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/PositionalParameterInfo.cs @@ -68,7 +68,7 @@ public static ImmutableArray GetPropertiesForPositional _ => throw ExceptionUtilities.Unreachable(), }).WhereNotNull()); - return resultBuilder.ToImmutable(); + return resultBuilder.ToImmutableAndClear(); } public static ImmutableArray GetInheritedPositionalParams( diff --git a/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs index c829b08232f00..f52e61fc4371b 100644 --- a/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs @@ -117,7 +117,7 @@ private static ImmutableArray GetAllUsingDirectives(Compil Recurse(compilationUnit.Members); - return result.ToImmutable(); + return result.ToImmutableAndClear(); void Recurse(SyntaxList members) { diff --git a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs index 17199e80037c5..282bb5ea8acab 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs @@ -104,7 +104,7 @@ private static ImmutableArray Expand(UsingStatementSyntax using for (int i = 0, n = result.Count; i < n; i++) result[i] = result[i].WithAdditionalAnnotations(Formatter.Annotation); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static SyntaxTriviaList Expand(ArrayBuilder result, UsingStatementSyntax usingStatement) diff --git a/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs b/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs index bd0fbe4312df9..40b463561fc63 100644 --- a/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs +++ b/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs @@ -77,7 +77,7 @@ ImmutableArray M() { {{pattern}} builder.Add(0); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } """ + s_arrayBuilderApi, @@ -100,7 +100,7 @@ ImmutableArray M() { {{pattern}} builder.Add(0); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } """ + s_arrayBuilderApi, @@ -123,7 +123,7 @@ ImmutableArray M() { {{pattern}} [|builder.Add(|]0); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } """ + s_arrayBuilderApi, @@ -1256,7 +1256,7 @@ ImmutableArray M() // Leading [|builder.Add(|]0); // Trailing - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } """ + s_arrayBuilderApi, @@ -1295,7 +1295,7 @@ ImmutableArray M() {{pattern}} [|builder.Add(|]1 + 2); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } """ + s_arrayBuilderApi, @@ -1336,7 +1336,7 @@ ImmutableArray M() 2); [|builder.Add(|]3 + 4); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } """ + s_arrayBuilderApi, @@ -1376,7 +1376,7 @@ ImmutableArray M() { using var _ = ArrayBuilder.GetInstance(10, 0, out var builder); builder.Add(0); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } """ + s_arrayBuilderApi, @@ -1540,7 +1540,7 @@ IEnumerable M() { {{pattern}} [|builder.Add(|]0); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } """ + s_arrayBuilderApi, @@ -1577,7 +1577,7 @@ IEnumerable M() { {{pattern}} builder.Add(0); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } """ + s_arrayBuilderApi, diff --git a/src/Analyzers/Core/Analyzers/UseCollectionInitializer/AbstractObjectCreationExpressionAnalyzer.cs b/src/Analyzers/Core/Analyzers/UseCollectionInitializer/AbstractObjectCreationExpressionAnalyzer.cs index ba361e6411ed3..e1cb4dc271488 100644 --- a/src/Analyzers/Core/Analyzers/UseCollectionInitializer/AbstractObjectCreationExpressionAnalyzer.cs +++ b/src/Analyzers/Core/Analyzers/UseCollectionInitializer/AbstractObjectCreationExpressionAnalyzer.cs @@ -84,7 +84,7 @@ protected ImmutableArray AnalyzeWorker(CancellationToken cancellationTok if (!TryAddMatches(matches, cancellationToken)) return default; - return matches.ToImmutable(); + return matches.ToImmutableAndClear(); } protected UpdateExpressionState? TryInitializeState( diff --git a/src/Analyzers/Core/CodeFixes/AddExplicitCast/Fixer.cs b/src/Analyzers/Core/CodeFixes/AddExplicitCast/Fixer.cs index a75028498ced1..11c73c424eac5 100644 --- a/src/Analyzers/Core/CodeFixes/AddExplicitCast/Fixer.cs +++ b/src/Analyzers/Core/CodeFixes/AddExplicitCast/Fixer.cs @@ -73,7 +73,7 @@ protected abstract class Fixer(semanticModel)); - return mutablePotentialConversionTypes.ToImmutable(); + return mutablePotentialConversionTypes.ToImmutableAndClear(); } /// diff --git a/src/Analyzers/Core/CodeFixes/AddParameter/AbstractAddParameterCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/AddParameter/AbstractAddParameterCodeFixProvider.cs index 117b30f2ccd8d..eb9175b371549 100644 --- a/src/Analyzers/Core/CodeFixes/AddParameter/AbstractAddParameterCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/AddParameter/AbstractAddParameterCodeFixProvider.cs @@ -312,7 +312,7 @@ ImmutableArray NestByCascading() builder.Add(CodeAction.Create(nestedCascadingTitle, cascadingActions, isInlinable: false)); } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } @@ -343,7 +343,7 @@ private ImmutableArray PrepareCreationOfCodeActions( builder.Add(codeFixData); } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private static string GetCodeFixTitle(string resourceString, IMethodSymbol methodToUpdate, bool includeParameters) diff --git a/src/Analyzers/Core/CodeFixes/MatchFolderAndNamespace/AbstractChangeNamespaceToMatchFolderCodeFixProvider.CustomFixAllProvider.cs b/src/Analyzers/Core/CodeFixes/MatchFolderAndNamespace/AbstractChangeNamespaceToMatchFolderCodeFixProvider.CustomFixAllProvider.cs index b8455ab05fb41..3a25c37639087 100644 --- a/src/Analyzers/Core/CodeFixes/MatchFolderAndNamespace/AbstractChangeNamespaceToMatchFolderCodeFixProvider.CustomFixAllProvider.cs +++ b/src/Analyzers/Core/CodeFixes/MatchFolderAndNamespace/AbstractChangeNamespaceToMatchFolderCodeFixProvider.CustomFixAllProvider.cs @@ -63,7 +63,7 @@ static async Task> GetSolutionDiagnosticsAsync(FixAll diagnostics.AddRange(projectDiagnostics); } - return diagnostics.ToImmutable(); + return diagnostics.ToImmutableAndClear(); } } diff --git a/src/EditorFeatures/CSharp/StringCopyPaste/KnownSourcePasteProcessor.cs b/src/EditorFeatures/CSharp/StringCopyPaste/KnownSourcePasteProcessor.cs index 27f9e58606bf2..52b8c4ba21028 100644 --- a/src/EditorFeatures/CSharp/StringCopyPaste/KnownSourcePasteProcessor.cs +++ b/src/EditorFeatures/CSharp/StringCopyPaste/KnownSourcePasteProcessor.cs @@ -221,7 +221,7 @@ private ImmutableArray DetermineTotalEditsToMakeToRawString( if (quotesToAdd != null) edits.Add(new TextChange(new TextSpan(StringExpressionBeforePasteInfo.EndDelimiterSpanWithoutSuffix.End, 0), quotesToAdd)); - return edits.ToImmutable(); + return edits.ToImmutableAndClear(); } private void UpdateExistingInterpolationBraces( diff --git a/src/EditorFeatures/CSharp/StringCopyPaste/UnknownSourcePasteProcessor.cs b/src/EditorFeatures/CSharp/StringCopyPaste/UnknownSourcePasteProcessor.cs index 2ad2bb0331962..05b75b0451d10 100644 --- a/src/EditorFeatures/CSharp/StringCopyPaste/UnknownSourcePasteProcessor.cs +++ b/src/EditorFeatures/CSharp/StringCopyPaste/UnknownSourcePasteProcessor.cs @@ -141,7 +141,7 @@ private ImmutableArray GetEditsForRawString() if (quotesToAdd != null) edits.Add(new TextChange(new TextSpan(StringExpressionBeforePasteInfo.EndDelimiterSpanWithoutSuffix.End, 0), quotesToAdd)); - return edits.ToImmutable(); + return edits.ToImmutableAndClear(); } /// diff --git a/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs b/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs index d275f78d275f5..a81d9ab3434de 100644 --- a/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs +++ b/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs @@ -94,7 +94,7 @@ public async Task> GetPeekableItemsAsync( } } - return results.ToImmutable(); + return results.ToImmutableAndClear(); } } } diff --git a/src/EditorFeatures/Core.Wpf/StringIndentation/StringIndentationAdornmentManager.VisibleBlock.cs b/src/EditorFeatures/Core.Wpf/StringIndentation/StringIndentationAdornmentManager.VisibleBlock.cs index d7deaeeef5cce..6f1533b0da943 100644 --- a/src/EditorFeatures/Core.Wpf/StringIndentation/StringIndentationAdornmentManager.VisibleBlock.cs +++ b/src/EditorFeatures/Core.Wpf/StringIndentation/StringIndentationAdornmentManager.VisibleBlock.cs @@ -163,7 +163,7 @@ private VisibleBlock(double x, ImmutableArray<(double start, double end)> ySegme if ((currentSegmentBottom - currentSegmentTop) >= MinLineHeight) segments.Add((currentSegmentTop, currentSegmentBottom)); - return segments.ToImmutable(); + return segments.ToImmutableAndClear(); } private static bool IsInHole(ImmutableArray orderedHoleSpans, ITextViewLine line) diff --git a/src/EditorFeatures/Core/CodeDefinitionWindow/DefinitionContextTracker.cs b/src/EditorFeatures/Core/CodeDefinitionWindow/DefinitionContextTracker.cs index 532504fbe00cf..ae249a9df14df 100644 --- a/src/EditorFeatures/Core/CodeDefinitionWindow/DefinitionContextTracker.cs +++ b/src/EditorFeatures/Core/CodeDefinitionWindow/DefinitionContextTracker.cs @@ -171,7 +171,7 @@ internal async Task> GetContextFrom } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } // We didn't have regular source references, but possibly: diff --git a/src/EditorFeatures/Core/Extensibility/NavigationBar/WrappedNavigationBarItem.cs b/src/EditorFeatures/Core/Extensibility/NavigationBar/WrappedNavigationBarItem.cs index 872596c7274ca..d123648303e91 100644 --- a/src/EditorFeatures/Core/Extensibility/NavigationBar/WrappedNavigationBarItem.cs +++ b/src/EditorFeatures/Core/Extensibility/NavigationBar/WrappedNavigationBarItem.cs @@ -39,7 +39,7 @@ private static ImmutableArray GetSpans(RoslynNavigationBarItem underly using var _ = ArrayBuilder.GetInstance(out var spans); AddSpans(underlyingItem, spans); spans.SortAndRemoveDuplicates(Comparer.Default); - return spans.ToImmutable(); + return spans.ToImmutableAndClear(); static void AddSpans(RoslynNavigationBarItem underlyingItem, ArrayBuilder spans) { diff --git a/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs b/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs index 295958e5aca64..cb0a42fd4e3e4 100644 --- a/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs +++ b/src/EditorFeatures/Core/ExternalAccess/IntelliCode/IntentProcessor.cs @@ -88,7 +88,7 @@ public async Task> ComputeIntentsAsync(IntentReques convertedResults.AddIfNotNull(convertedIntent); } - return convertedResults.ToImmutable(); + return convertedResults.ToImmutableAndClear(); } private static async Task ConvertToIntelliCodeResultAsync( diff --git a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/FilterSet.cs b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/FilterSet.cs index ebc2953cab5e5..6477cfdd23667 100644 --- a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/FilterSet.cs +++ b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/FilterSet.cs @@ -191,7 +191,7 @@ public ImmutableArray GetFilterStatesInSet() } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } /// @@ -218,7 +218,7 @@ public static ImmutableArray CombineFilterStates(Immu } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); void AddFilterState(ImmutableArray filterStates) { diff --git a/src/EditorFeatures/Core/ReferenceHighlighting/NavigateToHighlightReferenceCommandHandler.cs b/src/EditorFeatures/Core/ReferenceHighlighting/NavigateToHighlightReferenceCommandHandler.cs index 72c0a5ab9f2f6..ca9c4cfdab6b4 100644 --- a/src/EditorFeatures/Core/ReferenceHighlighting/NavigateToHighlightReferenceCommandHandler.cs +++ b/src/EditorFeatures/Core/ReferenceHighlighting/NavigateToHighlightReferenceCommandHandler.cs @@ -87,7 +87,7 @@ private static ImmutableArray GetTags( tags.AddRange(tag.Span.GetSpans(span.Snapshot.TextBuffer)); tags.Sort(static (ss1, ss2) => ss1.Start - ss2.Start); - return tags.ToImmutable(); + return tags.ToImmutableAndClear(); } private static SnapshotSpan GetDestinationTag( diff --git a/src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs b/src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs index 5febe18aacdd4..3905b4b0e91be 100644 --- a/src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs +++ b/src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs @@ -956,7 +956,7 @@ public ImmutableArray ParseStatements(string statements) } } - return list.ToImmutable(); + return list.ToImmutableAndClear(); } public void Dispose() diff --git a/src/EditorFeatures/Test/Snippets/RoslynLSPSnippetConvertTests.cs b/src/EditorFeatures/Test/Snippets/RoslynLSPSnippetConvertTests.cs index f8fe60b663d18..335fef3fef2df 100644 --- a/src/EditorFeatures/Test/Snippets/RoslynLSPSnippetConvertTests.cs +++ b/src/EditorFeatures/Test/Snippets/RoslynLSPSnippetConvertTests.cs @@ -515,7 +515,7 @@ private static ImmutableArray GetSnippetPlaceholders(string } } - return arrayBuilder.ToImmutable(); + return arrayBuilder.ToImmutableAndClear(); } } } diff --git a/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs b/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs index 415c50da62bb5..fdc91b04c1a0c 100644 --- a/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs +++ b/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs @@ -200,7 +200,7 @@ static ImmutableArray GetMergedChanges(TextChange? newLineEdit, Immu mergedChanges.Add(new TextChange(newTextChangeSpan, newTextChangeText)); } - return mergedChanges.ToImmutable(); + return mergedChanges.ToImmutableAndClear(); } } diff --git a/src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs b/src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs index 3bd0f2c120203..e12e26279379c 100644 --- a/src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs +++ b/src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs @@ -763,7 +763,7 @@ private ImmutableArray TransferLeadingWhitespaceTrivia(IEnumerable n index++; } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private async ValueTask> UpdateParamTagsInLeadingTriviaAsync( diff --git a/src/Features/CSharp/Portable/CodeLens/CSharpCodeLensMemberFinder.cs b/src/Features/CSharp/Portable/CodeLens/CSharpCodeLensMemberFinder.cs index 8f8c4fbfafd7e..6987f945cf723 100644 --- a/src/Features/CSharp/Portable/CodeLens/CSharpCodeLensMemberFinder.cs +++ b/src/Features/CSharp/Portable/CodeLens/CSharpCodeLensMemberFinder.cs @@ -33,7 +33,7 @@ public async Task> GetCodeLensMembersAsync(Docume visitor.Visit(root); - return codeLensNodes.ToImmutable(); + return codeLensNodes.ToImmutableAndClear(); } private sealed class CSharpCodeLensVisitor(ArrayBuilder memberBuilder) : CSharpSyntaxWalker diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationName/DeclarationNameRecommender.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationName/DeclarationNameRecommender.cs index 3d88f7a352b7e..9051e654375c1 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationName/DeclarationNameRecommender.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationName/DeclarationNameRecommender.cs @@ -60,7 +60,7 @@ public DeclarationNameRecommender() GetRecommendedNames(names, nameInfo, context, result, namingStyleOptions, cancellationToken); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private ImmutableArray> GetBaseNames(SemanticModel semanticModel, NameDeclarationInfo nameInfo) diff --git a/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_ProgramMain.cs b/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_ProgramMain.cs index ec583a5ca0285..bd8b54b33a3dc 100644 --- a/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_ProgramMain.cs +++ b/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_ProgramMain.cs @@ -146,7 +146,7 @@ private static ImmutableArray GenerateProgramMainStatements( } } - return statements.ToImmutable(); + return statements.ToImmutableAndClear(); } private static TSyntaxNode FixupComments(TSyntaxNode node) where TSyntaxNode : SyntaxNode diff --git a/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_TopLevelStatements.cs b/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_TopLevelStatements.cs index 1e313a61b1226..4ac7c6f4365ef 100644 --- a/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_TopLevelStatements.cs +++ b/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_TopLevelStatements.cs @@ -231,7 +231,7 @@ private static ImmutableArray GetGlobalStatements( foreach (var statement in statements) globalStatements.Add(GlobalStatement(statement).WithAdditionalAnnotations(Formatter.Annotation)); - return globalStatements.ToImmutable(); + return globalStatements.ToImmutableAndClear(); } private static VariableDeclarationSyntax ConvertDeclaration( diff --git a/src/Features/CSharp/Portable/DocumentHighlighting/CSharpDocumentHighlightsService.cs b/src/Features/CSharp/Portable/DocumentHighlighting/CSharpDocumentHighlightsService.cs index 8c621ef831a49..c8a48212c6e61 100644 --- a/src/Features/CSharp/Portable/DocumentHighlighting/CSharpDocumentHighlightsService.cs +++ b/src/Features/CSharp/Portable/DocumentHighlighting/CSharpDocumentHighlightsService.cs @@ -67,6 +67,6 @@ protected override async Task> GetAdditionalReferencesA } } - return results.ToImmutable(); + return results.ToImmutableAndClear(); } } diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs index 508f03bd15ebe..b95671ab482d1 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs @@ -60,7 +60,7 @@ protected override ImmutableArray GetInitialStatementsForMethod } } - return list.ToImmutable(); + return list.ToImmutableAndClear(); } private static IEnumerable GetStatementsFromContainer(SyntaxNode node) diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs index 366598ff22059..f097a8e1ad20c 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs @@ -408,7 +408,7 @@ private ImmutableArray MoveDeclarationOutFromMethodDefinition( result.AddRange(expressionStatements); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } /// diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.PostProcessor.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.PostProcessor.cs index b9573ad911765..5b0dfa7a74172 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.PostProcessor.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.PostProcessor.cs @@ -108,7 +108,7 @@ private ImmutableArray MergeDeclarationStatementsWorker(Immutab if (map.Count > 0) result.AddRange(GetMergedDeclarationStatements(map)); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private void AppendDeclarationStatementToMap( diff --git a/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs b/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs index 06b21c73514f7..e8a11332cf44e 100644 --- a/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs +++ b/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs @@ -99,7 +99,7 @@ protected override ImmutableArray GenerateTypeParameters(C list.Add(typeParameter); } - return list.ToImmutable(); + return list.ToImmutableAndClear(); } } @@ -158,7 +158,7 @@ protected override ImmutableArray DetermineTypeArguments(Cancellati } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } } } diff --git a/src/Features/CSharp/Portable/LanguageServices/CSharpStructuralTypeDisplayService.cs b/src/Features/CSharp/Portable/LanguageServices/CSharpStructuralTypeDisplayService.cs index 3873059bed1dd..1c385d83565a4 100644 --- a/src/Features/CSharp/Portable/LanguageServices/CSharpStructuralTypeDisplayService.cs +++ b/src/Features/CSharp/Portable/LanguageServices/CSharpStructuralTypeDisplayService.cs @@ -57,6 +57,6 @@ protected override ImmutableArray GetNormalAnonymousTypeParts members.AddRange(Space()); members.Add(Punctuation(SyntaxFacts.GetText(SyntaxKind.CloseBraceToken))); - return members.ToImmutable(); + return members.ToImmutableAndClear(); } } diff --git a/src/Features/CSharp/Portable/LineSeparators/CSharpLineSeparatorService.cs b/src/Features/CSharp/Portable/LineSeparators/CSharpLineSeparatorService.cs index 36af95476fd8a..90fad59bac2ba 100644 --- a/src/Features/CSharp/Portable/LineSeparators/CSharpLineSeparatorService.cs +++ b/src/Features/CSharp/Portable/LineSeparators/CSharpLineSeparatorService.cs @@ -64,7 +64,7 @@ public async Task> GetLineSeparatorsAsync( } } - return spans.ToImmutable(); + return spans.ToImmutableAndClear(); } /// Node types that are interesting for line separation. diff --git a/src/Features/CSharp/Portable/NavigationBar/CSharpNavigationBarItemService.cs b/src/Features/CSharp/Portable/NavigationBar/CSharpNavigationBarItemService.cs index 1f06dc9100fd9..ee7d28326b88c 100644 --- a/src/Features/CSharp/Portable/NavigationBar/CSharpNavigationBarItemService.cs +++ b/src/Features/CSharp/Portable/NavigationBar/CSharpNavigationBarItemService.cs @@ -108,7 +108,7 @@ private static ImmutableArray GetMembersInTypes( } items.Sort((x1, x2) => x1.Text.CompareTo(x2.Text)); - return items.ToImmutable(); + return items.ToImmutableAndClear(); } } diff --git a/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs b/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs index c0f41a8dd0b88..a7c7102ca66ba 100644 --- a/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs +++ b/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs @@ -100,7 +100,7 @@ private static ImmutableArray ConvertPropertyToMembers( cancellationToken)); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static SyntaxNode GetSetMethod( diff --git a/src/Features/CSharp/Portable/Snippets/CSharpForEachLoopSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpForEachLoopSnippetProvider.cs index a5a18c484d87d..1ff99c4351f6d 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpForEachLoopSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpForEachLoopSnippetProvider.cs @@ -113,7 +113,7 @@ protected override ImmutableArray GetPlaceHolderLocationsLis if (!ConstructedFromInlineExpression) arrayBuilder.Add(new SnippetPlaceholder(node.Expression.ToString(), node.Expression.SpanStart)); - return arrayBuilder.ToImmutable(); + return arrayBuilder.ToImmutableAndClear(); } protected override int GetTargetCaretPosition(ForEachStatementSyntax forEachStatement, SourceText sourceText) diff --git a/src/Features/CSharp/Portable/StringIndentation/CSharpStringIndentationService.cs b/src/Features/CSharp/Portable/StringIndentation/CSharpStringIndentationService.cs index 61b5753854a91..fd5d41cbb8f57 100644 --- a/src/Features/CSharp/Portable/StringIndentation/CSharpStringIndentationService.cs +++ b/src/Features/CSharp/Portable/StringIndentation/CSharpStringIndentationService.cs @@ -37,7 +37,7 @@ public async Task> GetStringIndentationR Recurse(text, root, textSpan, result, cancellationToken); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static void Recurse( diff --git a/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeRefactoringProvider.cs index 7bfabecaf2835..6c5a7895fd584 100644 --- a/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeRefactoringProvider.cs @@ -194,7 +194,7 @@ private static async Task> ComputeRefactoringsAsync( title)); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static async Task UpdateDocumentAsync( diff --git a/src/Features/CSharpTest/Diagnostics/Suppression/RemoveUnnecessaryPragmaSuppressionsTests.cs b/src/Features/CSharpTest/Diagnostics/Suppression/RemoveUnnecessaryPragmaSuppressionsTests.cs index 39e036613e679..f48f6e7b8cdaa 100644 --- a/src/Features/CSharpTest/Diagnostics/Suppression/RemoveUnnecessaryPragmaSuppressionsTests.cs +++ b/src/Features/CSharpTest/Diagnostics/Suppression/RemoveUnnecessaryPragmaSuppressionsTests.cs @@ -170,7 +170,7 @@ protected override ImmutableArray UnsupportedDiagnosticIds } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } } diff --git a/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.State.cs b/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.State.cs index 0631da4cd583f..043bbc57b1488 100644 --- a/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.State.cs +++ b/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.State.cs @@ -92,7 +92,7 @@ private static async Task> GetConstructorCa } } - return applicableConstructors.ToImmutable(); + return applicableConstructors.ToImmutableAndClear(); } private static async Task IsApplicableConstructorAsync(IMethodSymbol constructor, Document document, ImmutableArray parameterNamesForSelectedMembers, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.cs b/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.cs index ef233f3e5f4af..e2300a8a4fbee 100644 --- a/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.cs @@ -108,7 +108,7 @@ private static ImmutableArray GetGroupedActions(AddConstructorParame actions.Add(result.OptionalParameterActions.Single()); } - return actions.ToImmutable(); + return actions.ToImmutableAndClear(); } private static AddConstructorParameterResult CreateCodeActions(Document document, CodeGenerationContextInfo info, State state) @@ -192,6 +192,6 @@ public async Task> ComputeIntentAsync( results.Add(intent); } - return results.ToImmutable(); + return results.ToImmutableAndClear(); } } diff --git a/src/Features/Core/Portable/AddFileBanner/AbstractAddFileBannerCodeRefactoringProvider.cs b/src/Features/Core/Portable/AddFileBanner/AbstractAddFileBannerCodeRefactoringProvider.cs index c49e2d8fcdf05..647c0910067a8 100644 --- a/src/Features/Core/Portable/AddFileBanner/AbstractAddFileBannerCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/AddFileBanner/AbstractAddFileBannerCodeRefactoringProvider.cs @@ -159,7 +159,7 @@ private ImmutableArray UpdateEmbeddedFileNames( result.Add(updated); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private async Task> TryGetBannerAsync( diff --git a/src/Features/Core/Portable/AddImport/AbstractAddImportFeatureService.cs b/src/Features/Core/Portable/AddImport/AbstractAddImportFeatureService.cs index 99094f7dcdd97..d25940ab6bd71 100644 --- a/src/Features/Core/Portable/AddImport/AbstractAddImportFeatureService.cs +++ b/src/Features/Core/Portable/AddImport/AbstractAddImportFeatureService.cs @@ -121,7 +121,7 @@ private async Task> GetFixesInCurrentProcessAsy } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private async Task> FindResultsAsync( @@ -496,7 +496,7 @@ private static bool NotNull(SymbolReference reference) result.Add((diagnostic, fixes)); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } public async Task> GetUniqueFixesAsync( @@ -562,7 +562,7 @@ private async Task> GetUniqueFixesAsyncInCurren } } - return fixes.ToImmutable(); + return fixes.ToImmutableAndClear(); } public ImmutableArray GetCodeActionsForFixes( @@ -578,7 +578,7 @@ public ImmutableArray GetCodeActionsForFixes( break; } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static CodeAction? TryCreateCodeAction(Document document, AddImportFixData fixData, IPackageInstallerService? installerService) diff --git a/src/Features/Core/Portable/AddImport/CodeActions/InstallPackageAndAddImportCodeAction.cs b/src/Features/Core/Portable/AddImport/CodeActions/InstallPackageAndAddImportCodeAction.cs index 1dd12679dd76c..6030a278ba6ab 100644 --- a/src/Features/Core/Portable/AddImport/CodeActions/InstallPackageAndAddImportCodeAction.cs +++ b/src/Features/Core/Portable/AddImport/CodeActions/InstallPackageAndAddImportCodeAction.cs @@ -59,7 +59,7 @@ protected override async Task> ComputePreviewOp result.AddRange(await solutionChangeAction.GetPreviewOperationsAsync( this.OriginalDocument.Project.Solution, cancellationToken).ConfigureAwait(false)); result.Add(_installOperation); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private async Task GetUpdatedSolutionAsync(CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs b/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs index 57508f95172f4..4850d08d7fd1b 100644 --- a/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs +++ b/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs @@ -602,7 +602,7 @@ private ImmutableArray GetNamespaceSymbolReferences( references.Add(scope.CreateReference(mappedResult)); } - return references.ToImmutable(); + return references.ToImmutableAndClear(); } private static ImmutableArray> OfType(ImmutableArray> symbols) where T : ISymbol diff --git a/src/Features/Core/Portable/AddPackage/ParentInstallPackageCodeAction.cs b/src/Features/Core/Portable/AddPackage/ParentInstallPackageCodeAction.cs index 08704b0019666..4a240ec50b781 100644 --- a/src/Features/Core/Portable/AddPackage/ParentInstallPackageCodeAction.cs +++ b/src/Features/Core/Portable/AddPackage/ParentInstallPackageCodeAction.cs @@ -101,7 +101,7 @@ private static ImmutableArray CreateNestedActions( // And finally the action to show the package manager dialog. codeActions.Add(new InstallWithPackageManagerCodeAction(installerService, fixData.PackageName)); - return codeActions.ToImmutable(); + return codeActions.ToImmutableAndClear(); } private static CodeAction CreateCodeAction( diff --git a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs index 87850319e07e0..5984100dae2f1 100644 --- a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs +++ b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs @@ -746,7 +746,7 @@ protected ImmutableArray GetSeparators(SeparatedSyntaxList ar : CommaTokenWithElasticSpace()); } - return separators.ToImmutable(); + return separators.ToImmutableAndClear(); } protected virtual async Task> AddNewArgumentsToListAsync( @@ -1029,7 +1029,7 @@ protected ImmutableArray GetPermutedDocCommentTrivia(SyntaxNode no extraNodeList.Free(); - return updatedLeadingTrivia.ToImmutable(); + return updatedLeadingTrivia.ToImmutableAndClear(); } protected static bool IsParamsArrayExpandedHelper(ISymbol symbol, int argumentCount, bool lastArgumentIsNamed, SemanticModel semanticModel, SyntaxNode lastArgumentExpression, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/ChangeSignature/DelegateInvokeMethodReferenceFinder.cs b/src/Features/Core/Portable/ChangeSignature/DelegateInvokeMethodReferenceFinder.cs index da3355a3344b3..023fb637ee227 100644 --- a/src/Features/Core/Portable/ChangeSignature/DelegateInvokeMethodReferenceFinder.cs +++ b/src/Features/Core/Portable/ChangeSignature/DelegateInvokeMethodReferenceFinder.cs @@ -56,7 +56,7 @@ protected override async ValueTask> DetermineCascadedSym } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } protected override Task> DetermineDocumentsToSearchAsync( diff --git a/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs b/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs index 2dfef354517ad..b36c3000c7745 100644 --- a/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs +++ b/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs @@ -360,7 +360,7 @@ private async Task ConfigureAsync(CancellationToken cancellationToken) builder.Add((option.Definition.ConfigName, optionValue, option.IsPerLanguage)); } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } finally { diff --git a/src/Features/Core/Portable/CodeRefactorings/AbstractRefactoringHelpersService.cs b/src/Features/Core/Portable/CodeRefactorings/AbstractRefactoringHelpersService.cs index 53ed67ddf0918..11ac6cc583cc9 100644 --- a/src/Features/Core/Portable/CodeRefactorings/AbstractRefactoringHelpersService.cs +++ b/src/Features/Core/Portable/CodeRefactorings/AbstractRefactoringHelpersService.cs @@ -32,7 +32,7 @@ public async Task> GetRelevantNodesAsync.GetInstance(out var nonEmptyNodes); foreach (var node in relevantNodesBuilder) diff --git a/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs b/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs index 0a9847d7caba7..e58d370f34b55 100644 --- a/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/CodeRefactorings/ExtractMethod/AbstractExtractMethodCodeRefactoringProvider.cs @@ -66,7 +66,7 @@ private static async Task> GetCodeActionsAsync( var localFunctionAction = await ExtractLocalFunctionAsync(document, textSpan, extractOptions, cancellationToken).ConfigureAwait(false); actions.AddIfNotNull(localFunctionAction); - return actions.ToImmutable(); + return actions.ToImmutableAndClear(); } private static async Task ExtractMethodAsync( diff --git a/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.cs b/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.cs index a60133133f9ea..bb3804312b745 100644 --- a/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.cs +++ b/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.cs @@ -160,7 +160,7 @@ private ImmutableArray CreateActions(State state, CancellationToken Debug.Assert(actions.Count != 0, "No code actions found for MoveType Refactoring"); - return actions.ToImmutable(); + return actions.ToImmutableAndClear(); } private static bool ClassNextToGlobalStatements(SyntaxNode root, ISyntaxFactsService syntaxFacts) diff --git a/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs b/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs index 6a945ab96565f..8ee217162cee2 100644 --- a/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs +++ b/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs @@ -553,7 +553,7 @@ private static async Task> FindReferen } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private static async Task> FindReferencesAsync(ISymbol symbol, Document document, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/Common/AbstractProjectExtensionProvider.cs b/src/Features/Core/Portable/Common/AbstractProjectExtensionProvider.cs index 69d3d9d57adf2..480fa03983ebf 100644 --- a/src/Features/Core/Portable/Common/AbstractProjectExtensionProvider.cs +++ b/src/Features/Core/Portable/Common/AbstractProjectExtensionProvider.cs @@ -73,7 +73,7 @@ static ImmutableArray ComputeExtensions(string language, IReadOnlyLi builder.Add(extension); } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } @@ -178,6 +178,6 @@ private ImmutableArray CreateExtensions(string language) // NOTE: We could report "unable to load analyzer" exception here but it should have been already reported by DiagnosticService. } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } diff --git a/src/Features/Core/Portable/Completion/Providers/AbstractDocCommentCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/AbstractDocCommentCompletionProvider.cs index 6171d46223c1d..4bf683611ab5c 100644 --- a/src/Features/Core/Portable/Completion/Providers/AbstractDocCommentCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/AbstractDocCommentCompletionProvider.cs @@ -246,7 +246,7 @@ protected ImmutableArray GetTopLevelItems(ISymbol? symbol, TSynt } } - return items.ToImmutable(); + return items.ToImmutableAndClear(); } protected IEnumerable GetItemTagItems() diff --git a/src/Features/Core/Portable/Completion/Providers/AbstractKeywordCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/AbstractKeywordCompletionProvider.cs index 21398936c8f3e..730aff1b8f646 100644 --- a/src/Features/Core/Portable/Completion/Providers/AbstractKeywordCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/AbstractKeywordCompletionProvider.cs @@ -67,7 +67,7 @@ private async Task> RecommendKeywordsAsync( } result.RemoveDuplicates(); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } public sealed override Task GetTextChangeAsync(Document document, CompletionItem item, char? ch, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/Completion/Providers/AbstractSymbolCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/AbstractSymbolCompletionProvider.cs index f3a276a0b9718..ace71a736df3c 100644 --- a/src/Features/Core/Portable/Completion/Providers/AbstractSymbolCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/AbstractSymbolCompletionProvider.cs @@ -147,7 +147,7 @@ group symbol by texts into g itemListBuilder.Add(item); } - return itemListBuilder.ToImmutable(); + return itemListBuilder.ToImmutableAndClear(); } protected static bool TryFindFirstSymbolMatchesTargetTypes( @@ -337,7 +337,7 @@ private static Dictionary UnionSymbols( perContextSymbols.Add((relatedDocumentId, syntaxContext, symbols)); } - return perContextSymbols.ToImmutable(); + return perContextSymbols.ToImmutableAndClear(); } /// diff --git a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractImportCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractImportCompletionProvider.cs index 9aac29d32a390..9e34d43f12d36 100644 --- a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractImportCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractImportCompletionProvider.cs @@ -114,7 +114,7 @@ private static ImmutableArray GetImportedNamespaces(SyntaxContext contex } } - return usingsBuilder.ToImmutable(); + return usingsBuilder.ToImmutableAndClear(); } public override async Task GetChangeAsync( diff --git a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.SymbolComputer.cs b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.SymbolComputer.cs index 28b81bce83aa4..e3472e4604f61 100644 --- a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.SymbolComputer.cs +++ b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.SymbolComputer.cs @@ -298,7 +298,7 @@ private ImmutableArray GetExtensionMethodsForSymbolsFromDifferent } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private ImmutableArray GetExtensionMethodsForSymbolsFromSameCompilation( @@ -342,7 +342,7 @@ private ImmutableArray GetExtensionMethodsForSymbolsFromSameCompi } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private MultiDictionary GetPotentialMatchingSymbolsFromAssembly( diff --git a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs index 58af5842ea690..0f58f0b5e126c 100644 --- a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs +++ b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs @@ -205,7 +205,7 @@ private static ImmutableArray ConvertSymbolsTo itemsBuilder.Add(item); } - return itemsBuilder.ToImmutable(); + return itemsBuilder.ToImmutableAndClear(); } private static bool ShouldIncludeInTargetTypedCompletion( diff --git a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/TypeImportCompletionCacheEntry.cs b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/TypeImportCompletionCacheEntry.cs index c414b0124aaa9..c9ee742ce2d22 100644 --- a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/TypeImportCompletionCacheEntry.cs +++ b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/TypeImportCompletionCacheEntry.cs @@ -129,7 +129,7 @@ public ImmutableArray GetItemsForContext( builder.Add(item); } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); static CompletionItem GetAppropriateAttributeItem(CompletionItem attributeItem, bool isCaseSensitive) { diff --git a/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractLoadDirectiveCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractLoadDirectiveCompletionProvider.cs index 21b7f3f91b7d1..1d5bdf89688ce 100644 --- a/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractLoadDirectiveCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractLoadDirectiveCompletionProvider.cs @@ -34,7 +34,7 @@ private static ImmutableArray GetCommitCharacters() builder.Add('\\'); } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } protected override async Task ProvideCompletionsAsync(CompletionContext context, string pathThroughLastSlash) diff --git a/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractReferenceDirectiveCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractReferenceDirectiveCompletionProvider.cs index 2776564e7fc6a..5c8db335d6373 100644 --- a/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractReferenceDirectiveCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractReferenceDirectiveCompletionProvider.cs @@ -44,7 +44,7 @@ private static ImmutableArray GetCommitCharacters() builder.Add(','); } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } protected override async Task ProvideCompletionsAsync(CompletionContext context, string pathThroughLastSlash) diff --git a/src/Features/Core/Portable/Completion/Providers/Scripting/GlobalAssemblyCacheCompletionHelper.cs b/src/Features/Core/Portable/Completion/Providers/Scripting/GlobalAssemblyCacheCompletionHelper.cs index 680be79a82ff1..bf0374424e591 100644 --- a/src/Features/Core/Portable/Completion/Providers/Scripting/GlobalAssemblyCacheCompletionHelper.cs +++ b/src/Features/Core/Portable/Completion/Providers/Scripting/GlobalAssemblyCacheCompletionHelper.cs @@ -59,7 +59,7 @@ internal ImmutableArray GetItems(string directoryPath, Cancellat } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static IEnumerable GetAssemblyIdentities(string partialName) diff --git a/src/Features/Core/Portable/Completion/Providers/SymbolCompletionItem.cs b/src/Features/Core/Portable/Completion/Providers/SymbolCompletionItem.cs index 0990ee2947f07..2001d59c2c31c 100644 --- a/src/Features/Core/Portable/Completion/Providers/SymbolCompletionItem.cs +++ b/src/Features/Core/Portable/Completion/Providers/SymbolCompletionItem.cs @@ -155,7 +155,7 @@ public static async Task> GetSymbolsAsync(CompletionItem } } - return symbols.ToImmutable(); + return symbols.ToImmutableAndClear(); } return []; diff --git a/src/Features/Core/Portable/ConvertTupleToStruct/AbstractConvertTupleToStructCodeRefactoringProvider.cs b/src/Features/Core/Portable/ConvertTupleToStruct/AbstractConvertTupleToStructCodeRefactoringProvider.cs index 24b6101ffcff7..e0a363677cb8f 100644 --- a/src/Features/Core/Portable/ConvertTupleToStruct/AbstractConvertTupleToStructCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/ConvertTupleToStruct/AbstractConvertTupleToStructCodeRefactoringProvider.cs @@ -463,7 +463,7 @@ await AddDocumentsToUpdateForProjectAsync( project, result, tupleFieldNames, cancellationToken).ConfigureAwait(false); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static async Task> GetDocumentsToUpdateForContainingProjectAsync( @@ -475,7 +475,7 @@ private static async Task> GetDocumentsToUpdate await AddDocumentsToUpdateForProjectAsync( project, result, tupleFieldNames, cancellationToken).ConfigureAwait(false); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static async Task AddDocumentsToUpdateForProjectAsync(Project project, ArrayBuilder result, ImmutableArray tupleFieldNames, CancellationToken cancellationToken) @@ -528,7 +528,7 @@ private static async Task> GetDocumentsToUpdate result.Add(new DocumentToUpdate(document, nodes)); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static ImmutableArray GetDocumentsToUpdateForContainingMember( diff --git a/src/Features/Core/Portable/DesignerAttribute/DesignerAttributeDiscoveryService.cs b/src/Features/Core/Portable/DesignerAttribute/DesignerAttributeDiscoveryService.cs index 8fe77a1502baa..cbfd81891bc1e 100644 --- a/src/Features/Core/Portable/DesignerAttribute/DesignerAttributeDiscoveryService.cs +++ b/src/Features/Core/Portable/DesignerAttribute/DesignerAttributeDiscoveryService.cs @@ -249,7 +249,7 @@ private async Task ScanForDesignerCategoryUsageAsync( results.Add((data, projectVersion)); } - return results.ToImmutable(); + return results.ToImmutableAndClear(); async Task ComputeDesignerAttributeDataAsync( Project project, DocumentId documentId, string filePath, bool hasDesignerCategoryType) diff --git a/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs b/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs index e2881e3c26ea5..7125e80813e02 100644 --- a/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs +++ b/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs @@ -3809,7 +3809,7 @@ void AddDelete(ISymbol? symbol) foreach (var (_, indices) in deletedTypes) indices.Free(); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private static bool IsReloadable(INamedTypeSymbol type) diff --git a/src/Features/Core/Portable/EditAndContinue/ActiveStatementsMap.cs b/src/Features/Core/Portable/EditAndContinue/ActiveStatementsMap.cs index 704b2934917e1..b5069bc9a549e 100644 --- a/src/Features/Core/Portable/EditAndContinue/ActiveStatementsMap.cs +++ b/src/Features/Core/Portable/EditAndContinue/ActiveStatementsMap.cs @@ -249,7 +249,7 @@ void AddStatement(LinePositionSpan unmappedLineSpan, ActiveStatement activeState Debug.Assert(builder.IsSorted(Comparer.Create((x, y) => x.UnmappedSpan.Start.CompareTo(y.UnmappedSpan.End)))); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private static LinePositionSpan ReverseMapLinePositionSpan(LinePositionSpan unmappedSection, LinePositionSpan mappedSection, LinePositionSpan mappedSpan) diff --git a/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs b/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs index 071b40d5e7440..3b926fff1dbbf 100644 --- a/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs +++ b/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs @@ -739,7 +739,7 @@ public async ValueTask>> GetB activeStatementsInChangedDocuments.FreeValues(); Debug.Assert(spans.Count == documentIds.Length); - return spans.ToImmutable(); + return spans.ToImmutableAndClear(); } catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken)) { @@ -816,7 +816,7 @@ public async ValueTask> GetAdjustedActiveSta } } - return adjustedMappedSpans.ToImmutable(); + return adjustedMappedSpans.ToImmutableAndClear(); } catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken)) { diff --git a/src/Features/Core/Portable/EditAndContinue/EditAndContinueCapabilities.cs b/src/Features/Core/Portable/EditAndContinue/EditAndContinueCapabilities.cs index 69800c49f88d5..ea8381ceb81b2 100644 --- a/src/Features/Core/Portable/EditAndContinue/EditAndContinueCapabilities.cs +++ b/src/Features/Core/Portable/EditAndContinue/EditAndContinueCapabilities.cs @@ -123,6 +123,6 @@ public static ImmutableArray ToStringArray(this EditAndContinueCapabilit if (capabilities.HasFlag(EditAndContinueCapabilities.UpdateParameters)) builder.Add(nameof(EditAndContinueCapabilities.UpdateParameters)); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } diff --git a/src/Features/Core/Portable/EditAndContinue/EditAndContinueDocumentAnalysesCache.cs b/src/Features/Core/Portable/EditAndContinue/EditAndContinueDocumentAnalysesCache.cs index 90c463d540cf9..9e5ec07398c1c 100644 --- a/src/Features/Core/Portable/EditAndContinue/EditAndContinueDocumentAnalysesCache.cs +++ b/src/Features/Core/Portable/EditAndContinue/EditAndContinueDocumentAnalysesCache.cs @@ -158,7 +158,7 @@ private async Task> GetLatestUnmappedAct activeStatementSpansBuilder.Add(new ActiveStatementLineSpan(newMappedDocumentActiveSpan.Id, unmappedSpan)); } - return activeStatementSpansBuilder.ToImmutable(); + return activeStatementSpansBuilder.ToImmutableAndClear(); } private AsyncLazy GetDocumentAnalysisNoLock(Project baseProject, Document document, ImmutableArray activeStatementSpans) diff --git a/src/Features/Core/Portable/EditAndContinue/EditSession.cs b/src/Features/Core/Portable/EditAndContinue/EditSession.cs index fc558099aebaf..456cfaac1a639 100644 --- a/src/Features/Core/Portable/EditAndContinue/EditSession.cs +++ b/src/Features/Core/Portable/EditAndContinue/EditSession.cs @@ -181,7 +181,7 @@ internal EditSession( diagnostics.Add(Diagnostic.Create(descriptor, location, messageArgs)); } - return diagnostics.ToImmutable(); + return diagnostics.ToImmutableAndClear(); } private static async IAsyncEnumerable CreateChangedLocationsAsync(Project oldProject, Project newProject, ImmutableArray documentAnalyses, [EnumeratorCancellation] CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/EditAndContinue/EmitSolutionUpdateResults.cs b/src/Features/Core/Portable/EditAndContinue/EmitSolutionUpdateResults.cs index d27a67d59ed99..730e2abe05c3d 100644 --- a/src/Features/Core/Portable/EditAndContinue/EmitSolutionUpdateResults.cs +++ b/src/Features/Core/Portable/EditAndContinue/EmitSolutionUpdateResults.cs @@ -90,7 +90,7 @@ public async Task> GetAllDiagnosticsAsync(Solution so diagnostics.AddRange(projectEmitDiagnostics); } - return diagnostics.ToImmutable(); + return diagnostics.ToImmutableAndClear(); } internal static async ValueTask> GetHotReloadDiagnosticsAsync( @@ -164,6 +164,6 @@ internal static async ValueTask> GetH } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } diff --git a/src/Features/Core/Portable/EditAndContinue/ProjectDiagnostics.cs b/src/Features/Core/Portable/EditAndContinue/ProjectDiagnostics.cs index 52218cb41f9ad..67ab5b683bf09 100644 --- a/src/Features/Core/Portable/EditAndContinue/ProjectDiagnostics.cs +++ b/src/Features/Core/Portable/EditAndContinue/ProjectDiagnostics.cs @@ -29,6 +29,6 @@ public static ImmutableArray ToDiagnosticData(this ImmutableArra } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } } diff --git a/src/Features/Core/Portable/EditAndContinue/Remote/RemoteEditAndContinueServiceProxy.cs b/src/Features/Core/Portable/EditAndContinue/Remote/RemoteEditAndContinueServiceProxy.cs index 9e93e6c963a0f..aa5cd4388b2aa 100644 --- a/src/Features/Core/Portable/EditAndContinue/Remote/RemoteEditAndContinueServiceProxy.cs +++ b/src/Features/Core/Portable/EditAndContinue/Remote/RemoteEditAndContinueServiceProxy.cs @@ -215,7 +215,7 @@ public async ValueTask> GetDocumentDiagnosticsAsync(D result.Add(diagnostic); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static Diagnostic RemapLocation(Document designTimeDocument, DiagnosticData data) diff --git a/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonLexer.cs b/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonLexer.cs index 8476e7be98fc0..bc07d43a097fd 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonLexer.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonLexer.cs @@ -230,7 +230,7 @@ private ImmutableArray ScanTrivia(bool leading) break; } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private JsonTrivia? ScanEndOfLine() diff --git a/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonParser.cs b/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonParser.cs index 018d43fea8a0b..75ce0a69046bb 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonParser.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/Json/JsonParser.cs @@ -322,7 +322,7 @@ private ImmutableArray ParseSequenceWorker() while (ShouldConsumeSequenceElement()) result.Add(ParseValue()); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private JsonSeparatedList ParseCommaSeparatedSequence() diff --git a/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegexLexer.cs b/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegexLexer.cs index e11ef92f6a82b..397fa4abc0efc 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegexLexer.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegexLexer.cs @@ -124,7 +124,7 @@ private ImmutableArray ScanLeadingTrivia(bool allowTrivia, RegexOpt break; } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } public RegexTrivia? ScanComment(RegexOptions options) diff --git a/src/Features/Core/Portable/EmbeddedLanguages/StackFrame/StackFrameLexer.cs b/src/Features/Core/Portable/EmbeddedLanguages/StackFrame/StackFrameLexer.cs index 0e9eb8a273910..3577bf1060937 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/StackFrame/StackFrameLexer.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/StackFrame/StackFrameLexer.cs @@ -432,7 +432,7 @@ private static ImmutableArray CreateTrivia(params StackFrameTr } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private readonly bool IsStringAtPosition(string val) diff --git a/src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs b/src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs index c3b7319cf330b..5715e2012bebf 100644 --- a/src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs +++ b/src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs @@ -70,7 +70,7 @@ public async Task> GetEncapsulateFieldCodeActionsAsyn } builder.AddRange(EncapsulateAllFields(document, fields, fallbackOptions)); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private ImmutableArray EncapsulateAllFields(Document document, ImmutableArray fields, CleanCodeGenerationOptionsProvider fallbackOptions) diff --git a/src/Features/Core/Portable/ExternalAccess/UnitTesting/API/UnitTestingSearchHelpers.cs b/src/Features/Core/Portable/ExternalAccess/UnitTesting/API/UnitTestingSearchHelpers.cs index 3732e12669c7b..069c2bfa901bf 100644 --- a/src/Features/Core/Portable/ExternalAccess/UnitTesting/API/UnitTestingSearchHelpers.cs +++ b/src/Features/Core/Portable/ExternalAccess/UnitTesting/API/UnitTestingSearchHelpers.cs @@ -67,7 +67,7 @@ public static async Task> GetSourceLocat foreach (var location in locations.Value) result.AddIfNotNull(await location.TryRehydrateAsync(project.Solution, cancellationToken).ConfigureAwait(false)); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } return await GetSourceLocationsInProcessAsync(project, query, cancellationToken).ConfigureAwait(false); @@ -160,7 +160,7 @@ private static async Task> GetSourceLoca await foreach (var item in GetSourceLocationsInProcessWorkerAsync(project, query, cancellationToken).ConfigureAwait(false)) result.Add(item); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static IAsyncEnumerable GetSourceLocationsInProcessWorkerAsync( diff --git a/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs b/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs index db2ae0e7e12ca..12684fa5f487d 100644 --- a/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs +++ b/src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs @@ -439,7 +439,7 @@ private static ImmutableArray CreateInterfaceMembers(IEnumerable GetMethodParameters(DictionaryWhen false, variables whose data flow is not understood diff --git a/src/Features/Core/Portable/ExtractMethod/MethodExtractor.CodeGenerator.cs b/src/Features/Core/Portable/ExtractMethod/MethodExtractor.CodeGenerator.cs index 7b8c914018368..609df59688867 100644 --- a/src/Features/Core/Portable/ExtractMethod/MethodExtractor.CodeGenerator.cs +++ b/src/Features/Core/Portable/ExtractMethod/MethodExtractor.CodeGenerator.cs @@ -288,7 +288,7 @@ protected ImmutableArray AddSplitOrMoveDeclarationOutStatement list.Add(declaration); } - return list.ToImmutable(); + return list.ToImmutableAndClear(); } protected ImmutableArray AppendReturnStatementIfNeeded(ImmutableArray statements) diff --git a/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs b/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs index 89d32557d8d87..b3dc369273577 100644 --- a/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs +++ b/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs @@ -81,7 +81,7 @@ private static async Task> GetThirdPartyDefinitio result.AddIfNotNull(thirdParty); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static async Task FindSymbolReferencesAsync( diff --git a/src/Features/Core/Portable/GenerateComparisonOperators/GenerateComparisonOperatorsCodeRefactoringProvider.cs b/src/Features/Core/Portable/GenerateComparisonOperators/GenerateComparisonOperatorsCodeRefactoringProvider.cs index 37b6b8f905968..677bfa87e2373 100644 --- a/src/Features/Core/Portable/GenerateComparisonOperators/GenerateComparisonOperatorsCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/GenerateComparisonOperators/GenerateComparisonOperatorsCodeRefactoringProvider.cs @@ -205,7 +205,7 @@ private static ImmutableArray GenerateComparisonOperators( } } - return operators.ToImmutable(); + return operators.ToImmutableAndClear(); } private static SyntaxNode GenerateStatement( diff --git a/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs b/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs index c928cddf866f9..9a48f82069dc3 100644 --- a/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs @@ -104,7 +104,7 @@ await ComputeRefactoringsAsync( results.AddIfNotNull(intentResult); } - return results.ToImmutable(); + return results.ToImmutableAndClear(); static async Task GetIntentProcessorResultAsync( Document priorDocument, CodeAction codeAction, IProgress progressTracker, CancellationToken cancellationToken) @@ -280,7 +280,7 @@ private ImmutableArray GetCodeActions(Document document, State state if (state.DelegatedConstructor != null) result.Add(new ConstructorDelegatingCodeAction(this, document, state, addNullChecks, fallbackOptions)); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static async Task AddNavigationAnnotationAsync(Document document, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/GenerateDefaultConstructors/AbstractGenerateDefaultConstructorsService.cs b/src/Features/Core/Portable/GenerateDefaultConstructors/AbstractGenerateDefaultConstructorsService.cs index 0a44b64ad45b7..40bbda4c13000 100644 --- a/src/Features/Core/Portable/GenerateDefaultConstructors/AbstractGenerateDefaultConstructorsService.cs +++ b/src/Features/Core/Portable/GenerateDefaultConstructors/AbstractGenerateDefaultConstructorsService.cs @@ -50,7 +50,7 @@ public async Task> GenerateDefaultConstructorsAsync( } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } } } diff --git a/src/Features/Core/Portable/GenerateFromMembers/AbstractGenerateFromMembersCodeRefactoringProvider.cs b/src/Features/Core/Portable/GenerateFromMembers/AbstractGenerateFromMembersCodeRefactoringProvider.cs index 1a5d71ab6c46f..26eb5f27584f4 100644 --- a/src/Features/Core/Portable/GenerateFromMembers/AbstractGenerateFromMembersCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/GenerateFromMembers/AbstractGenerateFromMembersCodeRefactoringProvider.cs @@ -115,7 +115,7 @@ protected static ImmutableArray DetermineParameters( name: parameterName)); } - return parameters.ToImmutable(); + return parameters.ToImmutableAndClear(); } protected static readonly SymbolDisplayFormat SimpleFormat = diff --git a/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.cs b/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.cs index 2b673dbdbcb49..27c3d1936f32a 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.cs @@ -113,7 +113,7 @@ public async Task> GenerateConstructorAsync(Document c => state.GetChangedDocumentAsync(document, withFields: false, withProperties: false, c), nameof(FeaturesResources.Generate_constructor_in_0) + "_" + state.TypeToGenerateIn.Name)); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } } diff --git a/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateMethodService.State.cs b/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateMethodService.State.cs index 108f79783a531..326c90abfad9b 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateMethodService.State.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateMethodService.State.cs @@ -242,7 +242,7 @@ private static ImmutableArray GenerateParameterNamesBasedOnParameterType } NameGenerator.EnsureUniquenessInPlace(names, isFixed); - return names.ToImmutable(); + return names.ToImmutableAndClear(); } private static IMethodSymbol CreateMethodSymbolWithReturnType( diff --git a/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs b/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs index 9641bb4d73d38..425164cfe28bc 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs @@ -216,7 +216,7 @@ private async ValueTask> DetermineParametersAsy name: names[i].BestNameForParameter)); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private Accessibility DetermineAccessibility(bool isAbstract) diff --git a/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.cs b/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.cs index 4e7f7c1c47d7d..b5b1561c3b3a5 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.cs @@ -71,6 +71,6 @@ protected async ValueTask> GetActionsAsync(Document d } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } } diff --git a/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.cs b/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.cs index f1172510dd147..3a3b069c83707 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.cs @@ -87,7 +87,7 @@ public async Task> GenerateVariableAsync( isInlinable: true)]; } - return actions.ToImmutable(); + return actions.ToImmutableAndClear(); } } diff --git a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.GenerateNamedType.cs b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.GenerateNamedType.cs index a85787d4e4be3..f2bc225c4db8a 100644 --- a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.GenerateNamedType.cs +++ b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.GenerateNamedType.cs @@ -109,7 +109,7 @@ private async Task> DetermineMembersAsync(GenerateTypeOp if (_state.IsException) AddExceptionConstructors(members); - return members.ToImmutable(); + return members.ToImmutableAndClear(); } private async Task AddMembersAsync(ArrayBuilder members, GenerateTypeOptionsResult options = null) diff --git a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs index 3a45f46b1aa00..61df8079a4dbb 100644 --- a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs +++ b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs @@ -140,7 +140,7 @@ private ImmutableArray GetActions( if (generateNewTypeInDialog) result.Add(new GenerateTypeCodeActionWithOption((TService)this, document.Document, state, fallbackOptions)); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static bool CanGenerateIntoContainingNamespace(SemanticDocument semanticDocument, SyntaxNode node, CancellationToken cancellationToken) @@ -234,7 +234,7 @@ protected static ImmutableArray GetTypeParameters( typeParameters[i] = CodeGenerationSymbolFactory.CreateTypeParameterSymbol(names[i]); } - return typeParameters.ToImmutable(); + return typeParameters.ToImmutableAndClear(); } protected static Accessibility DetermineDefaultAccessibility( diff --git a/src/Features/Core/Portable/GoToDefinition/GoToDefinitionFeatureHelpers.cs b/src/Features/Core/Portable/GoToDefinition/GoToDefinitionFeatureHelpers.cs index 8320436f1d185..a28e87d1ad407 100644 --- a/src/Features/Core/Portable/GoToDefinition/GoToDefinitionFeatureHelpers.cs +++ b/src/Features/Core/Portable/GoToDefinition/GoToDefinitionFeatureHelpers.cs @@ -100,6 +100,6 @@ public static async Task> GetDefinitionsAsync( } definitions.Add(definitionItem); - return definitions.ToImmutable(); + return definitions.ToImmutableAndClear(); } } diff --git a/src/Features/Core/Portable/ImplementAbstractClass/ImplementAbstractClassData.cs b/src/Features/Core/Portable/ImplementAbstractClass/ImplementAbstractClassData.cs index 0a01da68140f6..f304e08c863d0 100644 --- a/src/Features/Core/Portable/ImplementAbstractClass/ImplementAbstractClassData.cs +++ b/src/Features/Core/Portable/ImplementAbstractClass/ImplementAbstractClassData.cs @@ -288,7 +288,7 @@ private bool ShouldGenerateAccessor([NotNullWhen(true)] IMethodSymbol? method) } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static bool InheritsFromOrEquals(ITypeSymbol type, ITypeSymbol baseType) diff --git a/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.CodeAction.cs b/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.CodeAction.cs index 335f52732a0c0..0a02004557f60 100644 --- a/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.CodeAction.cs +++ b/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.CodeAction.cs @@ -262,7 +262,7 @@ private ImmutableArray GenerateMembers( } } - return implementedMembers.ToImmutable(); + return implementedMembers.ToImmutableAndClear(); } private bool IsReservedName(string name) diff --git a/src/Features/Core/Portable/ImplementInterface/ImplementHelpers.cs b/src/Features/Core/Portable/ImplementInterface/ImplementHelpers.cs index 86e490d30d974..919364162fef8 100644 --- a/src/Features/Core/Portable/ImplementInterface/ImplementHelpers.cs +++ b/src/Features/Core/Portable/ImplementInterface/ImplementHelpers.cs @@ -62,7 +62,7 @@ ImmutableArray GetNonCapturedPrimaryConstructorParameters( } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } bool IsAssignedToFieldOrProperty(ImmutableArray fields, ImmutableArray properties, IParameterSymbol parameter) diff --git a/src/Features/Core/Portable/InheritanceMargin/AbstractInheritanceMarginService_Helpers.cs b/src/Features/Core/Portable/InheritanceMargin/AbstractInheritanceMarginService_Helpers.cs index 815e2bf225fc3..e81dc72b6dc5a 100644 --- a/src/Features/Core/Portable/InheritanceMargin/AbstractInheritanceMarginService_Helpers.cs +++ b/src/Features/Core/Portable/InheritanceMargin/AbstractInheritanceMarginService_Helpers.cs @@ -72,7 +72,7 @@ private static async ValueTask> GetSymbolI } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private async ValueTask<(Project remapped, SymbolAndLineNumberArray symbolAndLineNumbers)> GetMemberSymbolsAsync( @@ -145,7 +145,7 @@ private async Task> GetInheritanceMarginIt cancellationToken).ConfigureAwait(false)); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private async Task> GetGlobalImportsItemsAsync( @@ -269,7 +269,7 @@ private async Task> GetGlobalImportsItemsA } } - return items.ToImmutable(); + return items.ToImmutableAndClear(); } private static async ValueTask AddInheritanceMemberItemsForNamedTypeAsync( @@ -756,6 +756,6 @@ private static ImmutableArray GetNonNullTargetItems(Immut } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } diff --git a/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs b/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs index 1fd5cb23f3215..f806c61306e53 100644 --- a/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs +++ b/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs @@ -155,7 +155,7 @@ private async Task> HandleNoExistingFieldOrPropertyAs } } - return allActions.ToImmutable(); + return allActions.ToImmutableAndClear(); } private (CodeAction? fieldAction, CodeAction? propertyAction) AddAllParameterInitializationActions( @@ -239,7 +239,7 @@ private static ImmutableArray GetParametersWithoutAssociatedMe result.Add(parameter); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private ImmutableArray HandleExistingFieldOrProperty( diff --git a/src/Features/Core/Portable/InitializeParameter/InitializeParameterHelpersCore.cs b/src/Features/Core/Portable/InitializeParameter/InitializeParameterHelpersCore.cs index bdf337e0b4399..2621c07da0bfb 100644 --- a/src/Features/Core/Portable/InitializeParameter/InitializeParameterHelpersCore.cs +++ b/src/Features/Core/Portable/InitializeParameter/InitializeParameterHelpersCore.cs @@ -31,7 +31,7 @@ internal static class InitializeParameterHelpersCore siblings.Add((method.Parameters[i], before: false)); } - return siblings.ToImmutable(); + return siblings.ToImmutableAndClear(); } public static bool IsParameterReference(IOperation? operation, IParameterSymbol parameter) diff --git a/src/Features/Core/Portable/InlineHints/AbstractInlineParameterNameHintsService.cs b/src/Features/Core/Portable/InlineHints/AbstractInlineParameterNameHintsService.cs index 60f4bda8a6118..fbcb5d6321723 100644 --- a/src/Features/Core/Portable/InlineHints/AbstractInlineParameterNameHintsService.cs +++ b/src/Features/Core/Portable/InlineHints/AbstractInlineParameterNameHintsService.cs @@ -77,7 +77,7 @@ public async Task> GetInlineHintsAsync( } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); void AddHintsIfAppropriate(SyntaxNode node) { diff --git a/src/Features/Core/Portable/InlineHints/AbstractInlineTypeHintsService.cs b/src/Features/Core/Portable/InlineHints/AbstractInlineTypeHintsService.cs index bea7757ce632c..6f96cb42b46e4 100644 --- a/src/Features/Core/Portable/InlineHints/AbstractInlineTypeHintsService.cs +++ b/src/Features/Core/Portable/InlineHints/AbstractInlineTypeHintsService.cs @@ -86,7 +86,7 @@ public async Task> GetInlineHintsAsync( InlineHintHelpers.GetDescriptionFunction(span.Start, type.GetSymbolKey(cancellationToken: cancellationToken), displayOptions))); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static void AddParts( diff --git a/src/Features/Core/Portable/InlineMethod/AbstractInlineMethodRefactoringProvider.MethodParametersInfo.cs b/src/Features/Core/Portable/InlineMethod/AbstractInlineMethodRefactoringProvider.MethodParametersInfo.cs index 40c4c9d5b0db0..cf2beec68451b 100644 --- a/src/Features/Core/Portable/InlineMethod/AbstractInlineMethodRefactoringProvider.MethodParametersInfo.cs +++ b/src/Features/Core/Portable/InlineMethod/AbstractInlineMethodRefactoringProvider.MethodParametersInfo.cs @@ -456,7 +456,7 @@ private static async Task> GetArgumentsReadOn } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } /// diff --git a/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs b/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs index 09a60fe9f2cc8..c63a0565e4fcd 100644 --- a/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs @@ -419,7 +419,7 @@ private ImmutableArray GetSubsequentStatementRanges(TIfStatement innerStatement = (TStatementSyntax)node; } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private SyntaxNode GetRootWithInvertIfStatement( diff --git a/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/AbstractStructuralTypeDisplayService.cs b/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/AbstractStructuralTypeDisplayService.cs index a6fe4acda7d4e..f900b9c23ba54 100644 --- a/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/AbstractStructuralTypeDisplayService.cs +++ b/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/AbstractStructuralTypeDisplayService.cs @@ -55,7 +55,7 @@ private static ImmutableArray MassageDelegateParts( result.Add(part); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } public StructuralTypeDisplayInfo GetTypeDisplayInfo( @@ -205,7 +205,7 @@ private static ImmutableArray GetTransitiveStructuralTypeRefer result.Add(namedType); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } protected static IEnumerable LineBreak(int count = 1) diff --git a/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.DocCommentFormatter.cs b/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.DocCommentFormatter.cs index b3208168182ff..c8181bea8e72d 100644 --- a/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.DocCommentFormatter.cs +++ b/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.DocCommentFormatter.cs @@ -140,7 +140,7 @@ internal static ImmutableArray Format(IDocumentationCommentFormattingSer while (formattedCommentLinesBuilder is [.., { Length: 0 }]) formattedCommentLinesBuilder.RemoveAt(formattedCommentLinesBuilder.Count - 1); - return formattedCommentLinesBuilder.ToImmutable(); + return formattedCommentLinesBuilder.ToImmutableAndClear(); } private static void AddWrappedTextFromRawText( diff --git a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs index 468ab3d47b214..bf2831289f9b8 100644 --- a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs +++ b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs @@ -87,7 +87,7 @@ private static ImmutableArray CreateRenameOperations(MoveTo } } - return operations.ToImmutable(); + return operations.ToImmutableAndClear(); } public static AbstractMoveToNamespaceCodeAction Generate(IMoveToNamespaceService changeNamespaceService, MoveToNamespaceAnalysisResult analysisResult, CodeCleanupOptionsProvider cleanupOptions) diff --git a/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs b/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs index 730f4cac07699..5224895958359 100644 --- a/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs +++ b/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs @@ -239,7 +239,7 @@ private static async ValueTask> GetAdditionalProjectsW } result.RemoveDuplicates(); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static string GetItemKind(DeclaredSymbolInfo declaredSymbolInfo) diff --git a/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs b/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs index fc90beeb18284..85ef7d099d162 100644 --- a/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs +++ b/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs @@ -339,7 +339,7 @@ private ImmutableArray GetPriorityDocuments(ImmutableArray pr } result.RemoveDuplicates(); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private async Task ProcessOrderedProjectsAsync( diff --git a/src/Features/Core/Portable/PdbSourceDocument/DocumentDebugInfoReader.cs b/src/Features/Core/Portable/PdbSourceDocument/DocumentDebugInfoReader.cs index c6e7b17c593ca..b01e635db8630 100644 --- a/src/Features/Core/Portable/PdbSourceDocument/DocumentDebugInfoReader.cs +++ b/src/Features/Core/Portable/PdbSourceDocument/DocumentDebugInfoReader.cs @@ -54,7 +54,7 @@ public ImmutableArray FindSourceDocuments(EntityHandle entityHan sourceDocuments.Add(new SourceDocument(filePath, hashAlgorithm, checksum, embeddedTextBytes, sourceLinkUrl)); } - return sourceDocuments.ToImmutable(); + return sourceDocuments.ToImmutableAndClear(); } private string? TryGetSourceLinkUrl(DocumentHandle handle) diff --git a/src/Features/Core/Portable/PdbSourceDocument/PdbSourceDocumentMetadataAsSourceFileProvider.cs b/src/Features/Core/Portable/PdbSourceDocument/PdbSourceDocumentMetadataAsSourceFileProvider.cs index 10e1a2dcfa4c3..240ad43429469 100644 --- a/src/Features/Core/Portable/PdbSourceDocument/PdbSourceDocumentMetadataAsSourceFileProvider.cs +++ b/src/Features/Core/Portable/PdbSourceDocument/PdbSourceDocumentMetadataAsSourceFileProvider.cs @@ -338,7 +338,7 @@ private ImmutableArray CreateDocumentInfos( _fileToDocumentInfoMap[info.FilePath] = new(documentId, encoding, info.ChecksumAlgorithm, sourceProject.Id, sourceWorkspace); } - return documents.ToImmutable(); + return documents.ToImmutableAndClear(); } private static void AssertIsMainThread(MetadataAsSourceWorkspace workspace) diff --git a/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs b/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs index 56ad59f47dbcb..d46f18607c8b7 100644 --- a/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs @@ -424,7 +424,7 @@ private static async Task> GetGetSetPairsAsync( } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static TSymbol? GetSymbolInCurrentCompilation(Compilation compilation, TSymbol originalDefinition, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs b/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs index 035108f29721b..32eecb93707fd 100644 --- a/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs @@ -412,7 +412,7 @@ private static async Task ReplaceDefinitionsWithMethodsAsync( result.Add((property, declaration)); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static async Task GetPropertyDeclarationAsync( diff --git a/src/Features/Core/Portable/Shared/Utilities/ExtractTypeHelpers.cs b/src/Features/Core/Portable/Shared/Utilities/ExtractTypeHelpers.cs index 574e0035ee1ce..fb6c7614baeab 100644 --- a/src/Features/Core/Portable/Shared/Utilities/ExtractTypeHelpers.cs +++ b/src/Features/Core/Portable/Shared/Utilities/ExtractTypeHelpers.cs @@ -180,7 +180,7 @@ private static ImmutableArray GetPotentialTypeParameters(I typeParameters.AddRange(typesToVisit.Pop().TypeParameters); } - return typeParameters.ToImmutable(); + return typeParameters.ToImmutableAndClear(); } private static ImmutableArray GetDirectlyReferencedTypeParameters(IEnumerable potentialTypeParameters, IEnumerable includedMembers) @@ -194,7 +194,7 @@ private static ImmutableArray GetDirectlyReferencedTypePar } } - return directlyReferencedTypeParameters.ToImmutable(); + return directlyReferencedTypeParameters.ToImmutableAndClear(); } private static bool DoesMemberReferenceTypeParameter(ISymbol member, ITypeParameterSymbol typeParameter, HashSet checkedTypes) diff --git a/src/Features/Core/Portable/SignatureHelp/AbstractSignatureHelpProvider.cs b/src/Features/Core/Portable/SignatureHelp/AbstractSignatureHelpProvider.cs index 9016af082906d..a4d8ee47c11db 100644 --- a/src/Features/Core/Portable/SignatureHelp/AbstractSignatureHelpProvider.cs +++ b/src/Features/Core/Portable/SignatureHelp/AbstractSignatureHelpProvider.cs @@ -313,7 +313,7 @@ private static async Task> FindActiveRelatedDocumentsAs } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private static SignatureHelpItem UpdateItem(SignatureHelpItem item, SupportedPlatformData platformData) diff --git a/src/Features/Core/Portable/Snippets/AbstractSnippetService.cs b/src/Features/Core/Portable/Snippets/AbstractSnippetService.cs index b61c196c6c36c..55e4cbe47b1f9 100644 --- a/src/Features/Core/Portable/Snippets/AbstractSnippetService.cs +++ b/src/Features/Core/Portable/Snippets/AbstractSnippetService.cs @@ -46,7 +46,7 @@ public async Task> GetSnippetsAsync(SnippetContext c arrayBuilder.AddIfNotNull(snippetData); } - return arrayBuilder.ToImmutable(); + return arrayBuilder.ToImmutableAndClear(); } private ImmutableArray GetSnippetProviders(Document document) diff --git a/src/Features/Core/Portable/SpellCheck/AbstractSpellCheckSpanService.cs b/src/Features/Core/Portable/SpellCheck/AbstractSpellCheckSpanService.cs index fb4791044b82f..e2db8f7469e60 100644 --- a/src/Features/Core/Portable/SpellCheck/AbstractSpellCheckSpanService.cs +++ b/src/Features/Core/Portable/SpellCheck/AbstractSpellCheckSpanService.cs @@ -37,7 +37,7 @@ ImmutableArray GetSpans() var worker = new Worker(this, syntaxFacts, classifier, virtualCharService, spans); worker.Recurse(root, cancellationToken); - return spans.ToImmutable(); + return spans.ToImmutableAndClear(); } } diff --git a/src/Features/Core/Portable/StackTraceExplorer/StackTraceAnalyzer.cs b/src/Features/Core/Portable/StackTraceExplorer/StackTraceAnalyzer.cs index e6f787106845b..8ddf4c63ed6e3 100644 --- a/src/Features/Core/Portable/StackTraceExplorer/StackTraceAnalyzer.cs +++ b/src/Features/Core/Portable/StackTraceExplorer/StackTraceAnalyzer.cs @@ -67,7 +67,7 @@ private static ImmutableArray Parse(string callstack, CancellationT } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private static IEnumerable SplitLines(VirtualCharSequence callstack) diff --git a/src/Features/Core/Portable/TaskList/AbstractTaskListService.cs b/src/Features/Core/Portable/TaskList/AbstractTaskListService.cs index 304745a969900..4fffe4664dde4 100644 --- a/src/Features/Core/Portable/TaskList/AbstractTaskListService.cs +++ b/src/Features/Core/Portable/TaskList/AbstractTaskListService.cs @@ -73,7 +73,7 @@ private async Task> GetTaskListItemsInProcessAsync( AppendTaskListItems(descriptors, syntaxDoc, trivia, items); } - return items.ToImmutable(); + return items.ToImmutableAndClear(); } private bool ContainsComments(SyntaxTrivia trivia) diff --git a/src/Features/Core/Portable/UnusedReferences/UnusedReferencesRemover.cs b/src/Features/Core/Portable/UnusedReferences/UnusedReferencesRemover.cs index 6b52fabbaec56..a6ef0fb053b04 100644 --- a/src/Features/Core/Portable/UnusedReferences/UnusedReferencesRemover.cs +++ b/src/Features/Core/Portable/UnusedReferences/UnusedReferencesRemover.cs @@ -121,7 +121,7 @@ internal static ImmutableArray GetUnusedReferences( unusedReferencesBuilder.AddRange(unusedReferences); } - return unusedReferencesBuilder.ToImmutable(); + return unusedReferencesBuilder.ToImmutableAndClear(); } private static ImmutableArray RemoveDirectlyUsedReferences( @@ -177,7 +177,7 @@ private static ImmutableArray RemoveDirectlyUsedReferences( RemoveAllCompilationAssemblies(reference, usedAssemblyFilePaths); } - return unusedReferencesBuilder.ToImmutable(); + return unusedReferencesBuilder.ToImmutableAndClear(); } private static ImmutableArray RemoveTransitivelyUsedReferences( @@ -219,7 +219,7 @@ private static ImmutableArray RemoveTransitivelyUsedReferences( RemoveAllCompilationAssemblies(reference, usedAssemblyFilePaths); } - return unusedReferencesBuilder.ToImmutable(); + return unusedReferencesBuilder.ToImmutableAndClear(); } internal static bool HasAnyCompilationAssembly(ReferenceInfo reference) diff --git a/src/Features/Core/Portable/Workspace/CompileTimeSolutionProvider.cs b/src/Features/Core/Portable/Workspace/CompileTimeSolutionProvider.cs index 9c47cb263583d..e9e4b2bd13245 100644 --- a/src/Features/Core/Portable/Workspace/CompileTimeSolutionProvider.cs +++ b/src/Features/Core/Portable/Workspace/CompileTimeSolutionProvider.cs @@ -287,7 +287,7 @@ internal static async Task> GetDesignTimeDocumentsAsy } compileTimeFilePathsByProject.FreeValues(); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } } } diff --git a/src/Features/Core/Portable/Wrapping/BinaryExpression/AbstractBinaryExpressionWrapper.cs b/src/Features/Core/Portable/Wrapping/BinaryExpression/AbstractBinaryExpressionWrapper.cs index 5fdf919e4568d..12d3eb0980a70 100644 --- a/src/Features/Core/Portable/Wrapping/BinaryExpression/AbstractBinaryExpressionWrapper.cs +++ b/src/Features/Core/Portable/Wrapping/BinaryExpression/AbstractBinaryExpressionWrapper.cs @@ -98,7 +98,7 @@ private ImmutableArray GetExpressionsAndOperators( { using var _ = ArrayBuilder.GetInstance(out var result); AddExpressionsAndOperators(precedence, binaryExpr, result); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private void AddExpressionsAndOperators( diff --git a/src/Features/Core/Portable/Wrapping/BinaryExpression/BinaryExpressionCodeActionComputer.cs b/src/Features/Core/Portable/Wrapping/BinaryExpression/BinaryExpressionCodeActionComputer.cs index 9cbcd65cfeeb5..5dcef3f9ee1ca 100644 --- a/src/Features/Core/Portable/Wrapping/BinaryExpression/BinaryExpressionCodeActionComputer.cs +++ b/src/Features/Core/Portable/Wrapping/BinaryExpression/BinaryExpressionCodeActionComputer.cs @@ -115,7 +115,7 @@ private ImmutableArray GetWrapEdits(bool align) } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private ImmutableArray GetUnwrapEdits() @@ -129,7 +129,7 @@ private ImmutableArray GetUnwrapEdits() NoTrivia, _exprsAndOperators[i + 1])); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } } } diff --git a/src/Features/Core/Portable/Wrapping/ChainedExpression/AbstractChainedExpressionWrapper.cs b/src/Features/Core/Portable/Wrapping/ChainedExpression/AbstractChainedExpressionWrapper.cs index e6e6743f9622e..120c904887019 100644 --- a/src/Features/Core/Portable/Wrapping/ChainedExpression/AbstractChainedExpressionWrapper.cs +++ b/src/Features/Core/Portable/Wrapping/ChainedExpression/AbstractChainedExpressionWrapper.cs @@ -132,7 +132,7 @@ private ImmutableArray> GetChainChunks(SyntaxN using var _2 = ArrayBuilder>.GetInstance(out var chunks); BreakPiecesIntoChunks(pieces, chunks); - return chunks.ToImmutable(); + return chunks.ToImmutableAndClear(); } private void BreakPiecesIntoChunks( diff --git a/src/Features/Core/Portable/Wrapping/ChainedExpression/ChainedExpressionCodeActionComputer.cs b/src/Features/Core/Portable/Wrapping/ChainedExpression/ChainedExpressionCodeActionComputer.cs index 50579e88e56c2..a31c0171fa21c 100644 --- a/src/Features/Core/Portable/Wrapping/ChainedExpression/ChainedExpressionCodeActionComputer.cs +++ b/src/Features/Core/Portable/Wrapping/ChainedExpression/ChainedExpressionCodeActionComputer.cs @@ -163,7 +163,7 @@ private ImmutableArray GetWrapEdits(int wrappingColumn, bool align) position += NormalizedWidth(chunk); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static int NormalizedWidth(ImmutableArray chunk) @@ -178,7 +178,7 @@ private ImmutableArray GetUnwrapEdits() var flattened = _chunks.SelectManyAsArray(c => c); DeleteAllSpacesInChunk(result, flattened); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static void DeleteAllSpacesInChunk( diff --git a/src/Features/Core/Portable/Wrapping/SeparatedSyntaxList/SeparatedSyntaxListCodeActionComputer.cs b/src/Features/Core/Portable/Wrapping/SeparatedSyntaxList/SeparatedSyntaxListCodeActionComputer.cs index 40c4321579d54..a9d2659ee3c21 100644 --- a/src/Features/Core/Portable/Wrapping/SeparatedSyntaxList/SeparatedSyntaxListCodeActionComputer.cs +++ b/src/Features/Core/Portable/Wrapping/SeparatedSyntaxList/SeparatedSyntaxListCodeActionComputer.cs @@ -217,7 +217,7 @@ private ImmutableArray GetUnwrapAllEdits(WrappingStyle wrappingStyle) if (last.IsNode) result.Add(Edit.DeleteBetween(last, _listSyntax.GetLastToken())); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } #endregion @@ -342,7 +342,7 @@ private ImmutableArray GetWrapLongLinesEdits( result.Add(Edit.DeleteBetween(itemsAndSeparators.Last(), _listSyntax.GetLastToken())); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } #endregion @@ -445,7 +445,7 @@ private ImmutableArray GetWrapEachEdits( result.Add(Edit.DeleteBetween(itemsAndSeparators.Last(), _listSyntax.GetLastToken())); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } #endregion diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Testing/TestDiscoverer.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Testing/TestDiscoverer.cs index 8ecd99cba7114..7237daa8f6cb9 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Testing/TestDiscoverer.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Testing/TestDiscoverer.cs @@ -105,6 +105,6 @@ private async Task> MatchDiscoveredTestsToTestsInRangeA } _logger.LogDebug($"Filtered {discoveredTests.Length} to {matchedTests.Count} tests"); - return matchedTests.ToImmutable(); + return matchedTests.ToImmutableAndClear(); } } diff --git a/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs b/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs index f29feac5079e7..a50adc0b63f24 100644 --- a/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs +++ b/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs @@ -659,7 +659,7 @@ private static async Task> GetCodeFixesAsync( var task = fixer.RegisterCodeFixesAsync(context) ?? Task.CompletedTask; await task.ConfigureAwait(false); - return fixes.ToImmutable(); + return fixes.ToImmutableAndClear(); static ImmutableArray FilterApplicableDiagnostics( ImmutableArray applicableDiagnostics, @@ -938,7 +938,7 @@ static ImmutableArray GetConfigurationFixProviders(Im builder.Add(languageKindAndFixersValue.Value); } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.ProjectStates.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.ProjectStates.cs index 7d36dfaca4e24..9687fa9cc85d9 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.ProjectStates.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.ProjectStates.cs @@ -177,7 +177,7 @@ private static ImmutableArray DiffStateSets( } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } } diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs index ef77efe45ac21..735e983e73719 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs @@ -52,7 +52,7 @@ public async Task> GetDiagnosticsForSpanAsync( document, range, list, shouldIncludeDiagnostic, includeSuppressedDiagnostics, includeCompilerDiagnostics, priorityProvider, blockForData, addOperationScope, diagnosticKinds, isExplicit, cancellationToken).ConfigureAwait(false); Debug.Assert(result); - return list.ToImmutable(); + return list.ToImmutableAndClear(); } /// diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs index 118e5133c645e..af943468881a4 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs @@ -53,7 +53,7 @@ public async Task> ForceAnalyzeProjectAsync(Proje } } - return diagnostics.ToImmutable(); + return diagnostics.ToImmutableAndClear(); } catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken)) { diff --git a/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActionsSource.cs b/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActionsSource.cs index 75513230f0080..e5cd699d5d641 100644 --- a/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActionsSource.cs +++ b/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActionsSource.cs @@ -774,7 +774,7 @@ private static ImmutableArray FilterActionSetsByTitle } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static UnifiedSuggestedActionSet? FilterActionSetByTitle(UnifiedSuggestedActionSet set, HashSet seenTitles) diff --git a/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionHelpers.cs b/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionHelpers.cs index a0fa0af6eef3a..b8ac33f20ddb6 100644 --- a/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionHelpers.cs +++ b/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionHelpers.cs @@ -165,7 +165,7 @@ private static LSP.CodeAction[] GenerateCodeActions( } } - return nestedCodeActions.ToImmutable(); + return nestedCodeActions.ToImmutableAndClear(); } private static void AddLSPCodeActions( @@ -338,7 +338,7 @@ public static async Task> GetCodeActionsAsync( } } - return codeActions.ToImmutable(); + return codeActions.ToImmutableAndClear(); } /// diff --git a/src/Features/LanguageServer/Protocol/Handler/Configuration/DidChangeConfigurationNotificationHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Configuration/DidChangeConfigurationNotificationHandler.cs index bdff74a62be0a..c61ec8ca969a1 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Configuration/DidChangeConfigurationNotificationHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Configuration/DidChangeConfigurationNotificationHandler.cs @@ -152,7 +152,7 @@ private async Task> GetConfigurationsAsync(CancellationTo } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } /// @@ -185,7 +185,7 @@ private static ImmutableArray GenerateGlobalConfigurationItem } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } /// diff --git a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractWorkspacePullDiagnosticsHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractWorkspacePullDiagnosticsHandler.cs index d39af98d94d7b..d45959627ed45 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractWorkspacePullDiagnosticsHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Diagnostics/AbstractWorkspacePullDiagnosticsHandler.cs @@ -127,7 +127,7 @@ private static ImmutableArray GetTaskListDiagnosticSources( } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } public static async ValueTask> GetDiagnosticSourcesAsync( @@ -144,7 +144,7 @@ public static async ValueTask> GetDiagnosticSo foreach (var project in GetProjectsInPriorityOrder(solution, context.SupportedLanguages)) await AddDocumentsAndProjectAsync(project, cancellationToken).ConfigureAwait(false); - return result.ToImmutable(); + return result.ToImmutableAndClear(); async Task AddDocumentsAndProjectAsync(Project project, CancellationToken cancellationToken) { diff --git a/src/Features/LanguageServer/Protocol/Handler/MapCode/MapCodeHandler.cs b/src/Features/LanguageServer/Protocol/Handler/MapCode/MapCodeHandler.cs index 7d8070437a6cb..3967261f2131d 100644 --- a/src/Features/LanguageServer/Protocol/Handler/MapCode/MapCodeHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/MapCode/MapCodeHandler.cs @@ -134,7 +134,7 @@ public MapCodeHandler() } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } } diff --git a/src/Features/LanguageServer/Protocol/Handler/SpellCheck/WorkspaceSpellCheckHandler.cs b/src/Features/LanguageServer/Protocol/Handler/SpellCheck/WorkspaceSpellCheckHandler.cs index b8ce56eb1cd0b..ba22db3d056ec 100644 --- a/src/Features/LanguageServer/Protocol/Handler/SpellCheck/WorkspaceSpellCheckHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/SpellCheck/WorkspaceSpellCheckHandler.cs @@ -56,7 +56,7 @@ protected override ImmutableArray GetOrderedDocuments(RequestContext c // Ensure that we only process documents once. result.RemoveDuplicates(); - return result.ToImmutable(); + return result.ToImmutableAndClear(); void AddDocumentsFromProject(Project? project, ImmutableArray supportedLanguages) { diff --git a/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs b/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs index 3c84bd75aeb67..ba01e7d11e979 100644 --- a/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs +++ b/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs @@ -285,7 +285,7 @@ public void UpdateTrackedDocument(Uri uri, SourceText newSourceText) solutions.Add((workspace, lspSolution, isForked)); } - return solutions.ToImmutable(); + return solutions.ToImmutableAndClear(); async Task<(Solution Solution, bool IsForked)> GetLspSolutionForWorkspaceAsync(Workspace workspace, CancellationToken cancellationToken) { diff --git a/src/Features/TestUtilities/EditAndContinue/ActiveStatementsDescription.cs b/src/Features/TestUtilities/EditAndContinue/ActiveStatementsDescription.cs index 9685f82743816..916f551d29251 100644 --- a/src/Features/TestUtilities/EditAndContinue/ActiveStatementsDescription.cs +++ b/src/Features/TestUtilities/EditAndContinue/ActiveStatementsDescription.cs @@ -152,7 +152,7 @@ internal static ImmutableArray GetUnmappedActiveStateme } activeStatements.Sort((x, y) => x.Statement.Id.Ordinal.CompareTo(y.Statement.Id.Ordinal)); - return activeStatements.ToImmutable(); + return activeStatements.ToImmutableAndClear(); } internal static ImmutableArray GetActiveStatementDebugInfos( diff --git a/src/VisualStudio/CSharp/Test/DocumentOutline/DocumentOutlineTests.cs b/src/VisualStudio/CSharp/Test/DocumentOutline/DocumentOutlineTests.cs index c412b53e936d2..4c215eafae28e 100644 --- a/src/VisualStudio/CSharp/Test/DocumentOutline/DocumentOutlineTests.cs +++ b/src/VisualStudio/CSharp/Test/DocumentOutline/DocumentOutlineTests.cs @@ -88,7 +88,7 @@ static ImmutableArray SortDocumentSymbols( sortedDocumentSymbols.Add(ReplaceChildren(documentSymbol, sortedChildren)); } - return sortedDocumentSymbols.ToImmutable(); + return sortedDocumentSymbols.ToImmutableAndClear(); } static ImmutableArray Sort(ImmutableArray items, SortOption sortOption) diff --git a/src/VisualStudio/Core/Def/CodeLens/RemoteCodeLensReferencesService.cs b/src/VisualStudio/Core/Def/CodeLens/RemoteCodeLensReferencesService.cs index 333a63a045f85..cc9705260d5f7 100644 --- a/src/VisualStudio/Core/Def/CodeLens/RemoteCodeLensReferencesService.cs +++ b/src/VisualStudio/Core/Def/CodeLens/RemoteCodeLensReferencesService.cs @@ -207,7 +207,7 @@ private async Task> FixUpDescriptors after2)); } - return list.ToImmutable(); + return list.ToImmutableAndClear(); } private static (string text, int start, int length) GetReferenceInfo(ExcerptResult? reference, ReferenceLocationDescriptor descriptor) diff --git a/src/VisualStudio/Core/Def/DocumentOutline/DocumentOutlineViewModel_Utilities.cs b/src/VisualStudio/Core/Def/DocumentOutline/DocumentOutlineViewModel_Utilities.cs index 789dc0c6c2760..02b9a463842bd 100644 --- a/src/VisualStudio/Core/Def/DocumentOutline/DocumentOutlineViewModel_Utilities.cs +++ b/src/VisualStudio/Core/Def/DocumentOutline/DocumentOutlineViewModel_Utilities.cs @@ -120,7 +120,7 @@ public static ImmutableArray CreateDocumentSymbolData(JToken while (currentStart < allSymbols.Length) finalResult.Add(NestDescendantSymbols(allSymbols, currentStart, out currentStart)); - return finalResult.ToImmutable(); + return finalResult.ToImmutableAndClear(); // Returns the symbol in the list at index start (the parent symbol) with the following symbols in the list // (descendants) appropriately nested into the parent. @@ -226,7 +226,7 @@ public static ImmutableArray SearchDocumentSymbolData( filteredDocumentSymbols.Add(documentSymbol with { Children = filteredChildren }); } - return filteredDocumentSymbols.ToImmutable(); + return filteredDocumentSymbols.ToImmutableAndClear(); // Returns true if the name of one of the tree nodes results in a pattern match. static bool SearchNodeTree(DocumentSymbolData tree, PatternMatcher patternMatcher, CancellationToken cancellationToken) diff --git a/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginHelpers.cs b/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginHelpers.cs index 786b749e85cc1..b9764f5656baa 100644 --- a/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginHelpers.cs +++ b/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginHelpers.cs @@ -191,6 +191,6 @@ public static ImmutableArray CreateMenuItemsWithHeader( builder.Add(TargetMenuItemViewModel.Create(target, target.DisplayName)); } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } diff --git a/src/VisualStudio/Core/Def/Library/ObjectBrowser/AbstractListItemFactory.cs b/src/VisualStudio/Core/Def/Library/ObjectBrowser/AbstractListItemFactory.cs index cc6478b12b1c2..be5372c39863d 100644 --- a/src/VisualStudio/Core/Def/Library/ObjectBrowser/AbstractListItemFactory.cs +++ b/src/VisualStudio/Core/Def/Library/ObjectBrowser/AbstractListItemFactory.cs @@ -174,7 +174,7 @@ private static ImmutableArray CreateListItemsFromSymbols( @@ -283,7 +283,7 @@ public ImmutableArray GetFolderListItems(ObjectListItem parentLi } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private ImmutableArray GetMemberListItems( @@ -309,7 +309,7 @@ private ImmutableArray GetMemberListItems( AddListItemsFromSymbols(inheritedMembers, compilation, projectId, CreateInheritedMemberListItem, builder); } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private static ImmutableArray GetMemberSymbols(INamedTypeSymbol namedTypeSymbol, Compilation compilation) @@ -325,7 +325,7 @@ private static ImmutableArray GetMemberSymbols(INamedTypeSymbol namedTy } } - return symbolBuilder.ToImmutable(); + return symbolBuilder.ToImmutableAndClear(); } private static ImmutableArray GetInheritedMemberSymbols(INamedTypeSymbol namedTypeSymbol, Compilation compilation) @@ -367,7 +367,7 @@ private static ImmutableArray GetInheritedMemberSymbols(INamedTypeSymbo } } - return symbolBuilder.ToImmutable(); + return symbolBuilder.ToImmutableAndClear(); } private static void AddOverriddenMembers(INamedTypeSymbol namedTypeSymbol, ref HashSet overriddenMembers) @@ -451,7 +451,7 @@ public ImmutableArray GetNamespaceListItems(ObjectListItem paren CollectNamespaceListItems(assemblySymbol, parentListItem.ProjectId, builder, searchString: null); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private class AssemblySymbolComparer : IEqualityComparer> @@ -562,7 +562,7 @@ private static ImmutableArray GetAccessibleTypeMembers(INamesp } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private static bool IncludeTypeMember(INamedTypeSymbol typeMember, IAssemblySymbol assemblySymbol) @@ -636,7 +636,7 @@ public ImmutableArray GetProjectListItems(Solution solution, str projectListItemBuilder.AddRange(referenceListItemBuilder); - return projectListItemBuilder.ToImmutable(); + return projectListItemBuilder.ToImmutableAndClear(); } public ImmutableArray GetReferenceListItems(ObjectListItem parentListItem, Compilation compilation) @@ -687,7 +687,7 @@ private static ImmutableArray GetAccessibleTypes(INamespaceSym } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private ImmutableArray GetTypeListItems( @@ -718,7 +718,7 @@ private ImmutableArray GetTypeListItems( } } - return finalBuilder.ToImmutable(); + return finalBuilder.ToImmutableAndClear(); } public ImmutableArray GetTypeListItems(ObjectListItem parentListItem, Compilation compilation) diff --git a/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs b/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs index 637147bbaa7c4..c2102cb3edb89 100644 --- a/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs +++ b/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs @@ -669,7 +669,7 @@ public ImmutableArray GetProjectsWithInstalledPackage(Solution solution } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } public bool CanShowManagePackagesDialog() diff --git a/src/VisualStudio/Core/Def/Progression/GraphProvider.cs b/src/VisualStudio/Core/Def/Progression/GraphProvider.cs index 04cb9c0d82a26..3a9ce9b855f0b 100644 --- a/src/VisualStudio/Core/Def/Progression/GraphProvider.cs +++ b/src/VisualStudio/Core/Def/Progression/GraphProvider.cs @@ -155,7 +155,7 @@ public static ImmutableArray GetGraphQueries(IGraphContext context) } } - return graphQueries.ToImmutable(); + return graphQueries.ToImmutableAndClear(); } public void BeginGetGraphData(IGraphContext context) diff --git a/src/VisualStudio/Core/Def/Progression/GraphQueries/CallsGraphQuery.cs b/src/VisualStudio/Core/Def/Progression/GraphQueries/CallsGraphQuery.cs index 9ccf6ac974df6..d4c269556a082 100644 --- a/src/VisualStudio/Core/Def/Progression/GraphQueries/CallsGraphQuery.cs +++ b/src/VisualStudio/Core/Def/Progression/GraphQueries/CallsGraphQuery.cs @@ -60,6 +60,6 @@ private static async Task> GetCalledMethodSymbolsAsync( } } - return symbols.ToImmutable(); + return symbols.ToImmutableAndClear(); } } diff --git a/src/VisualStudio/Core/Def/Progression/SymbolContainment.cs b/src/VisualStudio/Core/Def/Progression/SymbolContainment.cs index 87dab244f14ca..0b298e0553561 100644 --- a/src/VisualStudio/Core/Def/Progression/SymbolContainment.cs +++ b/src/VisualStudio/Core/Def/Progression/SymbolContainment.cs @@ -52,7 +52,7 @@ public static async Task> GetContainedSymbolsAsync(Docum } } - return symbols.ToImmutable(); + return symbols.ToImmutableAndClear(); } private static bool IsTopLevelSymbol(ISymbol symbol) diff --git a/src/VisualStudio/Core/Def/Snippets/AbstractSnippetInfoService.cs b/src/VisualStudio/Core/Def/Snippets/AbstractSnippetInfoService.cs index 39c4945ba8550..4bee6e1386125 100644 --- a/src/VisualStudio/Core/Def/Snippets/AbstractSnippetInfoService.cs +++ b/src/VisualStudio/Core/Def/Snippets/AbstractSnippetInfoService.cs @@ -209,7 +209,7 @@ private ImmutableArray ExtractSnippetInfo(IVsExpansionEnumeration e Marshal.FreeCoTaskMem(pSnippetInfo[0]); } - return snippetListBuilder.ToImmutable(); + return snippetListBuilder.ToImmutableAndClear(); } protected static IImmutableSet GetShortcutsHashFromSnippets(ImmutableArray updatedSnippets) diff --git a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListSuppressionStateService.cs b/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListSuppressionStateService.cs index 51e583cf2dc4d..ffba254c0b0e0 100644 --- a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListSuppressionStateService.cs +++ b/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListSuppressionStateService.cs @@ -326,7 +326,7 @@ public async Task> GetSelectedItemsAsync(bool isA } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private static async Task> GetFilePathToDocumentMapAsync(Project project, CancellationToken cancellationToken) diff --git a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioSuppressionFixService.cs b/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioSuppressionFixService.cs index fe87d2561bea2..a1335ea259327 100644 --- a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioSuppressionFixService.cs +++ b/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioSuppressionFixService.cs @@ -199,7 +199,7 @@ private async Task> GetAllBuildDiagnosticsAsync(F } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private static string GetFixTitle(bool isAddSuppression) diff --git a/src/VisualStudio/Core/Def/TaskList/ExternalErrorDiagnosticUpdateSource.cs b/src/VisualStudio/Core/Def/TaskList/ExternalErrorDiagnosticUpdateSource.cs index 4b7bfc4f1a93b..d5440f5d2d032 100644 --- a/src/VisualStudio/Core/Def/TaskList/ExternalErrorDiagnosticUpdateSource.cs +++ b/src/VisualStudio/Core/Def/TaskList/ExternalErrorDiagnosticUpdateSource.cs @@ -697,7 +697,7 @@ public ImmutableArray GetLiveErrors() allLiveErrorsBuilder.AddRange(errors); } - return allLiveErrorsBuilder.ToImmutable(); + return allLiveErrorsBuilder.ToImmutableAndClear(); // Local functions. IEnumerable GetProjectsWithErrors() @@ -728,7 +728,7 @@ public ImmutableArray GetLiveErrorsForProject(ProjectId projectI } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } public void AddErrors(DocumentId key, HashSet diagnostics) diff --git a/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs b/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs index 45fdb1c714ec7..1a9747fc226a7 100644 --- a/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs +++ b/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs @@ -366,7 +366,7 @@ private static ImmutableArray> Permute(T[] values) { using var _ = ArrayBuilder>.GetInstance(out var result); DoPermute(0, values.Length - 1); - return result.ToImmutable(); + return result.ToImmutableAndClear(); void DoPermute(int start, int end) { diff --git a/src/Workspaces/CSharp/Portable/Recommendations/CSharpRecommendationServiceRunner.cs b/src/Workspaces/CSharp/Portable/Recommendations/CSharpRecommendationServiceRunner.cs index 45d57037d405e..e50eb4f4a3c07 100644 --- a/src/Workspaces/CSharp/Portable/Recommendations/CSharpRecommendationServiceRunner.cs +++ b/src/Workspaces/CSharp/Portable/Recommendations/CSharpRecommendationServiceRunner.cs @@ -824,7 +824,7 @@ private ImmutableArray GetUnnamedSymbols(ExpressionSyntax originalExpre AddOperators(container, symbols); AddConversions(container, symbols); - return symbols.ToImmutable(); + return symbols.ToImmutableAndClear(); } private ITypeSymbol? GetContainerForUnnamedSymbols(SemanticModel semanticModel, ExpressionSyntax originalExpression) diff --git a/src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs b/src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs index c3b3bdfc853cd..23f2b73784bed 100644 --- a/src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs +++ b/src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs @@ -927,7 +927,7 @@ renamedSymbol.ContainingSymbol is IMethodSymbol methodSymbol && } } - return conflicts.ToImmutable(); + return conflicts.ToImmutableAndClear(); } catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken)) { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs b/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs index f188a353ef30f..4bfd90f760c37 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs @@ -164,7 +164,7 @@ private void EnsureMSBuildLoaded(string projectFilePath) } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } /// diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs index 53deba14cf6e3..5dfb1ce15e263 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs @@ -94,7 +94,7 @@ public async Task> GetProjectFileInfosAsync(Canc _loadedProject.ReevaluateIfNecessary(); - return results.ToImmutable(); + return results.ToImmutableAndClear(); } else { diff --git a/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs b/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs index c20e6b522a7a4..4b99843f78856 100644 --- a/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs +++ b/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs @@ -166,7 +166,7 @@ public async Task> LoadAsync(CancellationToken cance } } - return results.ToImmutable(); + return results.ToImmutableAndClear(); } private async Task> LoadProjectFileInfosAsync(string projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken) @@ -453,7 +453,7 @@ private ImmutableArray CreateDocumentInfos(IReadOnlyList GetUnresolvedMetadataReferenc } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private ImmutableArray GetMetadataReferences() @@ -173,7 +173,7 @@ private ImmutableArray GetMetadataReferences() } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private ImmutableHashSet GetProjectReferences() diff --git a/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs b/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs index cb76d362524a5..8af7ec97ac916 100644 --- a/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs +++ b/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs @@ -175,7 +175,7 @@ private static async Task> GetAllChangedDocumentsInDiag } } - return changedDocuments.ToImmutable(); + return changedDocuments.ToImmutableAndClear(); }, cancellationToken)); } @@ -188,7 +188,7 @@ private static async Task> GetAllChangedDocumentsInDiag foreach (var task in tasks) result.AddRange(await task.ConfigureAwait(false)); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } /// diff --git a/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResult.cs b/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResult.cs index 8599d0536cea8..949bea98a8ebb 100644 --- a/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResult.cs +++ b/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResult.cs @@ -235,7 +235,7 @@ public ImmutableArray GetAllDiagnostics() foreach (var data in _others) builder.AddRange(data); - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } public ImmutableArray GetDocumentDiagnostics(DocumentId documentId, AnalysisKind kind) diff --git a/src/Workspaces/Core/Portable/Diagnostics/Extensions.cs b/src/Workspaces/Core/Portable/Diagnostics/Extensions.cs index 942a846fa8671..6128338a0a43c 100644 --- a/src/Workspaces/Core/Portable/Diagnostics/Extensions.cs +++ b/src/Workspaces/Core/Portable/Diagnostics/Extensions.cs @@ -385,7 +385,7 @@ private static async Task> GetPragmaSuppressionAnalyz using var _ = ArrayBuilder.GetInstance(out var diagnosticsBuilder); await AnalyzeDocumentAsync(suppressionAnalyzer, document, documentAnalysisScope.Span, diagnosticsBuilder.Add).ConfigureAwait(false); - return diagnosticsBuilder.ToImmutable(); + return diagnosticsBuilder.ToImmutableAndClear(); } else { @@ -419,7 +419,7 @@ private static async Task> GetPragmaSuppressionAnalyz await AnalyzeDocumentAsync(suppressionAnalyzer, document, span: null, diagnosticsBuilder.Add).ConfigureAwait(false); } - return diagnosticsBuilder.ToImmutable(); + return diagnosticsBuilder.ToImmutableAndClear(); } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs index 37aba259d93a3..485422c8c7ff9 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs @@ -74,7 +74,7 @@ internal static async Task> FindAllDeclarationsWithNorma await SearchMetadataReferencesAsync().ConfigureAwait(false); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); async Task SearchCurrentProjectAsync() { diff --git a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs index 56120d6a720c9..647ac2afc594f 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs @@ -186,7 +186,7 @@ await AddCompilationSourceDeclarationsWithNormalQueryAsync( project, query, criteria, result, cancellationToken).ConfigureAwait(false); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } internal static async Task> FindSourceDeclarationsWithNormalQueryInCurrentProcessAsync( @@ -198,7 +198,7 @@ internal static async Task> FindSourceDeclarationsWithNo await AddCompilationSourceDeclarationsWithNormalQueryAsync( project, query, filter, result, cancellationToken).ConfigureAwait(false); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static async Task> FindSourceDeclarationsWithPatternInCurrentProcessAsync( diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder_Remote.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder_Remote.cs index d3b33e5d2d680..8c1d6eb9a7dce 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder_Remote.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder_Remote.cs @@ -91,6 +91,6 @@ private static async Task> RehydrateAsync(Solut builder.AddIfNotNull(namedType); } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferenceCache.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferenceCache.cs index 3c26c78c24971..a5247d4839031 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferenceCache.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferenceCache.cs @@ -175,7 +175,7 @@ static ImmutableArray FindMatchingIdentifierTokensFromText( index = nextIndex; } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } } @@ -206,6 +206,6 @@ private static ImmutableArray GetConstructorInitializerTokensWorker } } - return initializers.ToImmutable(); + return initializers.ToImmutableAndClear(); } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMethodOrPropertyOrEventSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMethodOrPropertyOrEventSymbolReferenceFinder.cs index 706ea16052e72..094c5db7de444 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMethodOrPropertyOrEventSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMethodOrPropertyOrEventSymbolReferenceFinder.cs @@ -41,7 +41,7 @@ protected static ImmutableArray GetReferencedAccessorSymbols( if (!semanticFacts.IsOnlyWrittenTo(semanticModel, node, cancellationToken)) result.AddIfNotNull(property.GetMethod); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } else { diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs index 7383f6e71739a..277b0857651f7 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs @@ -108,7 +108,7 @@ protected static async Task> FindDocumentsAsync( documents.Add(document); } - return documents.ToImmutable(); + return documents.ToImmutableAndClear(); } /// @@ -197,7 +197,7 @@ protected static async ValueTask> FindReferencesI } } - return locations.ToImmutable(); + return locations.ToImmutableAndClear(); } protected static FinderLocation CreateFinderLocation(FindReferencesDocumentState state, SyntaxToken token, CandidateReason reason, CancellationToken cancellationToken) @@ -300,7 +300,7 @@ private static async Task> FindReferencesThroughL } } - return allAliasReferences.ToImmutable(); + return allAliasReferences.ToImmutableAndClear(); } private static async Task> FindReferencesThroughLocalAliasSymbolsAsync( @@ -324,7 +324,7 @@ private static async Task> FindReferencesThroughL } } - return allAliasReferences.ToImmutable(); + return allAliasReferences.ToImmutableAndClear(); } protected static Task> FindDocumentsWithPredicateAsync( @@ -381,7 +381,7 @@ protected static async Task> FindReferencesInDocu collectMatchingReferences(node, state, locations); } - return locations.ToImmutable(); + return locations.ToImmutableAndClear(); } return []; diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder_GlobalSuppressions.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder_GlobalSuppressions.cs index 2202d3b2dc838..d3c9275698895 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder_GlobalSuppressions.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder_GlobalSuppressions.cs @@ -90,7 +90,7 @@ protected static async ValueTask> FindReferencesI } } - return locations.ToImmutable(); + return locations.ToImmutableAndClear(); // Local functions static bool IsCandidate( diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractTypeParameterSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractTypeParameterSymbolReferenceFinder.cs index caeeabeb0aa83..756ce8036d1fa 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractTypeParameterSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractTypeParameterSymbolReferenceFinder.cs @@ -59,7 +59,7 @@ ImmutableArray GetObjectCreationReferences(ImmutableArray> FindDocumentsWithImplicitObjectCreationExpressionAsync(Project project, IImmutableSet? documents, CancellationToken cancellationToken) @@ -140,7 +140,7 @@ await NamedTypeSymbolReferenceFinder.AddReferencesToTypeOrGlobalAliasToItAsync( result.AddRange(await FindReferencesInDocumentInsideGlobalSuppressionsAsync( methodSymbol, state, cancellationToken).ConfigureAwait(false)); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } /// diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ExplicitConversionSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ExplicitConversionSymbolReferenceFinder.cs index bbf655f55c57d..7059fefdf72ab 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ExplicitConversionSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ExplicitConversionSymbolReferenceFinder.cs @@ -56,7 +56,7 @@ protected sealed override async Task> DetermineDocument result.Add(document); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } protected sealed override ValueTask> FindReferencesInDocumentAsync( diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamedTypeSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamedTypeSymbolReferenceFinder.cs index 3dc76b005875f..74537c547319e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamedTypeSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamedTypeSymbolReferenceFinder.cs @@ -72,7 +72,7 @@ protected override async Task> DetermineDocumentsToSear result.AddRange(await FindDocumentsWithGlobalSuppressMessageAttributeAsync( project, documents, cancellationToken).ConfigureAwait(false)); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } /// @@ -134,7 +134,7 @@ await AddReferencesToTypeOrGlobalAliasToItAsync( initialReferences.AddRange(await FindReferencesInDocumentInsideGlobalSuppressionsAsync( namedType, state, cancellationToken).ConfigureAwait(false)); - return initialReferences.ToImmutable(); + return initialReferences.ToImmutableAndClear(); } internal static async ValueTask AddReferencesToTypeOrGlobalAliasToItAsync( diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamespaceSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamespaceSymbolReferenceFinder.cs index 1759897904691..dc0f2a36f79a3 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamespaceSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamespaceSymbolReferenceFinder.cs @@ -48,7 +48,7 @@ protected override async Task> DetermineDocumentsToSear var documentsWithGlobalAttributes = await FindDocumentsWithGlobalSuppressMessageAttributeAsync(project, documents, cancellationToken).ConfigureAwait(false); result.AddRange(documentsWithGlobalAttributes); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } protected override async ValueTask> FindReferencesInDocumentAsync( @@ -89,7 +89,7 @@ await AddNamedReferencesAsync( symbol, state, cancellationToken).ConfigureAwait(false)); } - return initialReferences.ToImmutable(); + return initialReferences.ToImmutableAndClear(); } /// diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs index ef3cde6005202..c15af3ce4355e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs @@ -63,7 +63,7 @@ protected override async ValueTask> DetermineCascadedSym CascadeBetweenPrimaryConstructorParameterAndProperties(parameter, symbols, cancellationToken); CascadeBetweenAnonymousDelegateParameters(parameter, symbols); - return symbols.ToImmutable(); + return symbols.ToImmutableAndClear(); } private static void CascadeBetweenAnonymousDelegateParameters(IParameterSymbol parameter, ArrayBuilder symbols) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertySymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertySymbolReferenceFinder.cs index 05bdb9bf8bfa1..6d2acf8ebeb77 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertySymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertySymbolReferenceFinder.cs @@ -211,7 +211,7 @@ private static async Task> FindIndexerReferencesA candidateReason))); } - return locations.ToImmutable(); + return locations.ToImmutableAndClear(); } private static ValueTask<(bool matched, CandidateReason reason, SyntaxNode indexerReference)> ComputeIndexerInformationAsync( diff --git a/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs b/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs index dfc42e1bf5983..4678c6b5e4c22 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs @@ -44,7 +44,7 @@ public ImmutableArray GetReferencedSymbols() foreach (var (symbol, locations) in _symbolToLocations) result.Add(new ReferencedSymbol(symbol, locations.ToImmutableArray())); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_CustomQueries.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_CustomQueries.cs index 862b5670e8d78..6cfe823cd8584 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_CustomQueries.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_CustomQueries.cs @@ -63,7 +63,7 @@ internal static async Task> FindSourceDeclarationsWithCu result.AddRange(symbols); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } } diff --git a/src/Workspaces/Core/Portable/ReassignedVariable/AbstractReassignedVariableService.cs b/src/Workspaces/Core/Portable/ReassignedVariable/AbstractReassignedVariableService.cs index 86bacec0c6c90..2393e5dff2ef2 100644 --- a/src/Workspaces/Core/Portable/ReassignedVariable/AbstractReassignedVariableService.cs +++ b/src/Workspaces/Core/Portable/ReassignedVariable/AbstractReassignedVariableService.cs @@ -56,7 +56,7 @@ public async Task> GetLocationsAsync( } result.RemoveDuplicates(); - return result.ToImmutable(); + return result.ToImmutableAndClear(); void Recurse(TextSpan span, SemanticModel semanticModel) { diff --git a/src/Workspaces/Core/Portable/Recommendations/AbstractRecommendationServiceRunner.cs b/src/Workspaces/Core/Portable/Recommendations/AbstractRecommendationServiceRunner.cs index a0e0860b111e9..b861712b760b8 100644 --- a/src/Workspaces/Core/Portable/Recommendations/AbstractRecommendationServiceRunner.cs +++ b/src/Workspaces/Core/Portable/Recommendations/AbstractRecommendationServiceRunner.cs @@ -170,7 +170,7 @@ private ImmutableArray SubstituteTypeParameters(ImmutableArray @@ -422,7 +422,7 @@ protected ImmutableArray LookupSymbolsInContainer( result.Add(member); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); static bool MatchesConstraints(ITypeSymbol originalContainerType, ImmutableArray constraintTypes) { diff --git a/src/Workspaces/Core/Portable/Remote/RemoteUtilities.cs b/src/Workspaces/Core/Portable/Remote/RemoteUtilities.cs index b6e0f76c3d498..31746fb54306c 100644 --- a/src/Workspaces/Core/Portable/Remote/RemoteUtilities.cs +++ b/src/Workspaces/Core/Portable/Remote/RemoteUtilities.cs @@ -39,7 +39,7 @@ internal static class RemoteUtilities } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } /// diff --git a/src/Workspaces/Core/Portable/Rename/SymbolicRenameLocations.cs b/src/Workspaces/Core/Portable/Rename/SymbolicRenameLocations.cs index 6bd6aa32dfe2b..9686f68c85235 100644 --- a/src/Workspaces/Core/Portable/Rename/SymbolicRenameLocations.cs +++ b/src/Workspaces/Core/Portable/Rename/SymbolicRenameLocations.cs @@ -123,7 +123,7 @@ private static async Task> GetOverloadsAsync( foreach (var overloadedSymbol in RenameUtilities.GetOverloadedSymbols(symbol)) overloadsResult.Add(await AddLocationsReferenceSymbolsAsync(overloadedSymbol, solution, cancellationToken).ConfigureAwait(false)); - return overloadsResult.ToImmutable(); + return overloadsResult.ToImmutableAndClear(); } private static async Task AddLocationsReferenceSymbolsAsync( diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/IAsyncEnumerableExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/IAsyncEnumerableExtensions.cs index aadde0b3d6c01..3a390a2769457 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/IAsyncEnumerableExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/IAsyncEnumerableExtensions.cs @@ -32,7 +32,7 @@ public static async Task> ToImmutableArrayAsync(this IAsync await foreach (var value in values.WithCancellation(cancellationToken).ConfigureAwait(false)) result.Add(value); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } /// diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs index 0fd2e6819501a..af8456252d02c 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs @@ -139,6 +139,6 @@ private static ImmutableArray FilterNonMatchingMethodNamesWork result.Add(reference); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } } diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.cs index 3dfc48994b3a6..6bef4e0d8324e 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.cs @@ -126,7 +126,7 @@ await constructedInterface.GetMembers(interfaceMember.Name).FirstOrDefaultAsync( } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } public static ISymbol? FindImplementations(this ITypeSymbol typeSymbol, ISymbol constructedInterfaceMember, SolutionServices services) diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs index b415cbcbe9421..ecce1282f978b 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs @@ -117,7 +117,7 @@ public static ImmutableArray CreateFieldsForParameters( } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } public static ImmutableArray CreatePropertiesForParameters( @@ -147,7 +147,7 @@ public static ImmutableArray CreatePropertiesForParameters( } } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } private static bool TryGetValue(IDictionary? dictionary, string key, [NotNullWhen(true)] out string? value) diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions_CreateEqualsMethod.cs b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions_CreateEqualsMethod.cs index bb3d0623e47c8..fce1e3dc980a1 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions_CreateEqualsMethod.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions_CreateEqualsMethod.cs @@ -115,7 +115,7 @@ private static ImmutableArray CreateEqualsMethodStatements( if (containingType.IsRefLikeType) { statements.Add(factory.ReturnStatement(factory.FalseLiteralExpression())); - return statements.ToImmutable(); + return statements.ToImmutableAndClear(); } // Come up with a good name for the local variable we're going to compare against. @@ -203,7 +203,7 @@ private static ImmutableArray CreateEqualsMethodStatements( statements.Add(factory.ReturnStatement( expressions.Aggregate(factory.LogicalAndExpression))); - return statements.ToImmutable(); + return statements.ToImmutableAndClear(); } private static void AddMemberChecks( diff --git a/src/Workspaces/Core/Portable/TaskList/TaskListItemDescriptor.cs b/src/Workspaces/Core/Portable/TaskList/TaskListItemDescriptor.cs index b2b45628fd3fb..82e8a8d302978 100644 --- a/src/Workspaces/Core/Portable/TaskList/TaskListItemDescriptor.cs +++ b/src/Workspaces/Core/Portable/TaskList/TaskListItemDescriptor.cs @@ -58,6 +58,6 @@ public static ImmutableArray Parse(ImmutableArray> MapSpansAsync( } } - return mappedFilePathAndTextChange.ToImmutable(); + return mappedFilePathAndTextChange.ToImmutableAndClear(); } } diff --git a/src/Workspaces/Remote/ServiceHub/Services/DiagnosticAnalyzer/DiagnosticComputer.cs b/src/Workspaces/Remote/ServiceHub/Services/DiagnosticAnalyzer/DiagnosticComputer.cs index cef12b7393db0..5d531395fb874 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/DiagnosticAnalyzer/DiagnosticComputer.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/DiagnosticAnalyzer/DiagnosticComputer.cs @@ -412,7 +412,7 @@ private async Task AnalyzeAsync( analyzerResults.Others))); } - return diagnostics.ToImmutable(); + return diagnostics.ToImmutableAndClear(); } private static ImmutableArray<(string analyzerId, AnalyzerTelemetryInfo)> GetTelemetryInfo( @@ -444,7 +444,7 @@ private async Task AnalyzeAsync( } } - return telemetryBuilder.ToImmutable(); + return telemetryBuilder.ToImmutableAndClear(); } private static string GetAnalyzerId(BidirectionalMap analyzerMap, DiagnosticAnalyzer analyzer) @@ -468,7 +468,7 @@ private static ImmutableArray GetAnalyzers(BidirectionalMap< } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } private async Task<(CompilationWithAnalyzers? compilationWithAnalyzers, BidirectionalMap analyzerToIdMap)> GetOrCreateCompilationWithAnalyzersAsync(CancellationToken cancellationToken) diff --git a/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs b/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs index 5d38cc493c2ab..323975f53f740 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs @@ -87,7 +87,7 @@ private static ImmutableArray Convert(ImmutableA foreach (var item in items) result.Add(SerializableSymbolAndProjectId.Dehydrate(solution, item, cancellationToken)); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } public ValueTask> FindAllDeclarationsWithNormalQueryAsync( diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SemanticFacts/CSharpSemanticFacts.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SemanticFacts/CSharpSemanticFacts.cs index 57362b6772187..8b2c346421d82 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SemanticFacts/CSharpSemanticFacts.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SemanticFacts/CSharpSemanticFacts.cs @@ -394,7 +394,7 @@ public ImmutableArray GetLocalFunctionSymbols(Compilation compila } } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } public bool IsInExpressionTree(SemanticModel semanticModel, SyntaxNode node, [NotNullWhen(true)] INamedTypeSymbol? expressionType, CancellationToken cancellationToken) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ICollectionExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ICollectionExtensions.cs index dc41d61adbb39..b0d57c834df5b 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ICollectionExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ICollectionExtensions.cs @@ -21,7 +21,7 @@ public static ImmutableArray WhereAsArray(this IEnumerable valu result.Add(value); } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } public static void RemoveRange(this ICollection collection, IEnumerable? items) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/TriviaEngine/AbstractTriviaFormatter.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/TriviaEngine/AbstractTriviaFormatter.cs index 928d8b88e75c4..d1723001a4b91 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/TriviaEngine/AbstractTriviaFormatter.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/TriviaEngine/AbstractTriviaFormatter.cs @@ -275,7 +275,7 @@ public ImmutableArray FormatToTextChanges(CancellationToken cancella if (Succeeded()) { - return changes.ToImmutable(); + return changes.ToImmutableAndClear(); } return []; diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SelectedMembers/AbstractSelectedMembers.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SelectedMembers/AbstractSelectedMembers.cs index 1ed4de851a4fb..840b4cb27697f 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SelectedMembers/AbstractSelectedMembers.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SelectedMembers/AbstractSelectedMembers.cs @@ -92,7 +92,7 @@ private ImmutableArray GetMembersInSpan( AddSelectedMemberDeclarations(member, membersToKeep); } - return selectedMembers.ToImmutable(); + return selectedMembers.ToImmutableAndClear(); void AddAllMembers(TMemberDeclarationSyntax member) { diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/SymbolKey/SymbolKey.BodyLevelSymbolKey.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/SymbolKey/SymbolKey.BodyLevelSymbolKey.cs index 4fd9c43b720b8..80aa37a6a9439 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/SymbolKey/SymbolKey.BodyLevelSymbolKey.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/SymbolKey/SymbolKey.BodyLevelSymbolKey.cs @@ -33,7 +33,7 @@ public static ImmutableArray GetBodyLevelSourceLocations(ISymbol symbo foreach (var syntaxRef in symbol.DeclaringSyntaxReferences) result.Add(syntaxRef.GetSyntax(cancellationToken).GetLocation()); - return result.ToImmutable(); + return result.ToImmutableAndClear(); } public static void Create(ISymbol symbol, SymbolKeyWriter visitor) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/SymbolKey/SymbolKey.ErrorTypeSymbolKey.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/SymbolKey/SymbolKey.ErrorTypeSymbolKey.cs index d37f8bd61d44f..319e43c9e32e0 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/SymbolKey/SymbolKey.ErrorTypeSymbolKey.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/SymbolKey/SymbolKey.ErrorTypeSymbolKey.cs @@ -59,7 +59,7 @@ private static ImmutableArray GetContainingNamespaceNamesInReverse(IName namespaceSymbol = namespaceSymbol.ContainingNamespace; } - return builder.ToImmutable(); + return builder.ToImmutableAndClear(); } protected sealed override SymbolKeyResolution Resolve( diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ParameterGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ParameterGenerator.cs index b239c9f765cbc..22cd0e3cec9a8 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ParameterGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ParameterGenerator.cs @@ -57,7 +57,7 @@ internal static ImmutableArray GetParameters( isFirstParam = false; } - return result.ToImmutable(); + return result.ToImmutableAndClear(); } internal static ParameterSyntax GetParameter(IParameterSymbol parameter, CSharpCodeGenerationContextInfo info, bool isExplicit, bool isFirstParam, bool seenOptional) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/TypeDeclarationSyntaxExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/TypeDeclarationSyntaxExtensions.cs index 419f016a12019..b15d8d2e2ff26 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/TypeDeclarationSyntaxExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/TypeDeclarationSyntaxExtensions.cs @@ -85,7 +85,7 @@ public static IEnumerable GetAllBaseListTypes(this TypeDeclarati baseListTypes.AddRange(baseTypes); } - return baseListTypes.ToImmutable(); + return baseListTypes.ToImmutableAndClear(); } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Editing/AddParameterEditor.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Editing/AddParameterEditor.cs index 7698602175d9b..f77701cbf1c55 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Editing/AddParameterEditor.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Editing/AddParameterEditor.cs @@ -145,7 +145,7 @@ private static ImmutableArray GetDesiredLeadingIndentation( triviaList.Add(lastWhitespace); } - return triviaList.ToImmutable(); + return triviaList.ToImmutableAndClear(); } private static bool ShouldPlaceParametersOnNewLine( From 352ca30aa6c9f7b14e63362256eed5fb7256c805 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 Apr 2024 21:27:43 -0700 Subject: [PATCH 02/37] revert --- .../UseCollectionExpressionForBuilderTests.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs b/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs index 40b463561fc63..bd0fbe4312df9 100644 --- a/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs +++ b/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs @@ -77,7 +77,7 @@ ImmutableArray M() { {{pattern}} builder.Add(0); - return builder.ToImmutableAndClear(); + return builder.ToImmutable(); } } """ + s_arrayBuilderApi, @@ -100,7 +100,7 @@ ImmutableArray M() { {{pattern}} builder.Add(0); - return builder.ToImmutableAndClear(); + return builder.ToImmutable(); } } """ + s_arrayBuilderApi, @@ -123,7 +123,7 @@ ImmutableArray M() { {{pattern}} [|builder.Add(|]0); - return builder.ToImmutableAndClear(); + return builder.ToImmutable(); } } """ + s_arrayBuilderApi, @@ -1256,7 +1256,7 @@ ImmutableArray M() // Leading [|builder.Add(|]0); // Trailing - return builder.ToImmutableAndClear(); + return builder.ToImmutable(); } } """ + s_arrayBuilderApi, @@ -1295,7 +1295,7 @@ ImmutableArray M() {{pattern}} [|builder.Add(|]1 + 2); - return builder.ToImmutableAndClear(); + return builder.ToImmutable(); } } """ + s_arrayBuilderApi, @@ -1336,7 +1336,7 @@ ImmutableArray M() 2); [|builder.Add(|]3 + 4); - return builder.ToImmutableAndClear(); + return builder.ToImmutable(); } } """ + s_arrayBuilderApi, @@ -1376,7 +1376,7 @@ ImmutableArray M() { using var _ = ArrayBuilder.GetInstance(10, 0, out var builder); builder.Add(0); - return builder.ToImmutableAndClear(); + return builder.ToImmutable(); } } """ + s_arrayBuilderApi, @@ -1540,7 +1540,7 @@ IEnumerable M() { {{pattern}} [|builder.Add(|]0); - return builder.ToImmutableAndClear(); + return builder.ToImmutable(); } } """ + s_arrayBuilderApi, @@ -1577,7 +1577,7 @@ IEnumerable M() { {{pattern}} builder.Add(0); - return builder.ToImmutableAndClear(); + return builder.ToImmutable(); } } """ + s_arrayBuilderApi, From 2dffdfb76bee111898a212e767338d9746b4ccc5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 Apr 2024 21:32:27 -0700 Subject: [PATCH 03/37] Use collection expressoins --- .../UseCollectionExpressionForBuilderTests.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs b/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs index bd0fbe4312df9..b4552f98d0246 100644 --- a/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs +++ b/src/Analyzers/CSharp/Tests/UseCollectionExpression/UseCollectionExpressionForBuilderTests.cs @@ -49,19 +49,19 @@ public void Clear() { } } """; - public static readonly IEnumerable FailureCreationPatterns = new[] - { - new[] {"var builder = ImmutableArray.CreateBuilder();" }, - new[] {"var builder = ArrayBuilder.GetInstance();" }, - new[] {"using var _ = ArrayBuilder.GetInstance(out var builder);" }, - }; - - public static readonly IEnumerable SuccessCreationPatterns = new[] - { - new[] {"[|var builder = ImmutableArray.[|CreateBuilder|]();|]" }, - new[] {"[|var builder = ArrayBuilder.[|GetInstance|]();|]" }, - new[] {"[|using var _ = ArrayBuilder.[|GetInstance|](out var builder);|]" }, - }; + public static readonly IEnumerable FailureCreationPatterns = + [ + ["var builder = ImmutableArray.CreateBuilder();"], + ["var builder = ArrayBuilder.GetInstance();"], + ["using var _ = ArrayBuilder.GetInstance(out var builder);"], + ]; + + public static readonly IEnumerable SuccessCreationPatterns = + [ + ["[|var builder = ImmutableArray.[|CreateBuilder|]();|]"], + ["[|var builder = ArrayBuilder.[|GetInstance|]();|]"], + ["[|using var _ = ArrayBuilder.[|GetInstance|](out var builder);|]"], + ]; [Theory, MemberData(nameof(FailureCreationPatterns))] public async Task TestNotInCSharp11(string pattern) From ac8070af72889d7d9a67808a8aa9817a0fa20057 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 09:44:41 -0700 Subject: [PATCH 04/37] Move to better type --- src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs b/src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs index 3905b4b0e91be..30d7508fba1c1 100644 --- a/src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs +++ b/src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs @@ -941,9 +941,9 @@ public ImmutableArray ParseStatements(string statements) return default; } - using var listDisposer = ArrayBuilder.GetInstance(out var list); var delimiter = IsVisualBasic ? "\r\n" : ";"; var parts = statements.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); + var list = new FixedSizeArrayBuilder(parts.Length); foreach (var p in parts) { if (IsVisualBasic) @@ -956,7 +956,7 @@ public ImmutableArray ParseStatements(string statements) } } - return list.ToImmutableAndClear(); + return list.MoveToImmutable(); } public void Dispose() From c42c71373653db87901c4ac41c37cf9decb07a1f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 09:45:28 -0700 Subject: [PATCH 05/37] Move to better type --- ...ConstructorParametersFromMembersCodeRefactoringProvider.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.cs b/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.cs index e2300a8a4fbee..583adc338a0e3 100644 --- a/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.cs @@ -181,7 +181,7 @@ public async Task> ComputeIntentAsync( return []; } - using var _ = ArrayBuilder.GetInstance(out var results); + var results = new FixedSizeArrayBuilder(actions.Length); foreach (var action in actions) { // Intents currently have no way to report progress. @@ -192,6 +192,6 @@ public async Task> ComputeIntentAsync( results.Add(intent); } - return results.ToImmutableAndClear(); + return results.MoveToImmutable(); } } From f40ad02d6f596448704983ca994db27c8ea5347e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 09:46:40 -0700 Subject: [PATCH 06/37] Move to better type --- .../Portable/AddImport/AbstractAddImportFeatureService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/AddImport/AbstractAddImportFeatureService.cs b/src/Features/Core/Portable/AddImport/AbstractAddImportFeatureService.cs index d25940ab6bd71..ca3f102bcfc9a 100644 --- a/src/Features/Core/Portable/AddImport/AbstractAddImportFeatureService.cs +++ b/src/Features/Core/Portable/AddImport/AbstractAddImportFeatureService.cs @@ -484,7 +484,7 @@ private static bool NotNull(SymbolReference reference) // We might have multiple different diagnostics covering the same span. Have to // process them all as we might produce different fixes for each diagnostic. - using var _ = ArrayBuilder<(Diagnostic, ImmutableArray)>.GetInstance(out var result); + var result = new FixedSizeArrayBuilder<(Diagnostic, ImmutableArray)>(diagnostics.Length); foreach (var diagnostic in diagnostics) { @@ -496,7 +496,7 @@ private static bool NotNull(SymbolReference reference) result.Add((diagnostic, fixes)); } - return result.ToImmutableAndClear(); + return result.MoveToImmutable(); } public async Task> GetUniqueFixesAsync( From bbeb8e340c45494a64e3e7e4610dc7384f6b6e2f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 09:47:31 -0700 Subject: [PATCH 07/37] Move to better type --- .../ChangeSignature/AbstractChangeSignatureService.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs index 5984100dae2f1..852b345190385 100644 --- a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs +++ b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs @@ -737,16 +737,17 @@ protected static int GetParameterIndex(SeparatedSyntaxList paramet protected ImmutableArray GetSeparators(SeparatedSyntaxList arguments, int numSeparatorsToSkip) where T : SyntaxNode { - var separators = ImmutableArray.CreateBuilder(); + var count = arguments.SeparatorCount - numSeparatorsToSkip; + var separators = new FixedSizeArrayBuilder(count); - for (var i = 0; i < arguments.SeparatorCount - numSeparatorsToSkip; i++) + for (var i = 0; i < count; i++) { separators.Add(i < arguments.SeparatorCount ? arguments.GetSeparator(i) : CommaTokenWithElasticSpace()); } - return separators.ToImmutableAndClear(); + return separators.MoveToImmutable(); } protected virtual async Task> AddNewArgumentsToListAsync( From d5758710f1530e095ccd3583ad856dd06da67dc7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 09:48:26 -0700 Subject: [PATCH 08/37] Move to better type --- .../Configuration/ConfigurationUpdater.cs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs b/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs index b36c3000c7745..a9d1b96663ade 100644 --- a/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs +++ b/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs @@ -350,22 +350,15 @@ private async Task ConfigureAsync(CancellationToken cancellationToken) var codeStyleOptions = GetCodeStyleOptionsForDiagnostic(diagnostic, project); if (!codeStyleOptions.IsEmpty) { - var builder = ArrayBuilder<(string optionName, string currentOptionValue, bool isPerLanguage)>.GetInstance(); + var builder = new FixedSizeArrayBuilder<(string optionName, string currentOptionValue, bool isPerLanguage)>(codeStyleOptions.Length); - try + foreach (var option in codeStyleOptions) { - foreach (var option in codeStyleOptions) - { - var optionValue = option.Definition.Serializer.Serialize(option.DefaultValue); - builder.Add((option.Definition.ConfigName, optionValue, option.IsPerLanguage)); - } - - return builder.ToImmutableAndClear(); - } - finally - { - builder.Free(); + var optionValue = option.Definition.Serializer.Serialize(option.DefaultValue); + builder.Add((option.Definition.ConfigName, optionValue, option.IsPerLanguage)); } + + return builder.MoveToImmutable(); } return []; From 4bd15f89e17360691fa8581273e9e5889296328f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 09:49:22 -0700 Subject: [PATCH 09/37] Move to better type --- .../ExtensionMethodImportCompletionHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs index 0f58f0b5e126c..d63813efdca06 100644 --- a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs +++ b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs @@ -188,7 +188,7 @@ private static ImmutableArray ConvertSymbolsTo } // Then convert symbols into completion items - using var _3 = ArrayBuilder.GetInstance(out var itemsBuilder); + var itemsBuilder = new FixedSizeArrayBuilder(overloadMap.Count); foreach (var ((containingNamespace, _, _), (bestSymbol, overloadCount, includeInTargetTypedCompletion)) in overloadMap) { @@ -205,7 +205,7 @@ private static ImmutableArray ConvertSymbolsTo itemsBuilder.Add(item); } - return itemsBuilder.ToImmutableAndClear(); + return itemsBuilder.MoveToImmutable(); } private static bool ShouldIncludeInTargetTypedCompletion( From a1d8a1e4dbd1d9d65d4d32fc365f9a4a496b0e23 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 09:50:07 -0700 Subject: [PATCH 10/37] Move to better type --- .../Scripting/AbstractLoadDirectiveCompletionProvider.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractLoadDirectiveCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractLoadDirectiveCompletionProvider.cs index 1d5bdf89688ce..aa29c2cce9dcd 100644 --- a/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractLoadDirectiveCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/Scripting/AbstractLoadDirectiveCompletionProvider.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Completion; using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.Shared.Collections; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Completion.Providers; @@ -22,7 +23,7 @@ internal abstract class AbstractLoadDirectiveCompletionProvider : AbstractDirect private static ImmutableArray GetCommitCharacters() { - using var builderDisposer = ArrayBuilder.GetInstance(out var builder); + using var builder = TemporaryArray.Empty; builder.Add('"'); if (PathUtilities.IsUnixLikePlatform) { From 86a73a4097893e4798569435e48695ba745b13f3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 09:50:55 -0700 Subject: [PATCH 11/37] Move to better type --- .../Remote/RemoteEditAndContinueServiceProxy.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/EditAndContinue/Remote/RemoteEditAndContinueServiceProxy.cs b/src/Features/Core/Portable/EditAndContinue/Remote/RemoteEditAndContinueServiceProxy.cs index aa5cd4388b2aa..dcb61c00ee82b 100644 --- a/src/Features/Core/Portable/EditAndContinue/Remote/RemoteEditAndContinueServiceProxy.cs +++ b/src/Features/Core/Portable/EditAndContinue/Remote/RemoteEditAndContinueServiceProxy.cs @@ -193,7 +193,7 @@ public async ValueTask> GetDocumentDiagnosticsAsync(D var project = document.Project; - using var _ = ArrayBuilder.GetInstance(out var result); + var result = new FixedSizeArrayBuilder(diagnosticData.Value.Length); foreach (var data in diagnosticData.Value) { Debug.Assert(data.DataLocation != null); @@ -215,7 +215,7 @@ public async ValueTask> GetDocumentDiagnosticsAsync(D result.Add(diagnostic); } - return result.ToImmutableAndClear(); + return result.MoveToImmutable(); } private static Diagnostic RemapLocation(Document designTimeDocument, DiagnosticData data) From f2e6fadfd2d7fc0595fb0dc9123ac83d99a97f9d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 09:59:15 -0700 Subject: [PATCH 12/37] Move to better type --- ...actGenerateConstructorFromMembersCodeRefactoringProvider.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs b/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs index 9a48f82069dc3..6335e33decd19 100644 --- a/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs @@ -18,6 +18,7 @@ using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PickMembers; using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.Shared.Collections; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.Simplification; @@ -274,7 +275,7 @@ public async Task> GenerateConstructorFromMembersAsyn private ImmutableArray GetCodeActions(Document document, State state, bool addNullChecks, CleanCodeGenerationOptionsProvider fallbackOptions) { - using var _ = ArrayBuilder.GetInstance(out var result); + var result = TemporaryArray.Empty; result.Add(new FieldDelegatingCodeAction(this, document, state, addNullChecks, fallbackOptions)); if (state.DelegatedConstructor != null) From 89acd32ea3303b7390a8b2604c2e55d4b336f9ba Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:00:02 -0700 Subject: [PATCH 13/37] Move to better type --- ...actGenerateConstructorFromMembersCodeRefactoringProvider.cs | 2 +- .../GenerateConstructor/AbstractGenerateConstructorService.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs b/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs index 6335e33decd19..842c90a3eb6e8 100644 --- a/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.cs @@ -275,7 +275,7 @@ public async Task> GenerateConstructorFromMembersAsyn private ImmutableArray GetCodeActions(Document document, State state, bool addNullChecks, CleanCodeGenerationOptionsProvider fallbackOptions) { - var result = TemporaryArray.Empty; + using var result = TemporaryArray.Empty; result.Add(new FieldDelegatingCodeAction(this, document, state, addNullChecks, fallbackOptions)); if (state.DelegatedConstructor != null) diff --git a/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.cs b/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.cs index 27c3d1936f32a..eef382a09391a 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.LanguageService; using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.Shared.Collections; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.Utilities; @@ -87,7 +88,7 @@ public async Task> GenerateConstructorAsync(Document { Contract.ThrowIfNull(state.TypeToGenerateIn); - using var _ = ArrayBuilder.GetInstance(out var result); + using var result = TemporaryArray.Empty; // If we have any fields we'd like to generate, offer a code action to do that. if (state.ParameterToNewFieldMap.Count > 0) From 288e932bdb155fe28203b45ccfacdae1baaa2d0c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:01:03 -0700 Subject: [PATCH 14/37] Move to better type --- ...bstractGenerateParameterizedMemberService.SignatureInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs b/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs index 425164cfe28bc..4f586c5d254f0 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.SignatureInfo.cs @@ -204,7 +204,7 @@ private async ValueTask> DetermineParametersAsy var optionality = DetermineParameterOptionality(cancellationToken); var names = DetermineParameterNames(cancellationToken); - using var _ = ArrayBuilder.GetInstance(out var result); + var result = new FixedSizeArrayBuilder(modifiers.Length); for (var i = 0; i < modifiers.Length; i++) { result.Add(CodeGenerationSymbolFactory.CreateParameterSymbol( @@ -216,7 +216,7 @@ private async ValueTask> DetermineParametersAsy name: names[i].BestNameForParameter)); } - return result.ToImmutableAndClear(); + return result.MoveToImmutable(); } private Accessibility DetermineAccessibility(bool isAbstract) From bbcac94e166e0cd87d36b41a387278e7d00d1728 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:02:23 -0700 Subject: [PATCH 15/37] Move to better type --- .../Portable/PdbSourceDocument/DocumentDebugInfoReader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/PdbSourceDocument/DocumentDebugInfoReader.cs b/src/Features/Core/Portable/PdbSourceDocument/DocumentDebugInfoReader.cs index b01e635db8630..154bd02308ad4 100644 --- a/src/Features/Core/Portable/PdbSourceDocument/DocumentDebugInfoReader.cs +++ b/src/Features/Core/Portable/PdbSourceDocument/DocumentDebugInfoReader.cs @@ -37,7 +37,7 @@ public ImmutableArray FindSourceDocuments(EntityHandle entityHan { var documentHandles = SymbolSourceDocumentFinder.FindDocumentHandles(entityHandle, _dllReader, _pdbReader); - using var _ = ArrayBuilder.GetInstance(out var sourceDocuments); + var sourceDocuments = new FixedSizeArrayBuilder(documentHandles.Count); foreach (var handle in documentHandles) { @@ -54,7 +54,7 @@ public ImmutableArray FindSourceDocuments(EntityHandle entityHan sourceDocuments.Add(new SourceDocument(filePath, hashAlgorithm, checksum, embeddedTextBytes, sourceLinkUrl)); } - return sourceDocuments.ToImmutableAndClear(); + return sourceDocuments.MoveToImmutable(); } private string? TryGetSourceLinkUrl(DocumentHandle handle) From df879550ed5a94652d72ec9ef840b78a41afc5ff Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:03:21 -0700 Subject: [PATCH 16/37] Move to better type --- .../BinaryExpression/BinaryExpressionCodeActionComputer.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Features/Core/Portable/Wrapping/BinaryExpression/BinaryExpressionCodeActionComputer.cs b/src/Features/Core/Portable/Wrapping/BinaryExpression/BinaryExpressionCodeActionComputer.cs index 5dcef3f9ee1ca..34d657cdc1884 100644 --- a/src/Features/Core/Portable/Wrapping/BinaryExpression/BinaryExpressionCodeActionComputer.cs +++ b/src/Features/Core/Portable/Wrapping/BinaryExpression/BinaryExpressionCodeActionComputer.cs @@ -120,16 +120,17 @@ private ImmutableArray GetWrapEdits(bool align) private ImmutableArray GetUnwrapEdits() { - using var _ = ArrayBuilder.GetInstance(out var result); + var count = _exprsAndOperators.Length - 1; + var result = new FixedSizeArrayBuilder(count); - for (var i = 0; i < _exprsAndOperators.Length - 1; i++) + for (var i = 0; i < count; i++) { result.Add(Edit.UpdateBetween( _exprsAndOperators[i], SingleWhitespaceTrivia, NoTrivia, _exprsAndOperators[i + 1])); } - return result.ToImmutableAndClear(); + return result.MoveToImmutable(); } } } From bac93e11a727bd2bdbd9abcb5dc978a0cb6902ee Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:04:00 -0700 Subject: [PATCH 17/37] Move to better type --- .../AbstractCurlyBraceOrBracketCompletionService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs b/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs index fdc91b04c1a0c..f01fef914a806 100644 --- a/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs +++ b/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs @@ -183,7 +183,7 @@ static ImmutableArray GetMergedChanges(TextChange? newLineEdit, Immu [newLineEdit.Value.ToTextChangeRange()], formattingChanges.SelectAsArray(f => f.ToTextChangeRange())); - using var _ = ArrayBuilder.GetInstance(out var mergedChanges); + var mergedChanges = new FixedSizeArrayBuilder(newRanges.Length); var amountToShift = 0; foreach (var newRange in newRanges) { @@ -200,7 +200,7 @@ static ImmutableArray GetMergedChanges(TextChange? newLineEdit, Immu mergedChanges.Add(new TextChange(newTextChangeSpan, newTextChangeText)); } - return mergedChanges.ToImmutableAndClear(); + return mergedChanges.MoveToImmutable(); } } From c3d51d7f33218e133ab4080963be31aa74653493 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:04:38 -0700 Subject: [PATCH 18/37] Move to better type --- .../ConvertProgramTransform_TopLevelStatements.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_TopLevelStatements.cs b/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_TopLevelStatements.cs index 4ac7c6f4365ef..7cbadc2a91c8a 100644 --- a/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_TopLevelStatements.cs +++ b/src/Features/CSharp/Portable/ConvertProgram/ConvertProgramTransform_TopLevelStatements.cs @@ -227,11 +227,11 @@ private static ImmutableArray GetGlobalStatements( } } - using var _1 = ArrayBuilder.GetInstance(out var globalStatements); + var globalStatements = new FixedSizeArrayBuilder(statements.Count); foreach (var statement in statements) globalStatements.Add(GlobalStatement(statement).WithAdditionalAnnotations(Formatter.Annotation)); - return globalStatements.ToImmutableAndClear(); + return globalStatements.MoveToImmutable(); } private static VariableDeclarationSyntax ConvertDeclaration( From 437f2479646bc177d72b1d27c45e799b9d6f2426 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:06:08 -0700 Subject: [PATCH 19/37] Move to better type --- .../CSharpGenerateParameterizedMemberService.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs b/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs index e8a11332cf44e..a2afc24618db4 100644 --- a/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs +++ b/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs @@ -84,9 +84,10 @@ protected override ImmutableArray GenerateTypeParameters(C } else { - using var _ = ArrayBuilder.GetInstance(out var list); + var list = new FixedSizeArrayBuilder(genericName.TypeArgumentList.Arguments.Count); - var usedIdentifiers = new HashSet { "T" }; + using var _ = PooledHashSet.GetInstance(out var usedIdentifiers); + usedIdentifiers.Add("T"); foreach (var type in genericName.TypeArgumentList.Arguments) { var typeParameter = GetUniqueTypeParameter( @@ -99,7 +100,7 @@ protected override ImmutableArray GenerateTypeParameters(C list.Add(typeParameter); } - return list.ToImmutableAndClear(); + return list.MoveToImmutable(); } } From 035fd297979846f29f5f3f3dfa5f594ed17456c1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:07:11 -0700 Subject: [PATCH 20/37] Move to better type --- .../CSharpGenerateParameterizedMemberService.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs b/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs index a2afc24618db4..6bab88b6f96d8 100644 --- a/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs +++ b/src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs @@ -148,18 +148,18 @@ protected override bool IsImplicitReferenceConversion(Compilation compilation, I protected override ImmutableArray DetermineTypeArguments(CancellationToken cancellationToken) { - using var _ = ArrayBuilder.GetInstance(out var result); - if (State.SimpleNameOpt is GenericNameSyntax genericName) + if (State.SimpleNameOpt is not GenericNameSyntax genericName) + return []; + + var result = new FixedSizeArrayBuilder(genericName.TypeArgumentList.Arguments.Count); + foreach (var typeArgument in genericName.TypeArgumentList.Arguments) { - foreach (var typeArgument in genericName.TypeArgumentList.Arguments) - { - var typeInfo = Document.SemanticModel.GetTypeInfo(typeArgument, cancellationToken); - result.Add(typeInfo.Type); - } + var typeInfo = Document.SemanticModel.GetTypeInfo(typeArgument, cancellationToken); + result.Add(typeInfo.Type); } - return result.ToImmutableAndClear(); + return result.MoveToImmutable(); } } } From 5ea35046c246cd907066f1947da0f2c4491e6716 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:07:52 -0700 Subject: [PATCH 21/37] Move to better type --- .../CSharpReplacePropertyWithMethodsService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs b/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs index a7c7102ca66ba..e74409937af67 100644 --- a/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs +++ b/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs @@ -16,8 +16,8 @@ using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.ReplacePropertyWithMethods; +using Microsoft.CodeAnalysis.Shared.Collections; using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; @@ -72,7 +72,7 @@ private static ImmutableArray ConvertPropertyToMembers( string desiredSetMethodName, CancellationToken cancellationToken) { - using var _ = ArrayBuilder.GetInstance(out var result); + using var result = TemporaryArray.Empty; if (propertyBackingField != null) { From a360d67f9e23f8239d6bfe75d3351ff1956b0006 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:08:25 -0700 Subject: [PATCH 22/37] Move to better type --- .../UseExpressionBodyForLambdaCodeRefactoringProvider.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeRefactoringProvider.cs index 6c5a7895fd584..371201965e981 100644 --- a/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeRefactoringProvider.cs @@ -15,6 +15,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.Shared.Collections; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; @@ -168,13 +169,11 @@ private static async Task> ComputeRefactoringsAsync( { var lambdaNode = await document.TryGetRelevantNodeAsync(span, cancellationToken).ConfigureAwait(false); if (lambdaNode == null) - { return []; - } var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); - using var resultDisposer = ArrayBuilder.GetInstance(out var result); + using var result = TemporaryArray.Empty; if (UseExpressionBodyForLambdaHelpers.CanOfferUseExpressionBody(option, lambdaNode, root.GetLanguageVersion(), cancellationToken)) { var title = UseExpressionBodyForLambdaHelpers.UseExpressionBodyTitle.ToString(); From 3c8bcaa37b0e161e1db5ce98aff9dad781b20e89 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:09:07 -0700 Subject: [PATCH 23/37] Move to better type --- .../Protocol/Features/CodeFixes/CodeFixService.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs b/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs index a50adc0b63f24..52f031d5db3a5 100644 --- a/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs +++ b/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs @@ -931,14 +931,12 @@ private static ImmutableDictionary GetConfigurationFixProviders(ImmutableArray> languageKindAndFixers) { - using var builderDisposer = ArrayBuilder.GetInstance(out var builder); var orderedLanguageKindAndFixers = ExtensionOrderer.Order(languageKindAndFixers); + var builder = new FixedSizeArrayBuilder(orderedLanguageKindAndFixers.Count); foreach (var languageKindAndFixersValue in orderedLanguageKindAndFixers) - { builder.Add(languageKindAndFixersValue.Value); - } - return builder.ToImmutableAndClear(); + return builder.MoveToImmutable(); } } From c72a167007bc7bfad4593e0c94d820f096c846a3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:11:54 -0700 Subject: [PATCH 24/37] Move to better type --- .../LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs b/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs index ba01e7d11e979..289f609e7df67 100644 --- a/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs +++ b/src/Features/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs @@ -274,7 +274,7 @@ public void UpdateTrackedDocument(Uri uri, SourceText newSourceText) .Concat(registeredWorkspaces.Where(workspace => workspace.Kind == WorkspaceKind.MiscellaneousFiles)) .ToImmutableArray(); - using var _ = ArrayBuilder<(Workspace, Solution, bool)>.GetInstance(out var solutions); + var solutions = new FixedSizeArrayBuilder<(Workspace, Solution, bool)>(registeredWorkspaces.Length); foreach (var workspace in registeredWorkspaces) { // Retrieve the workspace's current view of the world at the time the request comes in. If this is changing @@ -285,7 +285,7 @@ public void UpdateTrackedDocument(Uri uri, SourceText newSourceText) solutions.Add((workspace, lspSolution, isForked)); } - return solutions.ToImmutableAndClear(); + return solutions.MoveToImmutable(); async Task<(Solution Solution, bool IsForked)> GetLspSolutionForWorkspaceAsync(Workspace workspace, CancellationToken cancellationToken) { From e9c8ff5f236117ec7822a6fe728b13c1ba006091 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:13:23 -0700 Subject: [PATCH 25/37] Move to better type --- .../CSharp/Test/DocumentOutline/DocumentOutlineTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio/CSharp/Test/DocumentOutline/DocumentOutlineTests.cs b/src/VisualStudio/CSharp/Test/DocumentOutline/DocumentOutlineTests.cs index 4c215eafae28e..38cfd356f0961 100644 --- a/src/VisualStudio/CSharp/Test/DocumentOutline/DocumentOutlineTests.cs +++ b/src/VisualStudio/CSharp/Test/DocumentOutline/DocumentOutlineTests.cs @@ -80,15 +80,15 @@ static ImmutableArray SortDocumentSymbols( ImmutableArray documentSymbolData, SortOption sortOption) { - using var _ = ArrayBuilder.GetInstance(out var sortedDocumentSymbols); documentSymbolData = Sort(documentSymbolData, sortOption); + var sortedDocumentSymbols = new FixedSizeArrayBuilder(documentSymbolData.Length); foreach (var documentSymbol in documentSymbolData) { var sortedChildren = SortDocumentSymbols(documentSymbol.Children, sortOption); sortedDocumentSymbols.Add(ReplaceChildren(documentSymbol, sortedChildren)); } - return sortedDocumentSymbols.ToImmutableAndClear(); + return sortedDocumentSymbols.MoveToImmutable(); } static ImmutableArray Sort(ImmutableArray items, SortOption sortOption) From 3e7c13e30cf3bfd4f3e7d4cbdbd47387bbc31e75 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:13:56 -0700 Subject: [PATCH 26/37] Move to better type --- .../Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs b/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs index 4b99843f78856..19c234bb6c285 100644 --- a/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs +++ b/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs @@ -435,7 +435,7 @@ private IEnumerable ResolveAnalyzerReferences(CommandLineArgu private ImmutableArray CreateDocumentInfos(IReadOnlyList documentFileInfos, ProjectId projectId, Encoding? encoding) { - var results = ImmutableArray.CreateBuilder(); + var results = new FixedSizeArrayBuilder(documentFileInfos.Count); foreach (var info in documentFileInfos) { @@ -453,7 +453,7 @@ private ImmutableArray CreateDocumentInfos(IReadOnlyList Date: Sat, 13 Apr 2024 10:14:45 -0700 Subject: [PATCH 27/37] Move to better type --- .../Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs index 5dfb1ce15e263..4fa6436771ed5 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs @@ -68,11 +68,11 @@ public async Task> GetProjectFileInfosAsync(Canc // each value, and build the project. var targetFrameworks = targetFrameworksValue.Split(';'); - var results = ImmutableArray.CreateBuilder(targetFrameworks.Length); if (!_loadedProject.GlobalProperties.TryGetValue(PropertyNames.TargetFramework, out var initialGlobalTargetFrameworkValue)) initialGlobalTargetFrameworkValue = null; + var results = new FixedSizeArrayBuilder(targetFrameworks.Length); foreach (var targetFramework in targetFrameworks) { _loadedProject.SetGlobalProperty(PropertyNames.TargetFramework, targetFramework); @@ -94,7 +94,7 @@ public async Task> GetProjectFileInfosAsync(Canc _loadedProject.ReevaluateIfNecessary(); - return results.ToImmutableAndClear(); + return results.MoveToImmutable(); } else { From e2f73172ee5a062d97fccd80abb46731249d6ee8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:15:18 -0700 Subject: [PATCH 28/37] Move to better type --- .../Core/Portable/FindSymbols/StreamingProgressCollector.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs b/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs index 4678c6b5e4c22..9c62cd2c19139 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs @@ -40,11 +40,11 @@ public ImmutableArray GetReferencedSymbols() { lock (_gate) { - using var _ = ArrayBuilder.GetInstance(out var result); + var result = new FixedSizeArrayBuilder(_symbolToLocations.Count); foreach (var (symbol, locations) in _symbolToLocations) result.Add(new ReferencedSymbol(symbol, locations.ToImmutableArray())); - return result.ToImmutableAndClear(); + return result.MoveToImmutable(); } } From 74e09007f719f7683c12c38164aaa33377acf4ee Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:17:13 -0700 Subject: [PATCH 29/37] Move to better type --- .../SyntaxGeneratorExtensions_CreateEqualsMethod.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions_CreateEqualsMethod.cs b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions_CreateEqualsMethod.cs index fce1e3dc980a1..6ebbbe5063f0c 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions_CreateEqualsMethod.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions_CreateEqualsMethod.cs @@ -107,17 +107,17 @@ private static ImmutableArray CreateEqualsMethodStatements( ImmutableArray members, string localNameOpt) { - using var _1 = ArrayBuilder.GetInstance(out var statements); // A ref like type can not be boxed. Because of this an overloaded Equals taking object in the general case // can never be true, because an equivalent object can never be boxed into the object itself. Therefore only // need to return false. if (containingType.IsRefLikeType) { - statements.Add(factory.ReturnStatement(factory.FalseLiteralExpression())); - return statements.ToImmutableAndClear(); + return [factory.ReturnStatement(factory.FalseLiteralExpression())]; } + using var statements = TemporaryArray.Empty; + // Come up with a good name for the local variable we're going to compare against. // For example, if the class name is "CustomerOrder" then we'll generate: // From d5a4dd29412dc3b532ea369e18b1a375de22c195 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:17:48 -0700 Subject: [PATCH 30/37] Move to better type --- .../Services/DiagnosticAnalyzer/DiagnosticComputer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/Remote/ServiceHub/Services/DiagnosticAnalyzer/DiagnosticComputer.cs b/src/Workspaces/Remote/ServiceHub/Services/DiagnosticAnalyzer/DiagnosticComputer.cs index 5d531395fb874..d73d1bc31c709 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/DiagnosticAnalyzer/DiagnosticComputer.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/DiagnosticAnalyzer/DiagnosticComputer.cs @@ -398,7 +398,7 @@ private async Task AnalyzeAsync( ImmutableDictionary builderMap, BidirectionalMap analyzerToIdMap) { - using var _ = ArrayBuilder<(string analyzerId, SerializableDiagnosticMap diagnosticMap)>.GetInstance(out var diagnostics); + var diagnostics = new FixedSizeArrayBuilder<(string analyzerId, SerializableDiagnosticMap diagnosticMap)>(builderMap.Count); foreach (var (analyzer, analyzerResults) in builderMap) { @@ -412,7 +412,7 @@ private async Task AnalyzeAsync( analyzerResults.Others))); } - return diagnostics.ToImmutableAndClear(); + return diagnostics.MoveToImmutable(); } private static ImmutableArray<(string analyzerId, AnalyzerTelemetryInfo)> GetTelemetryInfo( From 56419f29ed6a4350303983ec153e424cc705c165 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:18:26 -0700 Subject: [PATCH 31/37] Move to better type --- .../Services/SymbolFinder/RemoteSymbolFinderService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs b/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs index 323975f53f740..43be04c3b336c 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs @@ -82,12 +82,12 @@ await SymbolFinder.FindLiteralReferencesInCurrentProcessAsync( private static ImmutableArray Convert(ImmutableArray items, Solution solution, CancellationToken cancellationToken) { - using var _ = ArrayBuilder.GetInstance(out var result); + var result = new FixedSizeArrayBuilder(items.Length); foreach (var item in items) result.Add(SerializableSymbolAndProjectId.Dehydrate(solution, item, cancellationToken)); - return result.ToImmutableAndClear(); + return result.MoveToImmutable(); } public ValueTask> FindAllDeclarationsWithNormalQueryAsync( From e28c5bb60e2b0161f5a995cc3e86e86231c9db21 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:19:02 -0700 Subject: [PATCH 32/37] Move to better type --- .../Workspace/CSharp/CodeGeneration/ParameterGenerator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ParameterGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ParameterGenerator.cs index 22cd0e3cec9a8..dde1cec02d278 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ParameterGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ParameterGenerator.cs @@ -45,10 +45,10 @@ internal static ImmutableArray GetParameters( bool isExplicit, CSharpCodeGenerationContextInfo info) { - using var _ = ArrayBuilder.GetInstance(out var result); var seenOptional = false; var isFirstParam = true; + var result = new FixedSizeArrayBuilder(parameterDefinitions.Length); foreach (var p in parameterDefinitions) { var parameter = GetParameter(p, info, isExplicit, isFirstParam, seenOptional); @@ -57,7 +57,7 @@ internal static ImmutableArray GetParameters( isFirstParam = false; } - return result.ToImmutableAndClear(); + return result.MoveToImmutable(); } internal static ParameterSyntax GetParameter(IParameterSymbol parameter, CSharpCodeGenerationContextInfo info, bool isExplicit, bool isFirstParam, bool seenOptional) From 6241a0c2047a71533e32c034752b3433616b16bc Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 10:20:06 -0700 Subject: [PATCH 33/37] Move to better type --- .../AbstractAddFileBannerCodeRefactoringProvider.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Features/Core/Portable/AddFileBanner/AbstractAddFileBannerCodeRefactoringProvider.cs b/src/Features/Core/Portable/AddFileBanner/AbstractAddFileBannerCodeRefactoringProvider.cs index 647c0910067a8..1abbea0e73f17 100644 --- a/src/Features/Core/Portable/AddFileBanner/AbstractAddFileBannerCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/AddFileBanner/AbstractAddFileBannerCodeRefactoringProvider.cs @@ -148,18 +148,16 @@ private ImmutableArray UpdateEmbeddedFileNames( var sourceName = IOUtilities.PerformIO(() => Path.GetFileName(sourceDocument.FilePath)); var destinationName = IOUtilities.PerformIO(() => Path.GetFileName(destinationDocument.FilePath)); if (string.IsNullOrEmpty(sourceName) || string.IsNullOrEmpty(destinationName)) - { return banner; - } - using var _ = ArrayBuilder.GetInstance(out var result); + var result = new FixedSizeArrayBuilder(banner.Length); foreach (var trivia in banner) { var updated = CreateTrivia(trivia, trivia.ToFullString().Replace(sourceName, destinationName)); result.Add(updated); } - return result.ToImmutableAndClear(); + return result.MoveToImmutable(); } private async Task> TryGetBannerAsync( From 5cf909c7b1627522a4ccc2aae8e1094a2284f82f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 11:22:35 -0700 Subject: [PATCH 34/37] Mix --- .../Portable/ChangeSignature/AbstractChangeSignatureService.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs index 852b345190385..e6f5785a4a2f5 100644 --- a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs +++ b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs @@ -738,6 +738,9 @@ protected static int GetParameterIndex(SeparatedSyntaxList paramet protected ImmutableArray GetSeparators(SeparatedSyntaxList arguments, int numSeparatorsToSkip) where T : SyntaxNode { var count = arguments.SeparatorCount - numSeparatorsToSkip; + if (count < 0) + return []; + var separators = new FixedSizeArrayBuilder(count); for (var i = 0; i < count; i++) From 8c74d24bdb28c9c72b97005049f4088388cdfb87 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 11:29:20 -0700 Subject: [PATCH 35/37] Remove explicit free --- .../ChangeSignature/AbstractChangeSignatureService.cs | 4 +--- .../CodeActionsLegacy/AbstractCodeActionTest_NoEditor.cs | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs index e6f5785a4a2f5..99322262f53c0 100644 --- a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs +++ b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs @@ -1013,7 +1013,7 @@ protected ImmutableArray GetPermutedDocCommentTrivia(SyntaxNode no updatedLeadingTrivia.Add(newTrivia); } - var extraNodeList = ArrayBuilder.GetInstance(); + using var _ = ArrayBuilder.GetInstance(out var extraNodeList); while (index < permutedParamNodes.Length) { extraNodeList.Add(permutedParamNodes[index]); @@ -1031,8 +1031,6 @@ protected ImmutableArray GetPermutedDocCommentTrivia(SyntaxNode no updatedLeadingTrivia.Add(newTrivia); } - extraNodeList.Free(); - return updatedLeadingTrivia.ToImmutableAndClear(); } diff --git a/src/Features/DiagnosticsTestUtilities/CodeActionsLegacy/AbstractCodeActionTest_NoEditor.cs b/src/Features/DiagnosticsTestUtilities/CodeActionsLegacy/AbstractCodeActionTest_NoEditor.cs index 6d88ecb9ef500..9b506aada4ead 100644 --- a/src/Features/DiagnosticsTestUtilities/CodeActionsLegacy/AbstractCodeActionTest_NoEditor.cs +++ b/src/Features/DiagnosticsTestUtilities/CodeActionsLegacy/AbstractCodeActionTest_NoEditor.cs @@ -105,7 +105,7 @@ internal async Task GetCodeRefactoringAsync( { var provider = CreateCodeRefactoringProvider(workspace, parameters); - var actions = ArrayBuilder<(CodeAction, TextSpan?)>.GetInstance(); + using var _ = ArrayBuilder<(CodeAction, TextSpan?)>.GetInstance(out var actions); var codeActionOptionsProvider = parameters.globalOptions?.IsEmpty() == false ? CodeActionOptionsStorage.GetCodeActionOptionsProvider(workspace.GlobalOptions) @@ -114,7 +114,6 @@ internal async Task GetCodeRefactoringAsync( var context = new CodeRefactoringContext(document, selectedOrAnnotatedSpan, (a, t) => actions.Add((a, t)), codeActionOptionsProvider, CancellationToken.None); await provider.ComputeRefactoringsAsync(context); var result = actions.Count > 0 ? new CodeRefactoring(provider, actions.ToImmutable(), FixAllProviderInfo.Create(provider), codeActionOptionsProvider) : null; - actions.Free(); return result; } From 305bb8ebc17177db26650d116c936ed48d5e4c52 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 11:34:43 -0700 Subject: [PATCH 36/37] Remove explicit free --- .../Core/Extensions/SyntaxTokenListExtensions.cs | 7 ------- .../CSharp/CodeGeneration/ConstructorGenerator.cs | 6 ++---- .../CSharp/CodeGeneration/EventGenerator.cs | 6 +++--- .../CSharp/CodeGeneration/FieldGenerator.cs | 12 ++---------- .../CSharp/CodeGeneration/MethodGenerator.cs | 10 +++------- .../CSharp/CodeGeneration/NamedTypeGenerator.cs | 14 +++----------- .../CSharp/CodeGeneration/PropertyGenerator.cs | 6 +++--- 7 files changed, 16 insertions(+), 45 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenListExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenListExtensions.cs index 13f8933d4a916..78f77b2d49258 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenListExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenListExtensions.cs @@ -11,11 +11,4 @@ internal static class SyntaxTokenListExtensions { public static SyntaxTokenList ToSyntaxTokenList(this IEnumerable tokens) => new(tokens); - - public static SyntaxTokenList ToSyntaxTokenListAndFree(this ArrayBuilder tokens) - { - var tokenList = new SyntaxTokenList(tokens); - tokens.Free(); - return tokenList; - } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ConstructorGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ConstructorGenerator.cs index 54057ca72c0df..1120246f9ee1f 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ConstructorGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ConstructorGenerator.cs @@ -117,7 +117,7 @@ private static BlockSyntax GenerateBlock( private static SyntaxTokenList GenerateModifiers(IMethodSymbol constructor, CSharpCodeGenerationContextInfo info) { - var tokens = ArrayBuilder.GetInstance(); + using var _ = ArrayBuilder.GetInstance(out var tokens); if (constructor.IsStatic) { @@ -129,10 +129,8 @@ private static SyntaxTokenList GenerateModifiers(IMethodSymbol constructor, CSha } if (CodeGenerationConstructorInfo.GetIsUnsafe(constructor)) - { tokens.Add(UnsafeKeyword); - } - return tokens.ToSyntaxTokenListAndFree(); + return tokens.ToSyntaxTokenList(); } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/EventGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/EventGenerator.cs index 3a1bc0601ce51..8f39cb352952a 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/EventGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/EventGenerator.cs @@ -192,7 +192,7 @@ private static bool HasAccessorBodies( private static SyntaxTokenList GenerateModifiers( IEventSymbol @event, CodeGenerationDestination destination, CSharpCodeGenerationContextInfo info) { - var tokens = ArrayBuilder.GetInstance(); + using var _ = ArrayBuilder.GetInstance(out var tokens); // Only "static" allowed if we're an explicit impl. if (@event.ExplicitInterfaceImplementations.Any()) @@ -216,7 +216,7 @@ private static SyntaxTokenList GenerateModifiers( } else { - CSharpCodeGenerationHelpers.AddAccessibilityModifiers(@event.DeclaredAccessibility, tokens, info, Accessibility.Private); + AddAccessibilityModifiers(@event.DeclaredAccessibility, tokens, info, Accessibility.Private); if (@event.IsStatic) tokens.Add(StaticKeyword); @@ -240,6 +240,6 @@ private static SyntaxTokenList GenerateModifiers( if (CodeGenerationEventInfo.GetIsUnsafe(@event)) tokens.Add(UnsafeKeyword); - return tokens.ToSyntaxTokenListAndFree(); + return tokens.ToSyntaxTokenList(); } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/FieldGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/FieldGenerator.cs index b20a5bf29fa0a..5c62a09916f54 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/FieldGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/FieldGenerator.cs @@ -121,7 +121,7 @@ public static FieldDeclarationSyntax GenerateFieldDeclaration( private static SyntaxTokenList GenerateModifiers(IFieldSymbol field, CSharpCodeGenerationContextInfo info) { - var tokens = ArrayBuilder.GetInstance(); + using var _ = ArrayBuilder.GetInstance(out var tokens); CSharpCodeGenerationHelpers.AddAccessibilityModifiers(field.DeclaredAccessibility, tokens, info, Accessibility.Private); if (field.IsConst) @@ -131,26 +131,18 @@ private static SyntaxTokenList GenerateModifiers(IFieldSymbol field, CSharpCodeG else { if (field.IsStatic) - { tokens.Add(StaticKeyword); - } if (field.IsReadOnly) - { tokens.Add(ReadOnlyKeyword); - } if (field.IsRequired) - { tokens.Add(RequiredKeyword); - } } if (CodeGenerationFieldInfo.GetIsUnsafe(field)) - { tokens.Add(UnsafeKeyword); - } - return tokens.ToSyntaxTokenListAndFree(); + return tokens.ToSyntaxTokenList(); } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/MethodGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/MethodGenerator.cs index 4e76fddfac39e..4cbf9e2c74082 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/MethodGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/MethodGenerator.cs @@ -254,7 +254,7 @@ private static SyntaxList GenerateDefaultCo private static SyntaxTokenList GenerateModifiers( IMethodSymbol method, CodeGenerationDestination destination, CSharpCodeGenerationContextInfo info) { - var tokens = ArrayBuilder.GetInstance(); + using var _ = ArrayBuilder.GetInstance(out var tokens); // Only "static" and "unsafe" modifiers allowed if we're an explicit impl. if (method.ExplicitInterfaceImplementations.Any()) @@ -282,7 +282,7 @@ private static SyntaxTokenList GenerateModifiers( else if (destination is not CodeGenerationDestination.CompilationUnit and not CodeGenerationDestination.Namespace) { - CSharpCodeGenerationHelpers.AddAccessibilityModifiers(method.DeclaredAccessibility, tokens, info, Accessibility.Private); + AddAccessibilityModifiers(method.DeclaredAccessibility, tokens, info, Accessibility.Private); if (method.IsStatic) tokens.Add(StaticKeyword); @@ -323,16 +323,12 @@ private static SyntaxTokenList GenerateModifiers( if (destination != CodeGenerationDestination.InterfaceType) { if (CodeGenerationMethodInfo.GetIsAsyncMethod(method)) - { tokens.Add(AsyncKeyword); - } } if (CodeGenerationMethodInfo.GetIsPartial(method) && method.IsAsync) - { tokens.Add(PartialKeyword); - } - return tokens.ToSyntaxTokenListAndFree(); + return tokens.ToSyntaxTokenList(); } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/NamedTypeGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/NamedTypeGenerator.cs index eaa4ba4e4ab0d..b806fe2c8933e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/NamedTypeGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/NamedTypeGenerator.cs @@ -268,14 +268,14 @@ private static SyntaxTokenList GenerateModifiers( CodeGenerationDestination destination, CSharpCodeGenerationContextInfo info) { - var tokens = ArrayBuilder.GetInstance(); + using var _ = ArrayBuilder.GetInstance(out var tokens); if (!namedType.IsFileLocal) { var defaultAccessibility = destination is CodeGenerationDestination.CompilationUnit or CodeGenerationDestination.Namespace ? Accessibility.Internal : Accessibility.Private; - CSharpCodeGenerationHelpers.AddAccessibilityModifiers(namedType.DeclaredAccessibility, tokens, info, defaultAccessibility); + AddAccessibilityModifiers(namedType.DeclaredAccessibility, tokens, info, defaultAccessibility); } else { @@ -291,28 +291,20 @@ private static SyntaxTokenList GenerateModifiers( if (namedType.TypeKind == TypeKind.Class) { if (namedType.IsAbstract) - { tokens.Add(AbstractKeyword); - } if (namedType.IsSealed) - { tokens.Add(SealedKeyword); - } } } if (namedType.IsReadOnly) - { tokens.Add(ReadOnlyKeyword); - } if (namedType.IsRefLikeType) - { tokens.Add(RefKeyword); - } - return tokens.ToSyntaxTokenListAndFree(); + return tokens.ToSyntaxTokenList(); } private static TypeParameterListSyntax? GenerateTypeParameterList( diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/PropertyGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/PropertyGenerator.cs index 9ce098e1446f4..388fb6fc21752 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/PropertyGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/PropertyGenerator.cs @@ -327,12 +327,12 @@ private static SyntaxTokenList GenerateAccessorModifiers( IMethodSymbol accessor, CSharpCodeGenerationContextInfo info) { - var modifiers = ArrayBuilder.GetInstance(); + using var _ = ArrayBuilder.GetInstance(out var modifiers); if (accessor.DeclaredAccessibility != Accessibility.NotApplicable && accessor.DeclaredAccessibility != property.DeclaredAccessibility) { - CSharpCodeGenerationHelpers.AddAccessibilityModifiers(accessor.DeclaredAccessibility, modifiers, info, property.DeclaredAccessibility); + AddAccessibilityModifiers(accessor.DeclaredAccessibility, modifiers, info, property.DeclaredAccessibility); } var hasNonReadOnlyAccessor = property.GetMethod?.IsReadOnly == false || property.SetMethod?.IsReadOnly == false; @@ -341,7 +341,7 @@ private static SyntaxTokenList GenerateAccessorModifiers( modifiers.Add(ReadOnlyKeyword); } - return modifiers.ToSyntaxTokenListAndFree(); + return modifiers.ToSyntaxTokenList(); } private static SyntaxTokenList GenerateModifiers( From 07896646a8042c5cf6b7e78d3462d60548312649 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 13 Apr 2024 11:40:29 -0700 Subject: [PATCH 37/37] Simplify --- .../Organizing/Organizers/ModifiersOrganizer.cs | 2 +- .../Compiler/Core/CompilerExtensions.projitems | 1 - .../Core/Extensions/SyntaxTokenListExtensions.cs | 14 -------------- .../CodeGeneration/CSharpCodeGenerationService.cs | 6 ++---- .../CSharp/CodeGeneration/ConstructorGenerator.cs | 9 ++++----- .../CSharp/CodeGeneration/EventGenerator.cs | 2 +- .../CSharp/CodeGeneration/FieldGenerator.cs | 8 ++++---- .../CSharp/CodeGeneration/MethodGenerator.cs | 2 +- .../CSharp/CodeGeneration/NamedTypeGenerator.cs | 2 +- .../CSharp/CodeGeneration/OperatorGenerator.cs | 4 +--- .../CSharp/CodeGeneration/PropertyGenerator.cs | 8 +++----- .../AbstractCodeGenerationService.cs | 6 +----- 12 files changed, 19 insertions(+), 45 deletions(-) delete mode 100644 src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenListExtensions.cs diff --git a/src/Features/CSharp/Portable/Organizing/Organizers/ModifiersOrganizer.cs b/src/Features/CSharp/Portable/Organizing/Organizers/ModifiersOrganizer.cs index 1e8336d3e1885..743e7b08a9f4e 100644 --- a/src/Features/CSharp/Portable/Organizing/Organizers/ModifiersOrganizer.cs +++ b/src/Features/CSharp/Portable/Organizing/Organizers/ModifiersOrganizer.cs @@ -27,7 +27,7 @@ public static SyntaxTokenList Organize(SyntaxTokenList modifiers) { finalList[0] = finalList[0].WithLeadingTrivia(leadingTrivia); - return finalList.ToSyntaxTokenList(); + return [.. finalList]; } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems index ac76082e5e8e3..87ccfaddde658 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems @@ -533,7 +533,6 @@ - diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenListExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenListExtensions.cs deleted file mode 100644 index 78f77b2d49258..0000000000000 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenListExtensions.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Collections.Generic; -using Microsoft.CodeAnalysis.PooledObjects; - -namespace Microsoft.CodeAnalysis.Shared.Extensions; - -internal static class SyntaxTokenListExtensions -{ - public static SyntaxTokenList ToSyntaxTokenList(this IEnumerable tokens) - => new(tokens); -} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/CSharpCodeGenerationService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/CSharpCodeGenerationService.cs index aaeae082f5d20..d70dc269c854c 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/CSharpCodeGenerationService.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/CSharpCodeGenerationService.cs @@ -729,14 +729,12 @@ private static TDeclarationNode UpdateDeclarationModifiers(TDe public override TDeclarationNode UpdateDeclarationModifiers(TDeclarationNode declaration, IEnumerable newModifiers, CSharpCodeGenerationContextInfo info, CancellationToken cancellationToken) { - SyntaxTokenList computeNewModifiersList(SyntaxTokenList modifiersList) => newModifiers.ToSyntaxTokenList(); - return UpdateDeclarationModifiers(declaration, computeNewModifiersList); + return UpdateDeclarationModifiers(declaration, _ => [.. newModifiers]); } public override TDeclarationNode UpdateDeclarationAccessibility(TDeclarationNode declaration, Accessibility newAccessibility, CSharpCodeGenerationContextInfo info, CancellationToken cancellationToken) { - SyntaxTokenList computeNewModifiersList(SyntaxTokenList modifiersList) => UpdateDeclarationAccessibility(modifiersList, newAccessibility, info); - return UpdateDeclarationModifiers(declaration, computeNewModifiersList); + return UpdateDeclarationModifiers(declaration, modifiersList => UpdateDeclarationAccessibility(modifiersList, newAccessibility, info)); } private static SyntaxTokenList UpdateDeclarationAccessibility(SyntaxTokenList modifiersList, Accessibility newAccessibility, CSharpCodeGenerationContextInfo info) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ConstructorGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ConstructorGenerator.cs index 1120246f9ee1f..2b9e2e42986d6 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ConstructorGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/ConstructorGenerator.cs @@ -10,12 +10,11 @@ using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.PooledObjects; -using Microsoft.CodeAnalysis.Shared.Extensions; -using static Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationHelpers; -using static Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpCodeGenerationHelpers; namespace Microsoft.CodeAnalysis.CSharp.CodeGeneration; +using static CodeGenerationHelpers; +using static CSharpCodeGenerationHelpers; using static CSharpSyntaxTokens; using static SyntaxFactory; @@ -125,12 +124,12 @@ private static SyntaxTokenList GenerateModifiers(IMethodSymbol constructor, CSha } else { - CSharpCodeGenerationHelpers.AddAccessibilityModifiers(constructor.DeclaredAccessibility, tokens, info, Accessibility.Private); + AddAccessibilityModifiers(constructor.DeclaredAccessibility, tokens, info, Accessibility.Private); } if (CodeGenerationConstructorInfo.GetIsUnsafe(constructor)) tokens.Add(UnsafeKeyword); - return tokens.ToSyntaxTokenList(); + return [.. tokens]; } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/EventGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/EventGenerator.cs index 8f39cb352952a..6891dcb45c718 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/EventGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/EventGenerator.cs @@ -240,6 +240,6 @@ private static SyntaxTokenList GenerateModifiers( if (CodeGenerationEventInfo.GetIsUnsafe(@event)) tokens.Add(UnsafeKeyword); - return tokens.ToSyntaxTokenList(); + return [.. tokens]; } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/FieldGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/FieldGenerator.cs index 5c62a09916f54..f6950b2e9d564 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/FieldGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/FieldGenerator.cs @@ -11,11 +11,11 @@ using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; -using static Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationHelpers; -using static Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpCodeGenerationHelpers; namespace Microsoft.CodeAnalysis.CSharp.CodeGeneration; +using static CodeGenerationHelpers; +using static CSharpCodeGenerationHelpers; using static CSharpSyntaxTokens; using static SyntaxFactory; @@ -123,7 +123,7 @@ private static SyntaxTokenList GenerateModifiers(IFieldSymbol field, CSharpCodeG { using var _ = ArrayBuilder.GetInstance(out var tokens); - CSharpCodeGenerationHelpers.AddAccessibilityModifiers(field.DeclaredAccessibility, tokens, info, Accessibility.Private); + AddAccessibilityModifiers(field.DeclaredAccessibility, tokens, info, Accessibility.Private); if (field.IsConst) { tokens.Add(ConstKeyword); @@ -143,6 +143,6 @@ private static SyntaxTokenList GenerateModifiers(IFieldSymbol field, CSharpCodeG if (CodeGenerationFieldInfo.GetIsUnsafe(field)) tokens.Add(UnsafeKeyword); - return tokens.ToSyntaxTokenList(); + return [.. tokens]; } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/MethodGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/MethodGenerator.cs index 4cbf9e2c74082..96beaea6d97c0 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/MethodGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/MethodGenerator.cs @@ -329,6 +329,6 @@ private static SyntaxTokenList GenerateModifiers( if (CodeGenerationMethodInfo.GetIsPartial(method) && method.IsAsync) tokens.Add(PartialKeyword); - return tokens.ToSyntaxTokenList(); + return [.. tokens]; } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/NamedTypeGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/NamedTypeGenerator.cs index b806fe2c8933e..810a767498d1b 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/NamedTypeGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/NamedTypeGenerator.cs @@ -304,7 +304,7 @@ private static SyntaxTokenList GenerateModifiers( if (namedType.IsRefLikeType) tokens.Add(RefKeyword); - return tokens.ToSyntaxTokenList(); + return [.. tokens]; } private static TypeParameterListSyntax? GenerateTypeParameterList( diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/OperatorGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/OperatorGenerator.cs index f9cb70919cb60..1e0c1fd58a445 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/OperatorGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/OperatorGenerator.cs @@ -119,10 +119,8 @@ private static SyntaxTokenList GenerateModifiers(IMethodSymbol method, CodeGener tokens.Add(StaticKeyword); if (method.IsAbstract) - { tokens.Add(AbstractKeyword); - } - return tokens.ToImmutableAndClear().ToSyntaxTokenList(); + return [.. tokens.ToImmutableAndClear()]; } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/PropertyGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/PropertyGenerator.cs index 388fb6fc21752..fb5130ab4ee32 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/PropertyGenerator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/PropertyGenerator.cs @@ -337,11 +337,9 @@ private static SyntaxTokenList GenerateAccessorModifiers( var hasNonReadOnlyAccessor = property.GetMethod?.IsReadOnly == false || property.SetMethod?.IsReadOnly == false; if (hasNonReadOnlyAccessor && accessor.IsReadOnly) - { modifiers.Add(ReadOnlyKeyword); - } - return modifiers.ToSyntaxTokenList(); + return [.. modifiers]; } private static SyntaxTokenList GenerateModifiers( @@ -370,7 +368,7 @@ private static SyntaxTokenList GenerateModifiers( } else if (destination is not CodeGenerationDestination.CompilationUnit) { - CSharpCodeGenerationHelpers.AddAccessibilityModifiers(property.DeclaredAccessibility, tokens, info, Accessibility.Private); + AddAccessibilityModifiers(property.DeclaredAccessibility, tokens, info, Accessibility.Private); if (property.IsStatic) tokens.Add(StaticKeyword); @@ -404,6 +402,6 @@ private static SyntaxTokenList GenerateModifiers( if (CodeGenerationPropertyInfo.GetIsUnsafe(property)) tokens.Add(UnsafeKeyword); - return tokens.ToSyntaxTokenList(); + return [.. tokens]; } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/AbstractCodeGenerationService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/AbstractCodeGenerationService.cs index 2da850bdcc8d9..9d3cb3850ad9c 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/AbstractCodeGenerationService.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/AbstractCodeGenerationService.cs @@ -557,9 +557,7 @@ protected static SyntaxTokenList GetUpdatedDeclarationAccessibilityModifiers( if (isAccessibilityModifier(modifier)) { if (newModifierTokens.Count == 0) - { continue; - } newModifier = newModifierTokens[0] .WithLeadingTrivia(modifier.LeadingTrivia) @@ -584,15 +582,13 @@ protected static SyntaxTokenList GetUpdatedDeclarationAccessibilityModifiers( if (!anyAccessModifierSeen) { for (var i = newModifierTokens.Count - 1; i >= 0; i--) - { updatedModifiersList.Insert(0, newModifierTokens[i]); - } } else { updatedModifiersList.AddRange(newModifierTokens); } - return updatedModifiersList.ToSyntaxTokenList(); + return [.. updatedModifiersList]; } }