Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
5b1cefb
use collection expr
CyrusNajmabadi Apr 6, 2024
b1ad3a9
use collection expr
CyrusNajmabadi Apr 6, 2024
c2723ff
use collection expr
CyrusNajmabadi Apr 6, 2024
6eae9d3
use collection expr
CyrusNajmabadi Apr 6, 2024
6f29ecc
use collection expr
CyrusNajmabadi Apr 6, 2024
1d161f0
use collection expr
CyrusNajmabadi Apr 6, 2024
8ce6597
use collection expr
CyrusNajmabadi Apr 6, 2024
66e4621
use collection expr
CyrusNajmabadi Apr 6, 2024
287d755
use collection expr
CyrusNajmabadi Apr 6, 2024
61bbeaf
use collection expr
CyrusNajmabadi Apr 6, 2024
c37bf61
use collection expr
CyrusNajmabadi Apr 6, 2024
5972199
use collection expr
CyrusNajmabadi Apr 6, 2024
5910bf7
use collection expr
CyrusNajmabadi Apr 6, 2024
42b6e42
use collection expr
CyrusNajmabadi Apr 6, 2024
87355c2
use collection expr
CyrusNajmabadi Apr 6, 2024
a5fc822
use collection expr
CyrusNajmabadi Apr 6, 2024
9981fba
use collection expr
CyrusNajmabadi Apr 6, 2024
36f595a
use collection expr
CyrusNajmabadi Apr 6, 2024
755963d
use collection expr
CyrusNajmabadi Apr 6, 2024
b7d1355
use collection expr
CyrusNajmabadi Apr 6, 2024
0e6c150
use collection expr
CyrusNajmabadi Apr 6, 2024
8efbd4f
use collection expr
CyrusNajmabadi Apr 6, 2024
2205cc3
use collection expr
CyrusNajmabadi Apr 6, 2024
30c7756
use collection expr
CyrusNajmabadi Apr 6, 2024
8c81f6e
use collection expr
CyrusNajmabadi Apr 6, 2024
964b07c
use collection expr
CyrusNajmabadi Apr 6, 2024
4a81e6c
use collection expr
CyrusNajmabadi Apr 6, 2024
61782b6
use collection expr
CyrusNajmabadi Apr 6, 2024
3c2320f
use collection expr
CyrusNajmabadi Apr 6, 2024
e96968a
use collection expr
CyrusNajmabadi Apr 6, 2024
7317482
use collection expr
CyrusNajmabadi Apr 6, 2024
0d49c33
use collection expr
CyrusNajmabadi Apr 6, 2024
990b648
use collection expr
CyrusNajmabadi Apr 6, 2024
54488ec
use collection expr
CyrusNajmabadi Apr 6, 2024
96730eb
use collection expr
CyrusNajmabadi Apr 6, 2024
89cd3ed
use collection expr
CyrusNajmabadi Apr 6, 2024
d011c76
use collection expr
CyrusNajmabadi Apr 6, 2024
219b4e4
use collection expr
CyrusNajmabadi Apr 6, 2024
1a929eb
use collection expr
CyrusNajmabadi Apr 6, 2024
72c99d5
use collection expr
CyrusNajmabadi Apr 6, 2024
0895867
use collection expr
CyrusNajmabadi Apr 6, 2024
8ee5ed9
use collection expr
CyrusNajmabadi Apr 6, 2024
495611f
use collection expr
CyrusNajmabadi Apr 6, 2024
538a13d
use collection expr
CyrusNajmabadi Apr 6, 2024
9bed21c
use collection expr
CyrusNajmabadi Apr 6, 2024
458e8be
use collection expr
CyrusNajmabadi Apr 6, 2024
4196ca5
use collection expr
CyrusNajmabadi Apr 6, 2024
06ba49a
use collection expr
CyrusNajmabadi Apr 6, 2024
ef22741
use collection expr
CyrusNajmabadi Apr 6, 2024
5e2cfcb
use collection expr
CyrusNajmabadi Apr 6, 2024
380a52a
use collection expr
CyrusNajmabadi Apr 6, 2024
ad9ec29
use collection expr
CyrusNajmabadi Apr 6, 2024
c0de600
fix
CyrusNajmabadi Apr 6, 2024
9c22aab
use collection expr
CyrusNajmabadi Apr 6, 2024
b6d33c9
use collection expr
CyrusNajmabadi Apr 6, 2024
1c8e45a
use collection expr
CyrusNajmabadi Apr 6, 2024
2a1720d
Revert
CyrusNajmabadi Apr 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Analyzers/Core/Analyzers/Formatting/FormatterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ internal static IEnumerable<AbstractFormattingRule> GetDefaultFormattingRules(IS
/// <param name="cancellationToken">An optional cancellation token.</param>
/// <returns>The formatted tree's root node.</returns>
public static SyntaxNode Format(SyntaxNode node, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken)
=> Format(node, SpecializedCollections.SingletonEnumerable(node.FullSpan), syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken);
=> Format(node, [node.FullSpan], syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken);
Comment thread
CyrusNajmabadi marked this conversation as resolved.

public static SyntaxNode Format(SyntaxNode node, TextSpan spanToFormat, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken)
=> Format(node, SpecializedCollections.SingletonEnumerable(spanToFormat), syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken);
=> Format(node, [spanToFormat], syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken);

/// <summary>
/// Formats the whitespace of a syntax tree.
Expand Down Expand Up @@ -63,5 +63,5 @@ internal static IFormattingResult GetFormattingResult(SyntaxNode node, IEnumerab
/// <param name="cancellationToken">An optional cancellation token.</param>
/// <returns>The changes necessary to format the tree.</returns>
public static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken)
=> GetFormattedTextChanges(node, SpecializedCollections.SingletonEnumerable(node.FullSpan), syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken);
=> GetFormattedTextChanges(node, [node.FullSpan], syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static ICollection<ISymbol> GetMissingEnumMembers(ISwitchExpressionOperat
}
}

return SpecializedCollections.EmptyCollection<ISymbol>();
return [];
}

