diff --git a/src/Analyzers/Core/Analyzers/UseCollectionInitializer/UpdateExpressionState.cs b/src/Analyzers/Core/Analyzers/UseCollectionInitializer/UpdateExpressionState.cs index deb58119c61fc..d93969a9f41db 100644 --- a/src/Analyzers/Core/Analyzers/UseCollectionInitializer/UpdateExpressionState.cs +++ b/src/Analyzers/Core/Analyzers/UseCollectionInitializer/UpdateExpressionState.cs @@ -71,7 +71,7 @@ public UpdateExpressionState( public IEnumerable GetSubsequentStatements() => ContainingStatement is null - ? SpecializedCollections.EmptyEnumerable() + ? [] : UseCollectionInitializerHelpers.GetSubsequentStatements(SyntaxFacts, ContainingStatement); /// diff --git a/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs b/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs index 3f3c83c5355ba..b609ea8f86b6f 100644 --- a/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs +++ b/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs @@ -287,7 +287,7 @@ private static IEnumerable GetOwningNodes(SyntaxNode root, int posit var token = root.FindTokenFromEnd(position); if (token.Kind() == SyntaxKind.None) { - return SpecializedCollections.EmptyEnumerable(); + return []; } return token.GetAncestors() diff --git a/src/EditorFeatures/Core.Wpf/Preview/AbstractPreviewTaggerProvider.cs b/src/EditorFeatures/Core.Wpf/Preview/AbstractPreviewTaggerProvider.cs index 333328614e413..5d03c0d282277 100644 --- a/src/EditorFeatures/Core.Wpf/Preview/AbstractPreviewTaggerProvider.cs +++ b/src/EditorFeatures/Core.Wpf/Preview/AbstractPreviewTaggerProvider.cs @@ -50,7 +50,7 @@ public IEnumerable> GetTags(NormalizedSnapshotSpanCollection span return intersection.Select(s => new TagSpan(s, _tagInstance)); } - return SpecializedCollections.EmptyEnumerable>(); + return []; } public event EventHandler TagsChanged = (s, e) => { }; diff --git a/src/EditorFeatures/Core/Copilot/CopilotTaggerProvider.cs b/src/EditorFeatures/Core/Copilot/CopilotTaggerProvider.cs index 7468e5dd43fa3..d3e00b302cd76 100644 --- a/src/EditorFeatures/Core/Copilot/CopilotTaggerProvider.cs +++ b/src/EditorFeatures/Core/Copilot/CopilotTaggerProvider.cs @@ -64,10 +64,7 @@ protected override IEnumerable GetSpansToTag(ITextView? textView, Contract.ThrowIfNull(textView); // We only care about the cases where we have caret. - if (textView.GetCaretPoint(subjectBuffer) is { } caret) - return SpecializedCollections.SingletonEnumerable(new SnapshotSpan(caret, 0)); - - return SpecializedCollections.EmptyEnumerable(); + return textView.GetCaretPoint(subjectBuffer) is { } caret ? [new SnapshotSpan(caret, 0)] : []; } protected override async Task ProduceTagsAsync(TaggerContext context, DocumentSnapshotSpan spanToTag, int? caretPosition, CancellationToken cancellationToken) diff --git a/src/EditorFeatures/Core/InlineRename/InlineRenameSession.OpenTextBufferManager.cs b/src/EditorFeatures/Core/InlineRename/InlineRenameSession.OpenTextBufferManager.cs index f75305bfba53d..18a99ec18cde6 100644 --- a/src/EditorFeatures/Core/InlineRename/InlineRenameSession.OpenTextBufferManager.cs +++ b/src/EditorFeatures/Core/InlineRename/InlineRenameSession.OpenTextBufferManager.cs @@ -454,7 +454,7 @@ internal void ApplyConflictResolutionEdits(IInlineRenameReplacementInfo conflict // Show merge conflicts comments as unresolvable conflicts, and do not // show any other rename-related spans that overlap a merge conflict comment. mergeResult.MergeConflictCommentSpans.TryGetValue(document.Id, out var mergeConflictComments); - mergeConflictComments ??= SpecializedCollections.EmptyEnumerable(); + mergeConflictComments ??= []; foreach (var conflict in mergeConflictComments) { @@ -545,7 +545,7 @@ private static async Task> GetTextChangesFromTextDiffere if (oldDocument == newDocument) { // no changes - return SpecializedCollections.EmptyEnumerable(); + return []; } if (newDocument.Id != oldDocument.Id) @@ -558,7 +558,7 @@ private static async Task> GetTextChangesFromTextDiffere if (oldText == newText) { - return SpecializedCollections.EmptyEnumerable(); + return []; } var textChanges = newText.GetTextChanges(oldText).ToList(); diff --git a/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs b/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs index bb8d8217667c3..70d17e84c9b60 100644 --- a/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs +++ b/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs @@ -422,7 +422,7 @@ private void SetReferenceLocations(ImmutableArray location if (!documents.Any(static (d, locationsByDocument) => locationsByDocument.Contains(d.Id), locationsByDocument)) { - _openTextBuffers[textBuffer].SetReferenceSpans(SpecializedCollections.EmptyEnumerable()); + _openTextBuffers[textBuffer].SetReferenceSpans([]); } else { diff --git a/src/EditorFeatures/Core/Shared/Utilities/ThreadingContextTaskSchedulerProvider.cs b/src/EditorFeatures/Core/Shared/Utilities/ThreadingContextTaskSchedulerProvider.cs index fe6b2dcf2ae46..fe845adb6458c 100644 --- a/src/EditorFeatures/Core/Shared/Utilities/ThreadingContextTaskSchedulerProvider.cs +++ b/src/EditorFeatures/Core/Shared/Utilities/ThreadingContextTaskSchedulerProvider.cs @@ -29,7 +29,7 @@ private sealed class JoinableTaskFactoryTaskScheduler(JoinableTaskFactory joinab public override int MaximumConcurrencyLevel => 1; protected override IEnumerable GetScheduledTasks() - => SpecializedCollections.EmptyEnumerable(); + => []; protected override void QueueTask(Task task) { diff --git a/src/EditorFeatures/Core/Tagging/AsynchronousViewportTaggerProvider.SingleViewportTaggerProvider.cs b/src/EditorFeatures/Core/Tagging/AsynchronousViewportTaggerProvider.SingleViewportTaggerProvider.cs index 6e9e4672dad6c..95f1635b7e39c 100644 --- a/src/EditorFeatures/Core/Tagging/AsynchronousViewportTaggerProvider.SingleViewportTaggerProvider.cs +++ b/src/EditorFeatures/Core/Tagging/AsynchronousViewportTaggerProvider.SingleViewportTaggerProvider.cs @@ -73,7 +73,7 @@ protected override IEnumerable GetSpansToTag(ITextView? textView, // above/below tagger should tag nothing. return _viewPortToTag == ViewPortToTag.InView ? base.GetSpansToTag(textView, subjectBuffer) - : SpecializedCollections.EmptyEnumerable(); + : []; } var visibleSpan = visibleSpanOpt.Value; diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/ChangeSignature/AbstractChangeSignatureTests.cs b/src/EditorFeatures/DiagnosticsTestUtilities/ChangeSignature/AbstractChangeSignatureTests.cs index 5cfcd4c680088..df222010dd24b 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/ChangeSignature/AbstractChangeSignatureTests.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/ChangeSignature/AbstractChangeSignatureTests.cs @@ -252,7 +252,7 @@ private static IEnumerable> GetPermutations(IEnumerable li { if (!list.Any()) { - yield return SpecializedCollections.EmptyEnumerable(); + yield return []; yield break; } @@ -286,9 +286,7 @@ private static IEnumerable GetListWithoutElementAtIndex(IEnumerable li private static IEnumerable> GetSubsets(IEnumerable list) { if (!list.Any()) - { - return SpecializedCollections.SingletonEnumerable(SpecializedCollections.EmptyEnumerable()); - } + return [[]]; var firstElement = list.Take(1); diff --git a/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs b/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs index 725475248e839..6a61dc2a06b30 100644 --- a/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs +++ b/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs @@ -54,7 +54,7 @@ public async Task TestGetFirstDiagnosticWithFixAsync() var logger = SpecializedCollections.SingletonEnumerable(new Lazy(() => workspace.Services.GetRequiredService())); var fixService = new CodeFixService( - diagnosticService, logger, fixers, SpecializedCollections.EmptyEnumerable>()); + diagnosticService, logger, fixers, configurationProviders: []); var reference = new MockAnalyzerReference(); var project = workspace.CurrentSolution.Projects.Single().AddAnalyzerReference(reference); @@ -366,7 +366,7 @@ private static (EditorTestWorkspace workspace, DiagnosticAnalyzerService analyze var configurationFixProviders = includeConfigurationFixProviders ? workspace.ExportProvider.GetExports() - : SpecializedCollections.EmptyEnumerable>(); + : []; var fixService = new CodeFixService( diagnosticService, @@ -768,7 +768,7 @@ private static async Task> GetNuGetAndVsixCode var vsixFixers = vsixFixer != null ? SpecializedCollections.SingletonEnumerable(new Lazy(() => vsixFixer, new CodeChangeProviderMetadata(name: nameof(VsixCodeFixProvider), languages: LanguageNames.CSharp))) - : SpecializedCollections.EmptyEnumerable>(); + : []; using var workspace = TestWorkspace.CreateCSharp(code, composition: s_compositionWithMockDiagnosticUpdateSourceRegistrationService, openDocuments: true); @@ -776,7 +776,7 @@ private static async Task> GetNuGetAndVsixCode var logger = SpecializedCollections.SingletonEnumerable(new Lazy(() => workspace.Services.GetRequiredService())); var fixService = new CodeFixService( - diagnosticService, logger, vsixFixers, SpecializedCollections.EmptyEnumerable>()); + diagnosticService, logger, vsixFixers, configurationProviders: []); diagnosticAnalyzer ??= new MockAnalyzerReference.MockDiagnosticAnalyzer(); var analyzers = ImmutableArray.Create(diagnosticAnalyzer); diff --git a/src/EditorFeatures/Test/MetadataAsSource/AbstractMetadataAsSourceTests.TestContext.cs b/src/EditorFeatures/Test/MetadataAsSource/AbstractMetadataAsSourceTests.TestContext.cs index 3afca1874b065..8044e56df5a09 100644 --- a/src/EditorFeatures/Test/MetadataAsSource/AbstractMetadataAsSourceTests.TestContext.cs +++ b/src/EditorFeatures/Test/MetadataAsSource/AbstractMetadataAsSourceTests.TestContext.cs @@ -44,7 +44,7 @@ public static TestContext Create( string? metadataCommonReferences = null) { projectLanguage ??= LanguageNames.CSharp; - metadataSources ??= SpecializedCollections.EmptyEnumerable(); + metadataSources ??= []; metadataSources = !metadataSources.Any() ? new[] { AbstractMetadataAsSourceTests.DefaultMetadataSource } : metadataSources; diff --git a/src/EditorFeatures/TestUtilities/Preview/MockPreviewPaneService.cs b/src/EditorFeatures/TestUtilities/Preview/MockPreviewPaneService.cs index 3fea5e6d0da58..d7941be6d254d 100644 --- a/src/EditorFeatures/TestUtilities/Preview/MockPreviewPaneService.cs +++ b/src/EditorFeatures/TestUtilities/Preview/MockPreviewPaneService.cs @@ -27,7 +27,7 @@ public MockPreviewPaneService() public object GetPreviewPane(DiagnosticData diagnostic, IReadOnlyList previewContents) { - var contents = previewContents ?? SpecializedCollections.EmptyEnumerable(); + var contents = previewContents ?? []; foreach (var content in contents.OfType()) { diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/AttributeNamedParameterCompletionProvider.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/AttributeNamedParameterCompletionProvider.cs index 61b65f0f72745..6e703ff629340 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/AttributeNamedParameterCompletionProvider.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/AttributeNamedParameterCompletionProvider.cs @@ -228,7 +228,7 @@ private static IEnumerable> GetParameterLists( .Select(c => c.Parameters); } - return SpecializedCollections.EmptyEnumerable>(); + return []; } private static IEnumerable GetAttributeNamedParameters( diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.cs index f19c7ca86ed08..f4a7ef5437256 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.cs @@ -180,7 +180,7 @@ public override bool IsInsertionTrigger(SourceText text, int characterPosition, } catch (Exception e) when (FatalError.ReportAndCatchUnlessCanceled(e, cancellationToken, ErrorSeverity.General)) { - return SpecializedCollections.EmptyEnumerable(); + return []; } } diff --git a/src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs b/src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs index 5c033411ba311..1b92ad61e2447 100644 --- a/src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs +++ b/src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs @@ -851,9 +851,7 @@ internal static TextSpan CreateSpanForVariableDeclarator( internal static IEnumerable GetActiveTokensForVariableDeclarator(VariableDeclaratorSyntax variableDeclarator, SyntaxTokenList modifiers, SyntaxToken semicolon) { if (variableDeclarator.Initializer == null || modifiers.Any(SyntaxKind.ConstKeyword)) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; // [|int F = 1;|] var variableDeclaration = (VariableDeclarationSyntax)variableDeclarator.Parent!; diff --git a/src/Features/CSharp/Portable/EditAndContinue/SyntaxComparer.cs b/src/Features/CSharp/Portable/EditAndContinue/SyntaxComparer.cs index b3472fac53302..c8352f7280dfa 100644 --- a/src/Features/CSharp/Portable/EditAndContinue/SyntaxComparer.cs +++ b/src/Features/CSharp/Portable/EditAndContinue/SyntaxComparer.cs @@ -1003,7 +1003,7 @@ private static void GetNestedFunctionsParts( } else { - parameters = SpecializedCollections.EmptyEnumerable(); + parameters = []; } asyncKeyword = anonymous.AsyncKeyword; diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.TriviaResult.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.TriviaResult.cs index 0d85ae254fd28..c476422c16404 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.TriviaResult.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.TriviaResult.cs @@ -104,7 +104,7 @@ private IEnumerable TriviaResolver( { return (location == TriviaLocation.AfterBeginningOfSpan) ? SpecializedCollections.SingletonEnumerable(SyntaxFactory.ElasticMarker) - : SpecializedCollections.EmptyEnumerable(); + : []; } } else @@ -114,15 +114,15 @@ private IEnumerable TriviaResolver( { return (location == TriviaLocation.AfterBeginningOfSpan) ? SpecializedCollections.SingletonEnumerable(SyntaxFactory.ElasticMarker) - : SpecializedCollections.EmptyEnumerable(); + : []; } } triviaMap.TryGetValue(tokenPair.PreviousToken, out var previousTriviaPair); - var trailingTrivia = previousTriviaPair.TrailingTrivia ?? SpecializedCollections.EmptyEnumerable(); + var trailingTrivia = previousTriviaPair.TrailingTrivia ?? []; triviaMap.TryGetValue(tokenPair.NextToken, out var nextTriviaPair); - var leadingTrivia = nextTriviaPair.LeadingTrivia ?? SpecializedCollections.EmptyEnumerable(); + var leadingTrivia = nextTriviaPair.LeadingTrivia ?? []; var list = trailingTrivia.Concat(leadingTrivia); @@ -166,7 +166,7 @@ private static IEnumerable AppendLeadingTrivia(PreviousNextTokenPa return tokenPair.NextToken.LeadingTrivia; } - return SpecializedCollections.EmptyEnumerable(); + return []; } private static IEnumerable AppendTrailingTrivia(PreviousNextTokenPair tokenPair) @@ -177,7 +177,7 @@ private static IEnumerable AppendTrailingTrivia(PreviousNextTokenP return tokenPair.PreviousToken.TrailingTrivia; } - return SpecializedCollections.EmptyEnumerable(); + return []; } } } diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionValidator.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionValidator.cs index c27ebc93ca693..9cd285c0abee1 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionValidator.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionValidator.cs @@ -453,9 +453,7 @@ public override IEnumerable GetOuterReturnStatements(SyntaxNode comm var container = commonRoot.GetAncestorsOrThis().Where(a => a.IsReturnableConstruct()).FirstOrDefault(); if (container == null) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var returnableConstructPairs = returnStatements.Select(r => (r, r.GetAncestors().Where(a => a.IsReturnableConstruct()).FirstOrDefault())) .Where(p => p.Item2 != null); diff --git a/src/Features/CSharp/Portable/NavigationBar/CSharpNavigationBarItemService.cs b/src/Features/CSharp/Portable/NavigationBar/CSharpNavigationBarItemService.cs index f08ad9316eb71..1f06dc9100fd9 100644 --- a/src/Features/CSharp/Portable/NavigationBar/CSharpNavigationBarItemService.cs +++ b/src/Features/CSharp/Portable/NavigationBar/CSharpNavigationBarItemService.cs @@ -131,9 +131,7 @@ private static IEnumerable GetTypesInFile(SemanticModel semant while (!nodesToVisit.IsEmpty()) { if (cancellationToken.IsCancellationRequested) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var node = nodesToVisit.Pop(); var type = GetType(semanticModel, node, cancellationToken); diff --git a/src/Features/CSharp/Portable/Organizing/Organizers/ModifiersOrganizer.cs b/src/Features/CSharp/Portable/Organizing/Organizers/ModifiersOrganizer.cs index d4cec0353fc69..1e8336d3e1885 100644 --- a/src/Features/CSharp/Portable/Organizing/Organizers/ModifiersOrganizer.cs +++ b/src/Features/CSharp/Portable/Organizing/Organizers/ModifiersOrganizer.cs @@ -20,7 +20,7 @@ public static SyntaxTokenList Organize(SyntaxTokenList modifiers) { var initialList = new List(modifiers); var leadingTrivia = initialList.First().LeadingTrivia; - initialList[0] = initialList[0].WithLeadingTrivia(SpecializedCollections.EmptyEnumerable()); + initialList[0] = initialList[0].WithLeadingTrivia(); var finalList = initialList.OrderBy(new Comparer()).ToList(); if (!initialList.SequenceEqual(finalList)) diff --git a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs index d6f7f10fac8c1..b4aa13a190617 100644 --- a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs +++ b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs @@ -43,6 +43,6 @@ protected override async Task> ComputeOperation } } - return SpecializedCollections.EmptyEnumerable(); + return []; } } diff --git a/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.GlobalSuppressMessageFixAllCodeAction.cs b/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.GlobalSuppressMessageFixAllCodeAction.cs index 5eb68373b0d5c..0db9273f39dbf 100644 --- a/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.GlobalSuppressMessageFixAllCodeAction.cs +++ b/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.GlobalSuppressMessageFixAllCodeAction.cs @@ -211,9 +211,7 @@ private static void AddDiagnosticForSymbolIfNeeded(ISymbol targetSymbol, Diagnos private static IEnumerable>> CreateDiagnosticsBySymbol(ImmutableDictionary>.Builder diagnosticsMapBuilder) { if (diagnosticsMapBuilder.Count == 0) - { - return SpecializedCollections.EmptyEnumerable>>(); - } + return []; var builder = new List>>(); foreach (var (symbol, diagnostics) in diagnosticsMapBuilder) diff --git a/src/Features/Core/Portable/Completion/Providers/AbstractDocCommentCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/AbstractDocCommentCompletionProvider.cs index e8ed717a8bf9d..6171d46223c1d 100644 --- a/src/Features/Core/Portable/Completion/Providers/AbstractDocCommentCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/AbstractDocCommentCompletionProvider.cs @@ -207,7 +207,7 @@ protected IEnumerable GetAttributeValueItems(ISymbol? symbol, st return s_listTypeValues.Select(CreateCompletionItem); } - return SpecializedCollections.EmptyEnumerable(); + return []; } protected ImmutableArray GetTopLevelItems(ISymbol? symbol, TSyntax syntax) diff --git a/src/Features/Core/Portable/Completion/Providers/AbstractPartialTypeCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/AbstractPartialTypeCompletionProvider.cs index 65b0957c36f00..37f354e2f5c9b 100644 --- a/src/Features/Core/Portable/Completion/Providers/AbstractPartialTypeCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/AbstractPartialTypeCompletionProvider.cs @@ -88,9 +88,7 @@ private CompletionItem CreateCompletionItem(INamedTypeSymbol symbol, TSyntaxCont var semanticModel = context.SemanticModel; if (declaredSymbol.ContainingSymbol is not INamespaceOrTypeSymbol containingSymbol) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return semanticModel.LookupNamespacesAndTypes(context.Position, containingSymbol) .OfType() diff --git a/src/Features/Core/Portable/Completion/Providers/Scripting/GlobalAssemblyCacheCompletionHelper.cs b/src/Features/Core/Portable/Completion/Providers/Scripting/GlobalAssemblyCacheCompletionHelper.cs index 103ffcbb2032b..680be79a82ff1 100644 --- a/src/Features/Core/Portable/Completion/Providers/Scripting/GlobalAssemblyCacheCompletionHelper.cs +++ b/src/Features/Core/Portable/Completion/Providers/Scripting/GlobalAssemblyCacheCompletionHelper.cs @@ -63,8 +63,5 @@ internal ImmutableArray GetItems(string directoryPath, Cancellat } private static IEnumerable GetAssemblyIdentities(string partialName) - { - return IOUtilities.PerformIO(() => GlobalAssemblyCache.Instance.GetAssemblyIdentities(partialName), - SpecializedCollections.EmptyEnumerable()); - } + => IOUtilities.PerformIO(() => GlobalAssemblyCache.Instance.GetAssemblyIdentities(partialName), []); } diff --git a/src/Features/Core/Portable/EditAndContinue/EditAndContinueService.cs b/src/Features/Core/Portable/EditAndContinue/EditAndContinueService.cs index 4c3265462f7e7..ee551a3796cd7 100644 --- a/src/Features/Core/Portable/EditAndContinue/EditAndContinueService.cs +++ b/src/Features/Core/Portable/EditAndContinue/EditAndContinueService.cs @@ -146,7 +146,7 @@ public async ValueTask StartDebuggingSessionAsync( } else { - initialDocumentStates = SpecializedCollections.EmptyEnumerable>(); + initialDocumentStates = []; } var sessionId = new DebuggingSessionId(Interlocked.Increment(ref s_debuggingSessionId)); diff --git a/src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.cs b/src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.cs index 006826cd33f57..bccd7842bc6fe 100644 --- a/src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.cs +++ b/src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.cs @@ -524,8 +524,8 @@ public UnitTestingReanalyzeScope(SolutionId solutionId) public UnitTestingReanalyzeScope(IEnumerable? projectIds = null, IEnumerable? documentIds = null) { - projectIds ??= SpecializedCollections.EmptyEnumerable(); - documentIds ??= SpecializedCollections.EmptyEnumerable(); + projectIds ??= []; + documentIds ??= []; _solutionId = null; _projectOrDocumentIds = new HashSet(projectIds); diff --git a/src/Features/Core/Portable/ExtractClass/ExtractClassWithDialogCodeAction.cs b/src/Features/Core/Portable/ExtractClass/ExtractClassWithDialogCodeAction.cs index 86ecfc7723b81..4fa3b561c7aa5 100644 --- a/src/Features/Core/Portable/ExtractClass/ExtractClassWithDialogCodeAction.cs +++ b/src/Features/Core/Portable/ExtractClass/ExtractClassWithDialogCodeAction.cs @@ -61,11 +61,9 @@ protected sealed override CodeActionPriority ComputePriority() protected override async Task> ComputeOperationsAsync( object options, IProgress progressTracker, CancellationToken cancellationToken) { + // If user click cancel button, options will be null and hit this branch if (options is not ExtractClassOptions extractClassOptions) - { - // If user click cancel button, options will be null and hit this branch - return SpecializedCollections.EmptyEnumerable(); - } + return []; // Map the symbols we're removing to annotations // so we can find them easily diff --git a/src/Features/Core/Portable/ExtractMethod/AbstractSyntaxTriviaService.Result.cs b/src/Features/Core/Portable/ExtractMethod/AbstractSyntaxTriviaService.Result.cs index 76b4d6663d422..58baa2a73d19e 100644 --- a/src/Features/Core/Portable/ExtractMethod/AbstractSyntaxTriviaService.Result.cs +++ b/src/Features/Core/Portable/ExtractMethod/AbstractSyntaxTriviaService.Result.cs @@ -148,9 +148,7 @@ private LeadingTrailingTriviaPair CreateTriviaPairs( { // beginning of the tree if (tokenPair.PreviousToken.RawKind == 0) - { - return new LeadingTrailingTriviaPair { TrailingTrivia = SpecializedCollections.EmptyEnumerable(), LeadingTrivia = trivia }; - } + return new LeadingTrailingTriviaPair { TrailingTrivia = [], LeadingTrivia = trivia }; return GetTrailingAndLeadingTrivia(trivia); } @@ -275,10 +273,10 @@ private static IEnumerable ResolveTrivia( Dictionary triviaMap) { triviaMap.TryGetValue(tokenPair.PreviousToken, out var previousTriviaPair); - var trailingTrivia = previousTriviaPair.TrailingTrivia ?? SpecializedCollections.EmptyEnumerable(); + var trailingTrivia = previousTriviaPair.TrailingTrivia ?? []; triviaMap.TryGetValue(tokenPair.NextToken, out var nextTriviaPair); - var leadingTrivia = nextTriviaPair.LeadingTrivia ?? SpecializedCollections.EmptyEnumerable(); + var leadingTrivia = nextTriviaPair.LeadingTrivia ?? []; return tokenPair.PreviousToken.TrailingTrivia.Concat(trailingTrivia).Concat(leadingTrivia).Concat(tokenPair.NextToken.LeadingTrivia); } diff --git a/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs b/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs index 0114fd1847205..6611b672c28e8 100644 --- a/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs +++ b/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs @@ -887,21 +887,15 @@ private static IEnumerable AppendTypeParametersInConstrain ITypeSymbol type, HashSet visited) { if (visited.Contains(type)) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; visited.Add(type); if (type.OriginalDefinition.Equals(type)) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; if (type is not INamedTypeSymbol constructedType) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var parameters = constructedType.GetAllTypeParameters().ToList(); var arguments = constructedType.GetAllTypeArguments().ToList(); diff --git a/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.GenerateConstructorWithDialogCodeAction.cs b/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.GenerateConstructorWithDialogCodeAction.cs index 6b17db6afc991..1b89718070601 100644 --- a/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.GenerateConstructorWithDialogCodeAction.cs +++ b/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.GenerateConstructorWithDialogCodeAction.cs @@ -57,9 +57,7 @@ protected override async Task> ComputeOperation { var result = (PickMembersResult)options; if (result.IsCanceled) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var addNullChecksOption = result.Options.FirstOrDefault(o => o.Id == AddNullChecksId); if (addNullChecksOption != null) @@ -79,9 +77,7 @@ protected override async Task> ComputeOperation result.Members, _fallbackOptions, cancellationToken).ConfigureAwait(false); if (state == null) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; // There was an existing constructor that matched what the user wants to create. // Generate it if it's the implicit, no-arg, constructor, otherwise just navigate diff --git a/src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndHashWithDialogCodeAction.cs b/src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndHashWithDialogCodeAction.cs index ea795e1ab5782..755f08914b06a 100644 --- a/src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndHashWithDialogCodeAction.cs +++ b/src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndHashWithDialogCodeAction.cs @@ -56,7 +56,7 @@ protected override async Task> ComputeOperation { var result = (PickMembersResult)options; if (result.IsCanceled) - return SpecializedCollections.EmptyEnumerable(); + return []; var solution = _document.Project.Solution; diff --git a/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesWithDialogCodeAction.cs b/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesWithDialogCodeAction.cs index 326aef8fce1bc..dafdd480c971e 100644 --- a/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesWithDialogCodeAction.cs +++ b/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesWithDialogCodeAction.cs @@ -54,7 +54,7 @@ protected override async Task> ComputeOperation { var result = (PickMembersResult)options; if (result.IsCanceled || result.Members.Length == 0) - return SpecializedCollections.EmptyEnumerable(); + return []; var syntaxTree = await _document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); RoslynDebug.AssertNotNull(syntaxTree); diff --git a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.GenerateNamedType.cs b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.GenerateNamedType.cs index a38ed48c9e31e..a85787d4e4be3 100644 --- a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.GenerateNamedType.cs +++ b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.GenerateNamedType.cs @@ -321,7 +321,7 @@ protected IList GetAvailableTypeParameters() var availableInnerTypeParameters = _service.GetTypeParameters(_state, _semanticDocument.SemanticModel, _cancellationToken); var availableOuterTypeParameters = !_intoNamespace && _state.TypeToGenerateInOpt != null ? _state.TypeToGenerateInOpt.GetAllTypeParameters() - : SpecializedCollections.EmptyEnumerable(); + : []; return availableOuterTypeParameters.Concat(availableInnerTypeParameters).ToList(); } diff --git a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs index f2e55c928e008..3a45f46b1aa00 100644 --- a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs +++ b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs @@ -272,7 +272,7 @@ protected IList GetAvailableTypeParameters( var availableInnerTypeParameters = GetTypeParameters(state, semanticModel, cancellationToken); var availableOuterTypeParameters = !intoNamespace && state.TypeToGenerateInOpt != null ? state.TypeToGenerateInOpt.GetAllTypeParameters() - : SpecializedCollections.EmptyEnumerable(); + : []; return availableOuterTypeParameters.Concat(availableInnerTypeParameters).ToList(); } diff --git a/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.CodeAction.cs b/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.CodeAction.cs index 425bfac34f9a4..335f52732a0c0 100644 --- a/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.CodeAction.cs +++ b/src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.CodeAction.cs @@ -307,7 +307,7 @@ private string DetermineMemberName(ISymbol member, ArrayBuilder impleme // // In this case we only want to generate 'Goo' once. if (HasMatchingMember(implementedVisibleMembers, member)) - return SpecializedCollections.EmptyEnumerable(); + return []; var memberName = DetermineMemberName(member, implementedVisibleMembers); diff --git a/src/Features/Core/Portable/MoveStaticMembers/MoveStaticMembersWithDialogCodeAction.cs b/src/Features/Core/Portable/MoveStaticMembers/MoveStaticMembersWithDialogCodeAction.cs index 41acdd3bfcfc5..230248be794f6 100644 --- a/src/Features/Core/Portable/MoveStaticMembers/MoveStaticMembersWithDialogCodeAction.cs +++ b/src/Features/Core/Portable/MoveStaticMembers/MoveStaticMembersWithDialogCodeAction.cs @@ -45,9 +45,7 @@ protected override async Task> ComputeOperation object options, IProgress progressTracker, CancellationToken cancellationToken) { if (options is not MoveStaticMembersOptions moveOptions || moveOptions.IsCancelled) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; // Find the original doc root var syntaxFacts = _document.GetRequiredLanguageService(); diff --git a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs index f5e3536f2b965..468ab3d47b214 100644 --- a/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs +++ b/src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceCodeAction.cs @@ -60,7 +60,7 @@ protected sealed override async Task> ComputeOp } } - return SpecializedCollections.EmptyEnumerable(); + return []; } private static ImmutableArray CreateRenameOperations(MoveToNamespaceResult moveToNamespaceResult) diff --git a/src/Features/Core/Portable/PullMemberUp/Dialog/PullMemberUpWithDialogCodeAction.cs b/src/Features/Core/Portable/PullMemberUp/Dialog/PullMemberUpWithDialogCodeAction.cs index ff4984a8d706b..8628c09a294b2 100644 --- a/src/Features/Core/Portable/PullMemberUp/Dialog/PullMemberUpWithDialogCodeAction.cs +++ b/src/Features/Core/Portable/PullMemberUp/Dialog/PullMemberUpWithDialogCodeAction.cs @@ -49,7 +49,7 @@ protected override async Task> ComputeOperation else { // If user click cancel button, options will be null and hit this branch - return SpecializedCollections.EmptyEnumerable(); + return []; } } } diff --git a/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs b/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs index ee949d13fc251..56ad59f47dbcb 100644 --- a/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs @@ -164,7 +164,7 @@ private static async Task ReplaceMethodsWithPropertyAsync( var getMethodReferences = await SymbolFinder.FindReferencesAsync( getMethod, originalSolution, cancellationToken).ConfigureAwait(false); var setMethodReferences = setMethod == null - ? SpecializedCollections.EmptyEnumerable() + ? [] : await SymbolFinder.FindReferencesAsync( setMethod, originalSolution, cancellationToken).ConfigureAwait(false); diff --git a/src/Features/Core/Portable/ReplacePropertyWithMethods/AbstractReplacePropertyWithMethodsService.cs b/src/Features/Core/Portable/ReplacePropertyWithMethods/AbstractReplacePropertyWithMethodsService.cs index 06a711b6b28f9..cf856cb40a3bf 100644 --- a/src/Features/Core/Portable/ReplacePropertyWithMethods/AbstractReplacePropertyWithMethodsService.cs +++ b/src/Features/Core/Portable/ReplacePropertyWithMethods/AbstractReplacePropertyWithMethodsService.cs @@ -399,7 +399,7 @@ private TExpressionSyntax GetInvocationExpression( var updatedExpression = _expression.ReplaceNode(_identifierName, newIdentifierName); var arguments = argument == null - ? SpecializedCollections.EmptyEnumerable() + ? [] : SpecializedCollections.SingletonEnumerable(argument); var invocation = Generator.InvocationExpression(updatedExpression, arguments); diff --git a/src/Features/Core/Portable/SignatureHelp/SignatureHelpItem.cs b/src/Features/Core/Portable/SignatureHelp/SignatureHelpItem.cs index 134503519a861..35ff80955b3ab 100644 --- a/src/Features/Core/Portable/SignatureHelp/SignatureHelpItem.cs +++ b/src/Features/Core/Portable/SignatureHelp/SignatureHelpItem.cs @@ -35,8 +35,7 @@ internal class SignatureHelpItem public Func> DocumentationFactory { get; } - private static readonly Func> s_emptyDocumentationFactory = - _ => SpecializedCollections.EmptyEnumerable(); + private static readonly Func> s_emptyDocumentationFactory = _ => []; public SignatureHelpItem( bool isVariadic, diff --git a/src/Features/Core/Portable/SignatureHelp/SignatureHelpParameter.cs b/src/Features/Core/Portable/SignatureHelp/SignatureHelpParameter.cs index e3b5f5523f87b..7a83abe7eed24 100644 --- a/src/Features/Core/Portable/SignatureHelp/SignatureHelpParameter.cs +++ b/src/Features/Core/Portable/SignatureHelp/SignatureHelpParameter.cs @@ -65,8 +65,7 @@ internal class SignatureHelpSymbolParameter( /// public IList SelectedDisplayParts { get; } = selectedDisplayParts.ToImmutableArrayOrEmpty(); - private static readonly Func> s_emptyDocumentationFactory = - _ => SpecializedCollections.EmptyEnumerable(); + private static readonly Func> s_emptyDocumentationFactory = _ => []; internal IEnumerable GetAllParts() { @@ -134,8 +133,7 @@ internal class SignatureHelpParameter( /// public IList SelectedDisplayParts { get; } = selectedDisplayParts.ToImmutableArrayOrEmpty(); - private static readonly Func> s_emptyDocumentationFactory = - _ => SpecializedCollections.EmptyEnumerable(); + private static readonly Func> s_emptyDocumentationFactory = _ => []; // Constructor kept for binary compat with TS. Remove when they move to the new API. public SignatureHelpParameter( diff --git a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractLockSnippetProvider.cs b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractLockSnippetProvider.cs index c37380580b8da..8d1d1c2488ada 100644 --- a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractLockSnippetProvider.cs +++ b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractLockSnippetProvider.cs @@ -16,7 +16,7 @@ internal abstract class AbstractLockSnippetProvider : Abst protected sealed override Task GenerateSnippetTextChangeAsync(Document document, int position, CancellationToken cancellationToken) { var generator = SyntaxGenerator.GetGenerator(document); - var statement = generator.LockStatement(generator.ThisExpression(), SpecializedCollections.EmptyEnumerable()); + var statement = generator.LockStatement(generator.ThisExpression(), statements: []); return Task.FromResult(new TextChange(TextSpan.FromBounds(position, position), statement.NormalizeWhitespace().ToFullString())); } } diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor.cs index f785abc52551a..b100f02f23ed2 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor.cs @@ -83,13 +83,11 @@ public async Task> ComputeDiagnosticsAsync(Diagnosti { return loadDiagnostic != null ? SpecializedCollections.SingletonEnumerable(DiagnosticData.Create(loadDiagnostic, textDocument)) - : SpecializedCollections.EmptyEnumerable(); + : []; } if (loadDiagnostic != null) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; if (analyzer == GeneratorDiagnosticsPlaceholderAnalyzer.Instance) { @@ -101,16 +99,14 @@ public async Task> ComputeDiagnosticsAsync(Diagnosti } else { - return SpecializedCollections.EmptyEnumerable(); + return []; } } if (analyzer is DocumentDiagnosticAnalyzer documentAnalyzer) { if (document == null) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var documentDiagnostics = await ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync( documentAnalyzer, document, kind, _compilationWithAnalyzers?.Compilation, cancellationToken).ConfigureAwait(false); @@ -127,7 +123,7 @@ public async Task> ComputeDiagnosticsAsync(Diagnosti (r, d, a, k) => $"Driver: {r != null}, {d.Id}, {d.Project.Id}, {a}, {k}", _compilationWithAnalyzers, textDocument, analyzer, kind); } - return SpecializedCollections.EmptyEnumerable(); + return []; } // if project is not loaded successfully then, we disable semantic errors for compiler analyzers @@ -139,16 +135,12 @@ public async Task> ComputeDiagnosticsAsync(Diagnosti Logger.Log(FunctionId.Diagnostics_SemanticDiagnostic, (a, d, e) => $"{a}, ({d.Id}, {d.Project.Id}), Enabled:{e}", analyzer, textDocument, isEnabled); if (!isEnabled) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; } + // We currently support document analysis only for source documents and additional documents. if (document == null && textDocument is not AdditionalDocument) - { - // We currently support document analysis only for source documents and additional documents. - return SpecializedCollections.EmptyEnumerable(); - } + return []; var diagnostics = kind switch { diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs index 851898e113e0c..1d14029d88371 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs @@ -41,18 +41,14 @@ public IEnumerable GetProjectsWithDiagnostics() { // quick bail out if (_activeFileStates.IsEmpty && _projectStates.IsEmpty) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; if (_activeFileStates.Count == 1 && _projectStates.IsEmpty) { // see whether we actually have diagnostics var (documentId, state) = _activeFileStates.First(); if (state.IsEmpty) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; // we do have diagnostics return SpecializedCollections.SingletonEnumerable(documentId.ProjectId); diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs index 7bf0a3fbb7bf0..e90818da57dd1 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs @@ -246,7 +246,7 @@ public async Task> GetProjectDiagnosticsAsync(Can var project = Solution.GetProject(ProjectId); if (project != null) { - await AppendDiagnosticsAsync(project, SpecializedCollections.EmptyEnumerable(), includeProjectNonLocalResult: true, cancellationToken).ConfigureAwait(false); + await AppendDiagnosticsAsync(project, documentIds: [], includeProjectNonLocalResult: true, cancellationToken).ConfigureAwait(false); } return GetDiagnosticData(); diff --git a/src/VisualStudio/Core/Def/Progression/SymbolContainment.cs b/src/VisualStudio/Core/Def/Progression/SymbolContainment.cs index a94b1d6503d2f..87dab244f14ca 100644 --- a/src/VisualStudio/Core/Def/Progression/SymbolContainment.cs +++ b/src/VisualStudio/Core/Def/Progression/SymbolContainment.cs @@ -26,9 +26,7 @@ public static async Task> GetContainedSyntaxNodesAsync(D { var progressionLanguageService = document.GetLanguageService(); if (progressionLanguageService == null) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var root = await syntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/VisualStudio/Core/Def/ProjectSystem/VisualStudioWorkspaceImpl.cs b/src/VisualStudio/Core/Def/ProjectSystem/VisualStudioWorkspaceImpl.cs index 051a66a017377..554f0864b6dec 100644 --- a/src/VisualStudio/Core/Def/ProjectSystem/VisualStudioWorkspaceImpl.cs +++ b/src/VisualStudio/Core/Def/ProjectSystem/VisualStudioWorkspaceImpl.cs @@ -838,9 +838,7 @@ private static IEnumerable FilterFolderForProjectType(EnvDTE.Project pro private static IEnumerable GetAllItems(ProjectItems projectItems) { if (projectItems == null) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var items = projectItems.OfType(); return items.Concat(items.SelectMany(i => GetAllItems(i.ProjectItems))); diff --git a/src/VisualStudio/Core/Def/Venus/ContainedDocument.cs b/src/VisualStudio/Core/Def/Venus/ContainedDocument.cs index a0475d1e3e760..5dbb5103ff05b 100644 --- a/src/VisualStudio/Core/Def/Venus/ContainedDocument.cs +++ b/src/VisualStudio/Core/Def/Venus/ContainedDocument.cs @@ -714,7 +714,7 @@ public IEnumerable GetEditorVisibleSpans() } else { - return SpecializedCollections.EmptyEnumerable(); + return []; } } diff --git a/src/VisualStudio/Core/Impl/SolutionExplorer/BaseItem.cs b/src/VisualStudio/Core/Impl/SolutionExplorer/BaseItem.cs index 1700f46c598b1..27d1a9fe951ac 100644 --- a/src/VisualStudio/Core/Impl/SolutionExplorer/BaseItem.cs +++ b/src/VisualStudio/Core/Impl/SolutionExplorer/BaseItem.cs @@ -42,7 +42,7 @@ public BaseItem(string name) _name = name; } - public IEnumerable Children => SpecializedCollections.EmptyEnumerable(); + public IEnumerable Children => []; public bool IsExpandable => true; diff --git a/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs b/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs index 9f99d822e1cd4..7cd3340877e74 100644 --- a/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs +++ b/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs @@ -462,14 +462,10 @@ public override SyntaxNode IndexerDeclaration( else { if (getAccessorStatements == null && hasGetter) - { - getAccessorStatements = SpecializedCollections.EmptyEnumerable(); - } + getAccessorStatements = []; if (setAccessorStatements == null && hasSetter) - { - setAccessorStatements = SpecializedCollections.EmptyEnumerable(); - } + setAccessorStatements = []; } if (hasGetter) @@ -545,8 +541,8 @@ public override SyntaxNode CustomEventDeclaration( } else { - addAccessorStatements ??= SpecializedCollections.EmptyEnumerable(); - removeAccessorStatements ??= SpecializedCollections.EmptyEnumerable(); + addAccessorStatements ??= []; + removeAccessorStatements ??= []; } accessors.Add(AccessorDeclaration(SyntaxKind.AddAccessorDeclaration, addAccessorStatements)); diff --git a/src/Workspaces/CSharp/Portable/Formatting/CSharpSyntaxFormattingService.cs b/src/Workspaces/CSharp/Portable/Formatting/CSharpSyntaxFormattingService.cs index 03f17834b4e67..8d1e1979279e4 100644 --- a/src/Workspaces/CSharp/Portable/Formatting/CSharpSyntaxFormattingService.cs +++ b/src/Workspaces/CSharp/Portable/Formatting/CSharpSyntaxFormattingService.cs @@ -279,7 +279,7 @@ private static IEnumerable GetTypingRules(SyntaxToken to if (tokenBeforeCaret.Kind() is SyntaxKind.CloseBraceToken or SyntaxKind.EndOfFileToken) { - return SpecializedCollections.EmptyEnumerable(); + return []; } return SpecializedCollections.SingletonEnumerable(TypingFormattingRule.Instance); diff --git a/src/Workspaces/Core/Portable/CodeActions/CodeActionWithOptions.cs b/src/Workspaces/Core/Portable/CodeActions/CodeActionWithOptions.cs index e93f95524ee93..5914b7fbd7a7b 100644 --- a/src/Workspaces/Core/Portable/CodeActions/CodeActionWithOptions.cs +++ b/src/Workspaces/Core/Portable/CodeActions/CodeActionWithOptions.cs @@ -38,9 +38,7 @@ public abstract class CodeActionWithOptions : CodeAction Solution originalSolution, object? options, IProgress progress, CancellationToken cancellationToken) { if (options == null) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var operations = await this.ComputeOperationsAsync(options, progress, cancellationToken).ConfigureAwait(false); diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Hierarchy.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Hierarchy.cs index 1e2473a314f0c..7bfe7ed73548e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Hierarchy.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Hierarchy.cs @@ -133,7 +133,7 @@ internal static async Task> FindImplementedInterfaceMemb var containingType = symbol.ContainingType.OriginalDefinition; var derivedClasses = includeImplementationsThroughDerivedTypes ? await FindDerivedClassesAsync(containingType, solution, projects, cancellationToken).ConfigureAwait(false) - : SpecializedCollections.EmptyEnumerable(); + : []; var allTypes = derivedClasses.Concat(containingType); using var _ = ArrayBuilder.GetInstance(out var builder); diff --git a/src/Workspaces/Core/Portable/Rename/ConflictEngine/MutableConflictResolution.cs b/src/Workspaces/Core/Portable/Rename/ConflictEngine/MutableConflictResolution.cs index 39cc3f28a0792..61ccd36af02b5 100644 --- a/src/Workspaces/Core/Portable/Rename/ConflictEngine/MutableConflictResolution.cs +++ b/src/Workspaces/Core/Portable/Rename/ConflictEngine/MutableConflictResolution.cs @@ -80,7 +80,7 @@ internal async Task RemoveAllRenameAnnotationsAsync( computeReplacementNode: (original, updated) => annotationSet.WithoutAnnotations(updated, annotationSet.GetAnnotations(updated).ToArray()), tokens: annotationSet.GetAnnotatedTokens(root), computeReplacementToken: (original, updated) => annotationSet.WithoutAnnotations(updated, annotationSet.GetAnnotations(updated).ToArray()), - trivia: SpecializedCollections.EmptyEnumerable(), + trivia: [], computeReplacementTrivia: null); intermediateSolution = intermediateSolution.WithDocumentSyntaxRoot(documentId, newRoot, PreservationMode.PreserveIdentity); diff --git a/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs b/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs index dbaa6671a11e1..6c6546e908b97 100644 --- a/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs +++ b/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs @@ -55,7 +55,7 @@ internal int GetAdjustedPosition(int startingPosition, DocumentId documentId) { var documentReplacementSpans = _documentToModifiedSpansMap.TryGetValue(documentId, out var modifiedSpans) ? modifiedSpans.Where(pair => pair.oldSpan.Start < startingPosition) - : SpecializedCollections.EmptyEnumerable<(TextSpan oldSpan, TextSpan newSpan)>(); + : []; var adjustedStartingPosition = startingPosition; foreach (var (oldSpan, newSpan) in documentReplacementSpans) @@ -65,7 +65,7 @@ internal int GetAdjustedPosition(int startingPosition, DocumentId documentId) var documentComplexifiedSpans = _documentToComplexifiedSpansMap.TryGetValue(documentId, out var complexifiedSpans) ? complexifiedSpans.Where(c => c.OriginalSpan.Start <= startingPosition) - : SpecializedCollections.EmptyEnumerable(); + : []; var appliedTextSpans = new HashSet(); foreach (var c in documentComplexifiedSpans.Reverse()) diff --git a/src/Workspaces/Core/Portable/Rename/SymbolicRenameLocations.ReferenceProcessing.cs b/src/Workspaces/Core/Portable/Rename/SymbolicRenameLocations.ReferenceProcessing.cs index 85a3daef15c1e..120c21c7ec2ae 100644 --- a/src/Workspaces/Core/Portable/Rename/SymbolicRenameLocations.ReferenceProcessing.cs +++ b/src/Workspaces/Core/Portable/Rename/SymbolicRenameLocations.ReferenceProcessing.cs @@ -235,22 +235,16 @@ internal static async Task> GetRenamableReferenceLoc // We won't try to update references in source generated files; we'll assume the generator will rerun // and produce an updated document with the new name. if (location.Document is SourceGeneratedDocument) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var shouldIncludeSymbol = await ShouldIncludeSymbolAsync(referencedSymbol, originalSymbol, solution, true, cancellationToken).ConfigureAwait(false); if (!shouldIncludeSymbol) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; // Implicit references are things like a foreach referencing GetEnumerator. We don't // want to consider those as part of the set if (location.IsImplicit) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var results = new List(); diff --git a/src/Workspaces/Core/Portable/Rename/TokenRenameInfo.cs b/src/Workspaces/Core/Portable/Rename/TokenRenameInfo.cs index 79385ad17a122..8c3a375c9f1fc 100644 --- a/src/Workspaces/Core/Portable/Rename/TokenRenameInfo.cs +++ b/src/Workspaces/Core/Portable/Rename/TokenRenameInfo.cs @@ -37,6 +37,6 @@ public static TokenRenameInfo CreateSingleSymbolTokenInfo(ISymbol symbol) ( hasSymbols: false, isMemberGroup: false, - symbols: SpecializedCollections.EmptyEnumerable() + symbols: [] ); } diff --git a/src/Workspaces/Core/Portable/Serialization/AbstractOptionsSerializationService.cs b/src/Workspaces/Core/Portable/Serialization/AbstractOptionsSerializationService.cs index 3a296dba72ee3..ef1ff19c1258e 100644 --- a/src/Workspaces/Core/Portable/Serialization/AbstractOptionsSerializationService.cs +++ b/src/Workspaces/Core/Portable/Serialization/AbstractOptionsSerializationService.cs @@ -146,7 +146,7 @@ protected static ( } } - var specificDiagnosticOptions = specificDiagnosticOptionsList ?? SpecializedCollections.EmptyEnumerable>(); + var specificDiagnosticOptions = specificDiagnosticOptionsList ?? []; var concurrentBuild = reader.ReadBoolean(); var deterministic = reader.ReadBoolean(); @@ -232,7 +232,7 @@ protected static (SourceCodeKind kind, DocumentationMode documentationMode, IEnu } } - var features = featuresList ?? SpecializedCollections.EmptyEnumerable>(); + var features = featuresList ?? []; return (kind, documentationMode, features); } } diff --git a/src/Workspaces/Core/Portable/Shared/Collections/IntervalTree.cs b/src/Workspaces/Core/Portable/Shared/Collections/IntervalTree.cs index 0d8a268537a47..a2de671e3cfd8 100644 --- a/src/Workspaces/Core/Portable/Shared/Collections/IntervalTree.cs +++ b/src/Workspaces/Core/Portable/Shared/Collections/IntervalTree.cs @@ -20,6 +20,6 @@ public static IntervalTree Create(in TIntrospector introspe public static IntervalTree Create(in TIntrospector introspector, IEnumerable values = null) where TIntrospector : struct, IIntervalIntrospector { - return IntervalTree.Create(in introspector, values ?? SpecializedCollections.EmptyEnumerable()); + return IntervalTree.Create(in introspector, values ?? []); } } diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/ILanguageServiceProviderExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/ILanguageServiceProviderExtensions.cs index 4c237281e18ea..855a5ac6f7c24 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/ILanguageServiceProviderExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/ILanguageServiceProviderExtensions.cs @@ -19,9 +19,7 @@ public static IEnumerable> SelectMatchingExtensions>(); - } + return []; return items.Where(lazy => lazy.Metadata.Language == serviceProvider.Language); } diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs index 5ee5302342f19..bdb16d4351df7 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs @@ -91,7 +91,7 @@ private static bool ShouldGenerateThisConstructorCall( .OfType() .Where(field => !field.IsStatic) .Select(field => field.AssociatedSymbol ?? field) - .Except(parameterToExistingFieldMap?.Values ?? SpecializedCollections.EmptyEnumerable()) + .Except(parameterToExistingFieldMap?.Values ?? []) .Any(); } diff --git a/src/Workspaces/Core/Portable/Simplification/AbstractSimplificationService.cs b/src/Workspaces/Core/Portable/Simplification/AbstractSimplificationService.cs index 5e03b565846ba..3a3bf94dfb4a5 100644 --- a/src/Workspaces/Core/Portable/Simplification/AbstractSimplificationService.cs +++ b/src/Workspaces/Core/Portable/Simplification/AbstractSimplificationService.cs @@ -152,7 +152,7 @@ bool isNodeOrTokenOutsideSimplifySpans(SyntaxNodeOrToken nodeOrToken) computeReplacementNode: (o, n) => TransformReducedNode(reducedNodesMap[o], n), tokens: reducedTokensMap.Keys, computeReplacementToken: (o, n) => reducedTokensMap[o], - trivia: SpecializedCollections.EmptyEnumerable(), + trivia: [], computeReplacementTrivia: null); document = document.WithSyntaxRoot(root); diff --git a/src/Workspaces/Core/Portable/Workspace/Host/HostWorkspaceServices.cs b/src/Workspaces/Core/Portable/Workspace/Host/HostWorkspaceServices.cs index 8e104f78ef3c4..ee33932aaf196 100644 --- a/src/Workspaces/Core/Portable/Workspace/Host/HostWorkspaceServices.cs +++ b/src/Workspaces/Core/Portable/Workspace/Host/HostWorkspaceServices.cs @@ -87,10 +87,7 @@ internal virtual ITextFactoryService TextFactory /// /// A list of language names for supported language services. /// - public virtual IEnumerable SupportedLanguages - { - get { return SpecializedCollections.EmptyEnumerable(); } - } + public virtual IEnumerable SupportedLanguages => []; /// /// Returns true if the language is supported. diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/Document.cs b/src/Workspaces/Core/Portable/Workspace/Solution/Document.cs index 43f4eca13e51e..7f2bffd0dd681 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/Document.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/Document.cs @@ -433,11 +433,9 @@ public async Task> GetTextChangesAsync(Document oldDocum { using (Logger.LogBlock(FunctionId.Workspace_Document_GetTextChanges, this.Name, cancellationToken)) { + // no changes if (oldDocument == this) - { - // no changes - return SpecializedCollections.EmptyEnumerable(); - } + return []; if (this.Id != oldDocument.Id) { @@ -448,9 +446,7 @@ public async Task> GetTextChangesAsync(Document oldDocum if (this.TryGetText(out var text) && oldDocument.TryGetText(out var oldText)) { if (text == oldText) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var container = text.Container; if (container != null) diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/TextDocumentStates.cs b/src/Workspaces/Core/Portable/Workspace/Solution/TextDocumentStates.cs index 4dea1bb700f59..535371c95a56a 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/TextDocumentStates.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/TextDocumentStates.cs @@ -237,13 +237,13 @@ public IEnumerable GetChangedStateIds(TextDocumentStates old /// Returns a s of added documents. /// public IEnumerable GetAddedStateIds(TextDocumentStates oldStates) - => (_ids == oldStates._ids) ? SpecializedCollections.EmptyEnumerable() : Except(_ids, oldStates._map); + => (_ids == oldStates._ids) ? [] : Except(_ids, oldStates._map); /// /// Returns a s of removed documents. /// public IEnumerable GetRemovedStateIds(TextDocumentStates oldStates) - => (_ids == oldStates._ids) ? SpecializedCollections.EmptyEnumerable() : Except(oldStates._ids, _map); + => (_ids == oldStates._ids) ? [] : Except(oldStates._ids, _map); private static IEnumerable Except(ImmutableList ids, ImmutableSortedDictionary map) { diff --git a/src/Workspaces/Core/Portable/Workspace/Workspace_Editor.cs b/src/Workspaces/Core/Portable/Workspace/Workspace_Editor.cs index b03867cd15a55..f59a4743aa37c 100644 --- a/src/Workspaces/Core/Portable/Workspace/Workspace_Editor.cs +++ b/src/Workspaces/Core/Portable/Workspace/Workspace_Editor.cs @@ -195,9 +195,7 @@ public virtual IEnumerable GetOpenDocumentIds(ProjectId? projectId = using (_stateLock.DisposableWait()) { if (_projectToOpenDocumentsMap.Count == 0) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; if (projectId != null) { @@ -206,7 +204,7 @@ public virtual IEnumerable GetOpenDocumentIds(ProjectId? projectId = return documentIds; } - return SpecializedCollections.EmptyEnumerable(); + return []; } return _projectToOpenDocumentsMap.SelectManyAsArray(kvp => kvp.Value); diff --git a/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs b/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs index b1f4c93237371..dcbe3accfd542 100644 --- a/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs +++ b/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs @@ -270,7 +270,7 @@ private async Task UpdateProjectsAsync( if (oldProjectIdToStateChecksums.TryGetValue(projectId, out var oldProjectChecksums) && oldProjectChecksums.ProjectReferences.Checksum != newProjectChecksums.ProjectReferences.Checksum) { - solution = solution.WithProjectReferences(projectId, SpecializedCollections.EmptyEnumerable()); + solution = solution.WithProjectReferences(projectId, projectReferences: []); } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SemanticModelExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SemanticModelExtensions.cs index 3802c800a2d9e..43c0af76af764 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SemanticModelExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SemanticModelExtensions.cs @@ -33,7 +33,7 @@ public static IEnumerable LookupTypeRegardlessOfArity( } } - return SpecializedCollections.EmptyEnumerable(); + return []; } public static ImmutableArray LookupName( diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs index 64ab289e859a3..59c702c08cac1 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs @@ -764,7 +764,7 @@ public static IEnumerable GetMembers(this SyntaxNode? n BaseNamespaceDeclarationSyntax @namespace => @namespace.Members, TypeDeclarationSyntax type => type.Members, EnumDeclarationSyntax @enum => @enum.Members, - _ => SpecializedCollections.EmptyEnumerable(), + _ => [], }; public static bool IsInExpressionTree( diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs index 792289b5df9da..47ca8fdd13dd0 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs @@ -1071,9 +1071,7 @@ private static TextSpan GetBlockBodySpan(BlockSyntax body) public IEnumerable GetConstructors(SyntaxNode? root, CancellationToken cancellationToken) { if (root is not CompilationUnitSyntax compilationUnit) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var constructors = new List(); AppendConstructors(compilationUnit.Members, constructors, cancellationToken); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/StructuredAnalyzerConfigOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/StructuredAnalyzerConfigOptions.cs index 76b0896a974b6..359c76a42da31 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/StructuredAnalyzerConfigOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Diagnostics/StructuredAnalyzerConfigOptions.cs @@ -53,7 +53,7 @@ public override bool TryGetValue(string key, [NotNullWhen(true)] out string? val } public override IEnumerable Keys - => SpecializedCollections.EmptyEnumerable(); + => []; } public static readonly StructuredAnalyzerConfigOptions Empty = new EmptyImplementation(); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/INamedTypeSymbolExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/INamedTypeSymbolExtensions.cs index 90d81d94307b5..e1509de06a403 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/INamedTypeSymbolExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/INamedTypeSymbolExtensions.cs @@ -388,7 +388,7 @@ private static ImmutableArray GetInterfacesToImplement( // implement. By definition they must contain all the necessary methods. var baseType = classOrStructType.BaseType; var alreadyImplementedInterfaces = baseType == null || allowReimplementation - ? SpecializedCollections.EmptyEnumerable() + ? [] : baseType.AllInterfaces; cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/INamespaceOrTypeSymbolExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/INamespaceOrTypeSymbolExtensions.cs index fdb6279f5eafe..e01bab1198830 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/INamespaceOrTypeSymbolExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/INamespaceOrTypeSymbolExtensions.cs @@ -24,7 +24,7 @@ public static string GetShortName(this INamespaceOrTypeSymbol symbol) public static IEnumerable GetIndexers(this INamespaceOrTypeSymbol? symbol) { return symbol == null - ? SpecializedCollections.EmptyEnumerable() + ? [] : symbol.GetMembers(WellKnownMemberNames.Indexer).OfType().Where(p => p.IsIndexer); } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ITypeSymbolExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ITypeSymbolExtensions.cs index 65bc4bcc48912..8732bd70f0b9c 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ITypeSymbolExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ITypeSymbolExtensions.cs @@ -434,9 +434,7 @@ public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, public static IEnumerable GetAccessibleMembersInBaseTypes(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol { if (containingType == null) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var types = containingType.GetBaseTypes(); return types.SelectMany(x => x.GetMembers().OfType().Where(m => m.IsAccessibleWithin(within))); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenExtensions.cs index 976a89f97a2f7..3452fa0214efe 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxTokenExtensions.cs @@ -26,14 +26,14 @@ public static IEnumerable GetAncestors(this SyntaxToken token) { return token.Parent != null ? token.Parent.AncestorsAndSelf().OfType() - : SpecializedCollections.EmptyEnumerable(); + : []; } public static IEnumerable GetAncestors(this SyntaxToken token, Func predicate) { return token.Parent != null ? token.Parent.AncestorsAndSelf().Where(predicate) - : SpecializedCollections.EmptyEnumerable(); + : []; } public static SyntaxNode? GetCommonRoot(this SyntaxToken token1, SyntaxToken token2) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IReadOnlyDictionaryExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IReadOnlyDictionaryExtensions.cs index 1df6973fea720..a00213fe05cc4 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IReadOnlyDictionaryExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IReadOnlyDictionaryExtensions.cs @@ -25,7 +25,7 @@ public static IEnumerable GetEnumerableMetadata(this IReadOnlyDictionary enumerable: return enumerable; case T s: return SpecializedCollections.SingletonEnumerable(s); - default: return SpecializedCollections.EmptyEnumerable(); + default: return []; } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/TypeDeclarationSyntaxExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/TypeDeclarationSyntaxExtensions.cs index bb9d23cfe0db2..419f016a12019 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/TypeDeclarationSyntaxExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/TypeDeclarationSyntaxExtensions.cs @@ -92,7 +92,7 @@ public static IEnumerable GetAllBaseListTypes(this TypeDeclarati if (typeNode.BaseList != null) return typeNode.BaseList.Types; - return SpecializedCollections.EmptyEnumerable(); + return []; } private static SyntaxToken EnsureToken(SyntaxToken token, SyntaxKind kind, bool prependNewLineIfMissing = false, bool appendNewLineIfMissing = false) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs index 6fb25a485e677..d9327ee6b5fe4 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs @@ -87,7 +87,7 @@ private IEnumerable GetTypesComplex(SyntaxNode node) } // TODO(cyrusn): More cases if necessary. - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable GetTypesSimple(SyntaxNode node) @@ -120,7 +120,7 @@ private IEnumerable GetTypesSimple(SyntaxNode node) } } - return SpecializedCollections.EmptyEnumerable(); + return []; } protected override IEnumerable InferTypesWorker_DoNotCallDirectly( @@ -185,7 +185,7 @@ protected override IEnumerable InferTypesWorker_DoNotCallDire WhenClauseSyntax whenClause => InferTypeInWhenClause(whenClause), WhileStatementSyntax whileStatement => InferTypeInWhileStatement(whileStatement), YieldStatementSyntax yieldStatement => InferTypeInYieldStatement(yieldStatement), - _ => SpecializedCollections.EmptyEnumerable(), + _ => [], }; } @@ -252,7 +252,7 @@ protected override IEnumerable InferTypesWorker_DoNotCallDire WhenClauseSyntax whenClause => InferTypeInWhenClause(whenClause, token), WhileStatementSyntax whileStatement => InferTypeInWhileStatement(whileStatement, token), YieldStatementSyntax yieldStatement => InferTypeInYieldStatement(yieldStatement, token), - _ => SpecializedCollections.EmptyEnumerable(), + _ => [], }; } @@ -263,7 +263,7 @@ private IEnumerable InferTypeInAnonymousObjectCreation(Anonym return InferTypes(expression.SpanStart); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInArgument( @@ -273,9 +273,7 @@ private IEnumerable InferTypeInArgument( { // If we have a position, then it must be after the colon in a named argument. if (argument.NameColon == null || argument.NameColon.ColonToken != previousToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; } if (argument.Parent != null) @@ -334,7 +332,7 @@ private IEnumerable InferTypeInArgument( } } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInTupleExpression( @@ -350,7 +348,7 @@ private IEnumerable InferTypeInTupleExpression( return InferTypeInTupleExpression(tupleExpression, (ArgumentSyntax)argsAndCommas[commaIndex + 1]); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInTupleExpression( @@ -371,9 +369,7 @@ private IEnumerable InferTypeInAttributeArgument(AttributeArg { // If we have a position, then it must be after the colon or equals in an argument. if (argument.NameColon == null || argument.NameColon.ColonToken != previousToken || argument.NameEquals.EqualsToken != previousToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; } if (argument.Parent != null) @@ -385,7 +381,7 @@ private IEnumerable InferTypeInAttributeArgument(AttributeArg } } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInConstructorInitializer(ConstructorInitializerSyntax initializer, int index, ArgumentSyntax argument = null) @@ -440,9 +436,7 @@ private IEnumerable InferTypeInObjectCreationExpression(BaseO var info = SemanticModel.GetTypeInfo(creation, CancellationToken); if (info.Type is not INamedTypeSymbol type) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; if (type.TypeKind == TypeKind.Delegate) { @@ -504,9 +498,7 @@ private IEnumerable InferTypeInArgumentList(ArgumentListSynta { // Has to follow the ( or a , if (previousToken != argumentList.OpenParenToken && previousToken.Kind() != SyntaxKind.CommaToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; switch (argumentList.Parent) { @@ -529,16 +521,14 @@ private IEnumerable InferTypeInArgumentList(ArgumentListSynta } } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInAttributeArgumentList(AttributeArgumentListSyntax attributeArgumentList, SyntaxToken previousToken) { // Has to follow the ( or a , if (previousToken != attributeArgumentList.OpenParenToken && previousToken.Kind() != SyntaxKind.CommaToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; if (attributeArgumentList.Parent is AttributeSyntax attribute) { @@ -546,7 +536,7 @@ private IEnumerable InferTypeInAttributeArgumentList(Attribut return InferTypeInAttribute(attribute, index); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInAttribute(AttributeSyntax attribute, int index, AttributeArgumentSyntax argumentOpt = null) @@ -808,7 +798,7 @@ private IEnumerable InferTypeInArrayCreationExpression( if (previousToken.HasValue && previousToken.Value != arrayCreationExpression.NewKeyword) { // Has to follow the 'new' keyword. - return SpecializedCollections.EmptyEnumerable(); + return []; } if (previousToken.HasValue && previousToken.Value.GetPreviousToken().Kind() == SyntaxKind.EqualsToken) @@ -835,9 +825,7 @@ private IEnumerable InferTypeInArrayRankSpecifier(ArrayRankSp // If we have a token, and it's not the open bracket or one of the commas, then no // inference. if (previousToken == arrayRankSpecifier.CloseBracketToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(this.Compilation.GetSpecialType(SpecialType.System_Int32)); } @@ -847,7 +835,7 @@ private IEnumerable InferTypeInArrayType(ArrayTypeSyntax arra if (previousToken.HasValue) { // TODO(cyrusn): NYI. Handle this appropriately if we need to. - return SpecializedCollections.EmptyEnumerable(); + return []; } // Bind the array type, then unwrap whatever we get back based on the number of rank @@ -869,9 +857,7 @@ private IEnumerable InferTypeInAttributeDeclaration(Attribute { // If we have a position, then it has to be after the open bracket. if (previousToken.HasValue && previousToken.Value != attributeDeclaration.OpenBracketToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(this.Compilation.AttributeType()); } @@ -882,9 +868,7 @@ private IEnumerable InferTypeInAttributeTargetSpecifier( { // If we have a position, then it has to be after the colon. if (previousToken.HasValue && previousToken.Value != attributeTargetSpecifier.ColonToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(this.Compilation.AttributeType()); } @@ -893,9 +877,7 @@ private IEnumerable InferTypeInBracketedArgumentList(Brackete { // Has to follow the [ or a , if (previousToken != bracketedArgumentList.OpenBracketToken && previousToken.Kind() != SyntaxKind.CommaToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; if (bracketedArgumentList.Parent is ElementAccessExpressionSyntax elementAccess) { @@ -904,7 +886,7 @@ private IEnumerable InferTypeInBracketedArgumentList(Brackete elementAccess, index); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private static int GetArgumentListIndex(BaseArgumentListSyntax argumentList, SyntaxToken previousToken) @@ -1077,21 +1059,17 @@ SyntaxKind.CaretToken or return CreateResult(SpecialType.System_Boolean); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInCastExpression(CastExpressionSyntax castExpression, ExpressionSyntax expressionOpt = null, SyntaxToken? previousToken = null) { if (expressionOpt != null && castExpression.Expression != expressionOpt) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; // If we have a position, then it has to be after the close paren. if (previousToken.HasValue && previousToken.Value != castExpression.CloseParenToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return this.GetTypes(castExpression.Type); } @@ -1100,9 +1078,7 @@ private IEnumerable InferTypeInCatchDeclaration(CatchDeclarat { // If we have a position, it has to be after "catch(" if (previousToken.HasValue && previousToken.Value != catchDeclaration.OpenParenToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(this.Compilation.ExceptionType()); } @@ -1111,9 +1087,7 @@ private IEnumerable InferTypeInCatchFilterClause(CatchFilterC { // If we have a position, it has to be after "if (" if (previousToken.HasValue && previousToken.Value != catchFilterClause.OpenParenToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(SpecialType.System_Boolean); } @@ -1198,7 +1172,7 @@ private IEnumerable InferTypeInConditionalExpression(Conditio ? GetTypes(conditional.WhenFalse) : inFalseClause ? GetTypes(conditional.WhenTrue) - : SpecializedCollections.EmptyEnumerable(); + : []; return otherTypes.IsEmpty() ? InferTypes(conditional) @@ -1212,9 +1186,7 @@ private IEnumerable InferTypeInDoStatement(DoStatementSyntax { // If we have a position, we need to be after "do { } while(" if (previousToken.HasValue && previousToken.Value != doStatement.OpenParenToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(SpecialType.System_Boolean); } @@ -1223,7 +1195,7 @@ private IEnumerable InferTypeInEqualsValueClause(EqualsValueC { // If we have a position, it has to be after the = if (previousToken.HasValue && previousToken.Value != equalsValue.EqualsToken) - return SpecializedCollections.EmptyEnumerable(); + return []; if (equalsValue?.Parent is VariableDeclaratorSyntax varDecl) return InferTypeInVariableDeclarator(varDecl); @@ -1237,7 +1209,7 @@ private IEnumerable InferTypeInEqualsValueClause(EqualsValueC return CreateResult(parameter.Type); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInPropertyDeclaration(PropertyDeclarationSyntax propertyDeclaration) @@ -1253,9 +1225,7 @@ private IEnumerable InferTypeInExpressionStatement(SyntaxToke // If we're position based, then that means we're after the semicolon. In this case // we don't have any sort of type to infer. if (previousToken.HasValue) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(SpecialType.System_Void); } @@ -1264,14 +1234,10 @@ private IEnumerable InferTypeInForEachStatement(ForEachStatem { // If we have a position, then we have to be after "foreach(... in" if (previousToken.HasValue && previousToken.Value != forEachStatementSyntax.InKeyword) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; if (expressionOpt != null && expressionOpt != forEachStatementSyntax.Expression) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var enumerableType = forEachStatementSyntax.AwaitKeyword == default ? this.Compilation.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T) @@ -1295,14 +1261,10 @@ private IEnumerable InferTypeInForStatement(ForStatementSynta { // If we have a position, it has to be after "for(...;" if (previousToken.HasValue && previousToken.Value != forStatement.FirstSemicolonToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; if (expressionOpt != null && forStatement.Condition != expressionOpt) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(SpecialType.System_Boolean); } @@ -1311,9 +1273,7 @@ private IEnumerable InferTypeInIfStatement(IfStatementSyntax { // If we have a position, we have to be after the "if(" if (previousToken.HasValue && previousToken.Value != ifStatement.OpenParenToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(SpecialType.System_Boolean); } @@ -1466,7 +1426,7 @@ private IEnumerable InferTypeInInitializerExpression( } } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInRecursivePattern(RecursivePatternSyntax recursivePattern) @@ -1515,7 +1475,7 @@ private IEnumerable InferTypeInSubpattern( return result.ToImmutableAndClear(); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeForSingleVariableDesignation(SingleVariableDesignationSyntax singleVariableDesignation) @@ -1534,7 +1494,7 @@ private IEnumerable InferTypeForSingleVariableDesignation(Sin } } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInIsPatternExpression( @@ -1550,7 +1510,7 @@ private IEnumerable InferTypeInIsPatternExpression( return GetTypes(isPatternExpression.Expression); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable GetPatternTypes(PatternSyntax pattern) @@ -1567,7 +1527,7 @@ _ when SemanticModel.GetOperation(pattern, CancellationToken) is IPatternOperati CreateResult(patternOperation.NarrowedType.IsErrorType() ? patternOperation.InputType : patternOperation.NarrowedType), - _ => SpecializedCollections.EmptyEnumerable() + _ => [], }; } @@ -1599,9 +1559,7 @@ private IEnumerable GetTypesForRecursivePattern(RecursivePatt var patternType = GetPatternTypes(subPattern.Pattern).FirstOrDefault(); if (patternType.InferredType == null) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; elementTypesBuilder.Add(patternType.InferredType); } @@ -1614,7 +1572,7 @@ private IEnumerable GetTypesForRecursivePattern(RecursivePatt } } - return SpecializedCollections.EmptyEnumerable(); + return []; } private static ImmutableArray GetNullableAnnotations(ImmutableArray elementTypes) @@ -1624,9 +1582,7 @@ private IEnumerable InferTypeInLockStatement(LockStatementSyn { // If we're position based, then we have to be after the "lock(" if (previousToken.HasValue && previousToken.Value != lockStatement.OpenParenToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(SpecialType.System_Object); } @@ -1635,9 +1591,7 @@ private IEnumerable InferTypeInLambdaExpression(LambdaExpress { // If we have a position, it has to be after the lambda arrow. if (previousToken.HasValue && previousToken.Value != lambdaExpression.ArrowToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return InferTypeInAnonymousFunctionExpression(lambdaExpression); } @@ -1660,7 +1614,7 @@ private IEnumerable InferTypeInAnonymousFunctionExpression(An } } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInMemberDeclarator(AnonymousObjectMemberDeclaratorSyntax memberDeclarator, SyntaxToken? previousTokenOpt = null) @@ -1669,9 +1623,7 @@ private IEnumerable InferTypeInMemberDeclarator(AnonymousObje { // If we're position based, then we have to be after the = if (previousTokenOpt.HasValue && previousTokenOpt.Value != memberDeclarator.NameEquals.EqualsToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var types = InferTypes((AnonymousObjectCreationExpressionSyntax)memberDeclarator.Parent); @@ -1681,7 +1633,7 @@ private IEnumerable InferTypeInMemberDeclarator(AnonymousObje .Select(p => new TypeInferenceInfo(p.Type))); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInNameColon(NameColonSyntax nameColon, SyntaxToken previousToken) @@ -1689,14 +1641,14 @@ private IEnumerable InferTypeInNameColon(NameColonSyntax name if (previousToken != nameColon.ColonToken) { // Must follow the colon token. - return SpecializedCollections.EmptyEnumerable(); + return []; } return nameColon.Parent switch { ArgumentSyntax argumentSyntax => InferTypeInArgument(argumentSyntax), SubpatternSyntax subPattern => InferTypeInSubpattern(subPattern, subPattern.Pattern), - _ => SpecializedCollections.EmptyEnumerable() + _ => [], }; } @@ -1705,13 +1657,13 @@ private IEnumerable InferTypeInExpressionColon(ExpressionColo if (previousToken != expressionColon.ColonToken) { // Must follow the colon token. - return SpecializedCollections.EmptyEnumerable(); + return []; } return expressionColon.Parent switch { SubpatternSyntax subPattern => InferTypeInSubpattern(subPattern, subPattern.Pattern), - _ => SpecializedCollections.EmptyEnumerable() + _ => [], }; } @@ -1728,9 +1680,7 @@ private IEnumerable InferTypeInMemberAccessExpression( if (previousToken != null) { if (previousToken.Value != memberAccessExpression.OperatorToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; // We're right after the dot in "Goo.Bar". The type for "Bar" should be // whatever type we'd infer for "Goo.Bar" itself. @@ -1812,7 +1762,7 @@ private IEnumerable InferTypeForExpressionOfMemberAccessExpre } } - return SpecializedCollections.EmptyEnumerable(); + return []; } private ITypeSymbol InferTypeForFirstParameterOfLambda( @@ -1890,7 +1840,7 @@ private IEnumerable InferTypeInNameColon(NameColonSyntax name return GetPatternTypes(subpattern.Pattern); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInExpressionColon(ExpressionColonSyntax expressionColon) @@ -1900,7 +1850,7 @@ private IEnumerable InferTypeInExpressionColon(ExpressionColo return GetPatternTypes(subpattern.Pattern); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInNameEquals(NameEqualsSyntax nameEquals, SyntaxToken? previousToken = null) @@ -1918,16 +1868,14 @@ private IEnumerable InferTypeInNameEquals(NameEqualsSyntax na return this.GetTypes(argumentExpression); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInPostfixUnaryExpression(PostfixUnaryExpressionSyntax postfixUnaryExpressionSyntax, SyntaxToken? previousToken = null) { // If we're after a postfix ++ or -- then we can't infer anything. if (previousToken.HasValue) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; switch (postfixUnaryExpressionSyntax.Kind()) { @@ -1936,7 +1884,7 @@ private IEnumerable InferTypeInPostfixUnaryExpression(Postfix return CreateResult(this.Compilation.GetSpecialType(SpecialType.System_Int32)); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInPrefixUnaryExpression(PrefixUnaryExpressionSyntax prefixUnaryExpression, SyntaxToken? previousToken = null) @@ -1973,7 +1921,7 @@ private IEnumerable InferTypeInPrefixUnaryExpression(PrefixUn return InferTypeInAddressOfExpression(prefixUnaryExpression); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInAddressOfExpression(PrefixUnaryExpressionSyntax prefixUnaryExpression) @@ -2007,9 +1955,7 @@ private IEnumerable InferTypeInAwaitExpression(AwaitExpressio var taskOfT = this.Compilation.TaskOfTType(); if (task == null || taskOfT == null) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; if (!types.Any()) { @@ -2023,9 +1969,7 @@ private IEnumerable InferTypeInYieldStatement(YieldStatementS { // If we are position based, then we have to be after the return keyword if (previousToken.HasValue && (previousToken.Value != yieldStatement.ReturnOrBreakKeyword || yieldStatement.ReturnOrBreakKeyword.IsKind(SyntaxKind.BreakKeyword))) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var declaration = yieldStatement.FirstAncestorOrSelf(n => n.IsReturnableConstruct()); var memberSymbol = GetDeclaredMemberSymbolFromOriginalSemanticModel(declaration); @@ -2036,7 +1980,7 @@ private IEnumerable InferTypeInYieldStatement(YieldStatementS // IAsyncEnumerable, IAsyncEnumerator and it's also good for error recovery in case there is a missing using. return memberType is INamedTypeSymbol namedType && namedType.TypeArguments.Length == 1 ? SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(namedType.TypeArguments[0])) - : SpecializedCollections.EmptyEnumerable(); + : []; } private IEnumerable InferTypeInRefExpression(RefExpressionSyntax refExpression) @@ -2066,9 +2010,7 @@ private IEnumerable InferTypeForReturnStatement( { // If we are position based, then we have to be after the return statement. if (previousToken.HasValue && previousToken.Value != returnStatement.ReturnKeyword) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var ancestor = returnStatement.FirstAncestorOrSelf(n => n.IsReturnableConstruct()); @@ -2090,7 +2032,7 @@ private IEnumerable InferTypeInMethodLikeDeclaration(SyntaxNo return type != null ? SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(UnwrapTaskLike(type, isAsync))) - : SpecializedCollections.EmptyEnumerable(); + : []; } private ISymbol GetDeclaredMemberSymbolFromOriginalSemanticModel(SyntaxNode declarationInCurrentTree) @@ -2139,7 +2081,7 @@ private IEnumerable InferTypeInSwitchExpressionArm( return InferTypes(switchExpression); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInSwitchExpression(SwitchExpressionSyntax switchExpression, SyntaxToken token) @@ -2147,7 +2089,7 @@ private IEnumerable InferTypeInSwitchExpression(SwitchExpress if (token.Kind() is SyntaxKind.OpenBraceToken or SyntaxKind.CommaToken) return GetTypes(switchExpression.GoverningExpression); - return SpecializedCollections.EmptyEnumerable(); + return []; } private IEnumerable InferTypeInSwitchLabel( @@ -2158,7 +2100,7 @@ private IEnumerable InferTypeInSwitchLabel( if (previousToken.Value != switchLabel.Keyword || switchLabel.Kind() != SyntaxKind.CaseSwitchLabel) { - return SpecializedCollections.EmptyEnumerable(); + return []; } } @@ -2171,9 +2113,7 @@ private IEnumerable InferTypeInSwitchStatement( { // If we have a position, then it has to be after "switch(" if (previousToken.HasValue && previousToken.Value != switchStatement.OpenParenToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; // Use the first case label to determine the return type. if (switchStatement.Sections.SelectMany(ss => ss.Labels) @@ -2193,9 +2133,7 @@ private IEnumerable InferTypeInThrowExpression(ThrowExpressio { // If we have a position, it has to be after the 'throw' keyword. if (previousToken.HasValue && previousToken.Value != throwExpression.ThrowKeyword) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(this.Compilation.ExceptionType()); } @@ -2204,9 +2142,7 @@ private IEnumerable InferTypeInThrowStatement(ThrowStatementS { // If we have a position, it has to be after the 'throw' keyword. if (previousToken.HasValue && previousToken.Value != throwStatement.ThrowKeyword) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(this.Compilation.ExceptionType()); } @@ -2215,9 +2151,7 @@ private IEnumerable InferTypeInUsingStatement(UsingStatementS { // If we have a position, it has to be after "using(" if (previousToken.HasValue && previousToken.Value != usingStatement.OpenParenToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(SpecialType.System_IDisposable); } @@ -2226,11 +2160,11 @@ private IEnumerable InferTypeInVariableDeclarator(VariableDec { var variableType = variableDeclarator.GetVariableType(); if (variableType == null) - return SpecializedCollections.EmptyEnumerable(); + return []; var symbol = SemanticModel.GetDeclaredSymbol(variableDeclarator); if (symbol == null) - return SpecializedCollections.EmptyEnumerable(); + return []; var type = symbol.GetSymbolType(); var types = CreateResult(type).Where(IsUsableTypeFunc); @@ -2327,7 +2261,7 @@ declExpr.Designation is ParenthesizedVariableDesignationSyntax parenthesizedVari return CreateResult(tupleType); } - return SpecializedCollections.EmptyEnumerable(); + return []; } private ITypeSymbol GetTupleType( @@ -2422,9 +2356,7 @@ private IEnumerable InferTypeInWhenClause(WhenClauseSyntax wh { // If we have a position, we have to be after the "when" if (previousToken.HasValue && previousToken.Value != whenClause.WhenKeyword) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(Compilation.GetSpecialType(SpecialType.System_Boolean))); } @@ -2433,9 +2365,7 @@ private IEnumerable InferTypeInWhileStatement(WhileStatementS { // If we're position based, then we have to be after the "while(" if (previousToken.HasValue && previousToken.Value != whileStatement.OpenParenToken) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; return CreateResult(SpecialType.System_Boolean); } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationContext.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationContext.cs index d1f79e57ab467..75ab6c7c49581 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationContext.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationContext.cs @@ -157,7 +157,7 @@ public CodeGenerationContext( AfterThisLocation = afterThisLocation; BeforeThisLocation = beforeThisLocation; AddImports = addImports; - AdditionalImports = additionalImports ?? SpecializedCollections.EmptyEnumerable(); + AdditionalImports = additionalImports ?? []; GenerateMembers = generateMembers; MergeNestedNamespaces = mergeNestedNamespaces; MergeAttributes = mergeAttributes; diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs index 42eb03714eb4d..a0663b98835ea 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs @@ -70,7 +70,7 @@ protected IEnumerable GetTypes(SyntaxNode expression, bool ob } } - return SpecializedCollections.EmptyEnumerable(); + return []; } private ImmutableArray Filter(IEnumerable types, bool filterUnusable = true) @@ -119,7 +119,7 @@ protected static IEnumerable GetCollectionElementType(INamedT } } - return SpecializedCollections.EmptyEnumerable(); + return []; } protected static bool IsEnumHasFlag(ISymbol symbol) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Utilities/ParsedDocument.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Utilities/ParsedDocument.cs index 5eb4b3ae50a8c..b3f3db3086555 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Utilities/ParsedDocument.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Utilities/ParsedDocument.cs @@ -73,9 +73,7 @@ public IEnumerable GetChanges(in ParsedDocument oldDocument) Contract.ThrowIfFalse(Id == oldDocument.Id); if (Text == oldDocument.Text || SyntaxTree == oldDocument.SyntaxTree) - { - return SpecializedCollections.EmptyEnumerable(); - } + return []; var textChanges = Text.GetTextChanges(oldDocument.Text); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Workspace/Mef/OrderableMetadata.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Workspace/Mef/OrderableMetadata.cs index 72c2a9a8c5a5d..0ca604272fc80 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Workspace/Mef/OrderableMetadata.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Workspace/Mef/OrderableMetadata.cs @@ -31,8 +31,8 @@ public OrderableMetadata(IDictionary data) public OrderableMetadata(string? name, IEnumerable? after = null, IEnumerable? before = null) { - this.AfterTyped = after ?? SpecializedCollections.EmptyEnumerable(); - this.BeforeTyped = before ?? SpecializedCollections.EmptyEnumerable(); + this.AfterTyped = after ?? []; + this.BeforeTyped = before ?? []; this.Name = name; } }