public static bool HasNullSwitchArm(ISwitchExpressionOperation operation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ public FixNameCodeAction(
}

protected override async Task<IEnumerable<CodeActionOperation>> ComputePreviewOperationsAsync(CancellationToken cancellationToken)
{
return SpecializedCollections.SingletonEnumerable(
new ApplyChangesOperation(await _createChangedSolutionAsync(cancellationToken).ConfigureAwait(false)));
}
=> [new ApplyChangesOperation(await _createChangedSolutionAsync(cancellationToken).ConfigureAwait(false))];

protected override async Task<ImmutableArray<CodeActionOperation>> ComputeOperationsAsync(IProgress<CodeAnalysisProgress> progress, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected override IList<TextChange> FormatBasedOnEndToken(ParsedDocument docume
var formatter = document.LanguageServices.GetRequiredService<ISyntaxFormattingService>();
return formatter.GetFormattingResult(
root,
SpecializedCollections.SingletonCollection(CommonFormattingHelpers.GetFormattingSpan(root, span.Value)),
[CommonFormattingHelpers.GetFormattingSpan(root, span.Value)],
options,
rules: null,
cancellationToken).GetTextChanges(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ private static (SyntaxNode newNode, SyntaxNode oldNode) ModifyObjectCreationExpr
// =>
// var l = new Bar() {}; // I am some comments
var replacementContainerNode = objectCreationNodeContainer.ReplaceSyntax(
nodes: SpecializedCollections.SingletonCollection(baseObjectCreationExpressionNode),
nodes: [baseObjectCreationExpressionNode],
(_, _) => objectCreationNodeWithCorrectInitializer.WithoutTrailingTrivia(),
tokens: SpecializedCollections.SingletonCollection(nextToken),
tokens: [nextToken],
computeReplacementToken: (_, _) =>
SyntaxFactory.Token(SyntaxKind.SemicolonToken).WithTrailingTrivia(objectCreationNodeWithCorrectInitializer.GetTrailingTrivia()),
trivia: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Task<ImmutableArray<TextChange>> GetFormattingChangesAsync(
var span = textSpan ?? new TextSpan(0, parsedDocument.Root.FullSpan.Length);
var formattingSpan = CommonFormattingHelpers.GetFormattingSpan(parsedDocument.Root, span);

return Task.FromResult(Formatter.GetFormattedTextChanges(parsedDocument.Root, SpecializedCollections.SingletonEnumerable(formattingSpan), document.Project.Solution.Services, options, cancellationToken).ToImmutableArray());
return Task.FromResult(Formatter.GetFormattedTextChanges(parsedDocument.Root, [formattingSpan], document.Project.Solution.Services, options, cancellationToken).ToImmutableArray());
}

public Task<ImmutableArray<TextChange>> GetFormattingChangesOnPasteAsync(Document document, ITextBuffer textBuffer, TextSpan textSpan, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public IEnumerable<string> DetailedDescription
=> null;

public IEnumerable<string> Names
=> SpecializedCollections.SingletonEnumerable(CommandName);
=> [CommandName];

public string CommandLine
=> "[" + NoConfigParameterName + "] [" + PlatformNames + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public NavigableSymbol(
public SnapshotSpan SymbolSpan { get; }

public IEnumerable<INavigableRelationship> Relationships
=> SpecializedCollections.SingletonEnumerable(PredefinedNavigableRelationships.Definition);
=> [PredefinedNavigableRelationships.Definition];

public void Navigate(INavigableRelationship relationship)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DefinitionPeekableItem(
}

public override IEnumerable<IPeekRelationship> Relationships
=> SpecializedCollections.SingletonEnumerable(PredefinedPeekRelationships.Definitions);
=> [PredefinedPeekRelationships.Definitions];

public override IPeekResultSource GetOrCreateResultSource(string relationshipName)
=> new ResultSource(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public ExternalFilePeekableItem(
}

public override IEnumerable<IPeekRelationship> Relationships
{
get { return SpecializedCollections.SingletonEnumerable(_relationship); }
}
=> [_relationship];

public override IPeekResultSource GetOrCreateResultSource(string relationshipName)
=> new ResultSource(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected override IEnumerable<SnapshotSpan> GetSpansToTag(ITextView? textView,
return base.GetSpansToTag(textView, subjectBuffer);
}

return SpecializedCollections.SingletonEnumerable(visibleSpanOpt.Value);
return [visibleSpanOpt.Value];
}

protected override async Task ProduceTagsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private void InitializeOpenBuffers(SnapshotSpan triggerSpan)
}

this.UndoManager.CreateInitialState(this.ReplacementText, _triggerView.Selection, new SnapshotSpan(triggerSpan.Snapshot, startingSpan));
_openTextBuffers[triggerSpan.Snapshot.TextBuffer].SetReferenceSpans(SpecializedCollections.SingletonEnumerable(startingSpan.ToTextSpan()));
_openTextBuffers[triggerSpan.Snapshot.TextBuffer].SetReferenceSpans([startingSpan.ToTextSpan()]);

UpdateReferenceLocationsTask();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ protected override async Task<IEnumerable<CodeActionOperation>> ComputePreviewOp

var solutionSet = await _renameTrackingCommitter.RenameSymbolAsync(cancellationToken).ConfigureAwait(false);

return SpecializedCollections.SingletonEnumerable(
(CodeActionOperation)new ApplyChangesOperation(solutionSet.RenamedSolution));
return [new ApplyChangesOperation(solutionSet.RenamedSolution)];
}

private bool TryInitializeRenameTrackingCommitter(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void FormatAndApplyToBuffer(
var formatter = document.GetRequiredLanguageService<ISyntaxFormattingService>();

var options = textBuffer.GetSyntaxFormattingOptions(editorOptionsService, document.Project.Services, explicitFormat: false);
var result = formatter.GetFormattingResult(documentSyntax.Root, SpecializedCollections.SingletonEnumerable(span), options, rules, cancellationToken);
var result = formatter.GetFormattingResult(documentSyntax.Root, [span], options, rules, cancellationToken);
var changes = result.GetTextChanges(cancellationToken);

using (Logger.LogBlock(FunctionId.Formatting_ApplyResultToBuffer, cancellationToken))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ private void RaiseTagsChanged(ITextBuffer buffer, DiffResult difference)
return;
}

OnTagsChangedForBuffer(SpecializedCollections.SingletonCollection(
new KeyValuePair<ITextBuffer, DiffResult>(buffer, difference)),
OnTagsChangedForBuffer(
[new KeyValuePair<ITextBuffer, DiffResult>(buffer, difference)],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This one won't fit the pattern unless the signature for OnTagsChangedForBuffer changes

highPriority: false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void AccumulateTextChanges(TextContentChangedEventArgs contentChanged)
var textChangeRange = new TextChangeRange(new TextSpan(c.OldSpan.Start, c.OldSpan.Length), c.NewLength);
this.AccumulatedTextChanges = this.AccumulatedTextChanges == null
? textChangeRange
: this.AccumulatedTextChanges.Accumulate(SpecializedCollections.SingletonEnumerable(textChangeRange));
: this.AccumulatedTextChanges.Accumulate([textChangeRange]);
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private void StoreTagSource(ITextView? textView, ITextBuffer subjectBuffer, TagS
protected virtual IEnumerable<SnapshotSpan> GetSpansToTag(ITextView? textView, ITextBuffer subjectBuffer)
{
// For a standard tagger, the spans to tag is the span of the entire snapshot.
return SpecializedCollections.SingletonEnumerable(subjectBuffer.CurrentSnapshot.GetFullSpan());
return [subjectBuffer.CurrentSnapshot.GetFullSpan()];
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override IEnumerable<SnapshotSpan> GetSpansToTag(ITextView? textView,

// If we're the 'InView' tagger, tag what was visible.
if (_viewPortToTag is ViewPortToTag.InView)
return SpecializedCollections.SingletonEnumerable(visibleSpan);
return [visibleSpan];

// For the above/below tagger, broaden the span to to the requested portion above/below what's visible, then
// subtract out the visible range.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private static FixAllState GetFixAllState(
if (scope == FixAllScope.Custom)
{
// Bulk fixing diagnostics in selected scope.
var diagnosticsToFix = ImmutableDictionary.CreateRange(SpecializedCollections.SingletonEnumerable(KeyValuePairUtil.Create(document, diagnostics.ToImmutableArray())));
var diagnosticsToFix = ImmutableDictionary.CreateRange([KeyValuePairUtil.Create(document, diagnostics.ToImmutableArray())]);
return FixAllState.Create(fixAllProvider, diagnosticsToFix, fixer, equivalenceKey, optionsProvider);
}

Expand Down
5 changes: 1 addition & 4 deletions src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,7 @@ private static void GetDocumentAndExtensionManager(
}

private static IEnumerable<Lazy<CodeFixProvider, CodeChangeProviderMetadata>> CreateFixers()
{
return SpecializedCollections.SingletonEnumerable(
new Lazy<CodeFixProvider, CodeChangeProviderMetadata>(() => new MockFixer(), new CodeChangeProviderMetadata("Test", languages: LanguageNames.CSharp)));
}
=> [new Lazy<CodeFixProvider, CodeChangeProviderMetadata>(() => new MockFixer(), new CodeChangeProviderMetadata("Test", languages: LanguageNames.CSharp))];

internal class MockFixer : CodeFixProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public virtual Task DisposeAsync()
internal static async Task GenerateAndVerifySourceAsync(
string metadataSource, string symbolName, string projectLanguage, string expected, bool signaturesOnly = true, bool includeXmlDocComments = false, string languageVersion = null, string metadataLanguageVersion = null, string metadataCommonReferences = null)
{
using var context = TestContext.Create(projectLanguage, SpecializedCollections.SingletonEnumerable(metadataSource), includeXmlDocComments, languageVersion: languageVersion, metadataLanguageVersion: metadataLanguageVersion, metadataCommonReferences: metadataCommonReferences);
using var context = TestContext.Create(projectLanguage, [metadataSource], includeXmlDocComments, languageVersion: languageVersion, metadataLanguageVersion: metadataLanguageVersion, metadataCommonReferences: metadataCommonReferences);
await context.GenerateAndVerifySourceAsync(symbolName, expected, signaturesOnly: signaturesOnly);
}

Expand Down Expand Up @@ -103,7 +103,7 @@ internal static async Task TestSymbolIdMatchesMetadataAsync(string projectLangua
var metadataSource = @"[assembly: System.Reflection.AssemblyVersion(""2.0.0.0"")] public class C { }";
var symbolName = "C";

using var context = TestContext.Create(projectLanguage, SpecializedCollections.SingletonEnumerable(metadataSource));
using var context = TestContext.Create(projectLanguage, [metadataSource]);
var metadataSymbol = await context.ResolveSymbolAsync(symbolName);
var metadataSymbolId = metadataSymbol.GetSymbolKey();
var generatedFile = await context.GenerateSourceAsync(symbolName);
Expand Down
Loading