Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void AnalyzeNamespace(SyntaxNodeAnalysisContext context)
diagnosticLocation,
option.Notification,
context.Options,
ImmutableArray.Create(declaration.GetLocation()),
[declaration.GetLocation()],
ImmutableDictionary<string, string?>.Empty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void AnalyzeNamespace(SyntaxNodeAnalysisContext context)
diagnosticLocation,
option.Notification,
context.Options,
ImmutableArray.Create(declaration.GetLocation()),
[declaration.GetLocation()],
ImmutableDictionary<string, string?>.Empty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void ProcessCompilationUnit(SyntaxNodeAnalysisContext context)
methodDeclaration, isHidden: option.Notification.Severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) == ReportDiagnostic.Hidden),
option.Notification,
context.Options,
ImmutableArray.Create(methodDeclaration.GetLocation()),
[methodDeclaration.GetLocation()],
ImmutableDictionary<string, string?>.Empty));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
localFunction.Identifier.GetLocation(),
option.Notification,
context.Options,
additionalLocations: ImmutableArray.Create(localFunction.GetLocation()),
additionalLocations: [localFunction.GetLocation()],
properties: null));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -140,7 +141,7 @@ private void AnalyzeBlock(
return;

var (location, additionalLocation) = GetDiagnosticLocation(owningMethod, cancellationToken);
if (location == null || !context.ShouldAnalyzeSpan(location.SourceSpan))
if (location == null || additionalLocation == null || !context.ShouldAnalyzeSpan(location.SourceSpan))
return;

foreach (var blockOperation in context.OperationBlocks)
Expand All @@ -163,7 +164,7 @@ private void AnalyzeBlock(
location,
notificationOption,
context.Options,
additionalLocations: ImmutableArray.Create(additionalLocation),
additionalLocations: [additionalLocation],
properties: null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override void InitializeWorker(AnalysisContext context)
location,
option.Notification,
context.Options,
additionalLocations: ImmutableArray.Create(additionalLocation),
additionalLocations: [additionalLocation],
properties: null));
});
}, SymbolKind.NamedType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void ProcessConstructorInitializer(
colonToken.GetLocation(),
notificationOption,
context.Options,
additionalLocations: ImmutableArray.Create(initializer.GetLocation()),
additionalLocations: [initializer.GetLocation()],
properties: null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
((PostfixUnaryExpressionSyntax)left).OperatorToken.GetLocation(),
NotificationOption2.Warning,
context.Options,
ImmutableArray.Create(node.GetLocation()),
[node.GetLocation()],
properties: null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void AnalyzeSubpattern(SyntaxNodeAnalysisContext syntaxContext)
expressionColon.GetLocation(),
styleOption.Notification,
syntaxContext.Options,
ImmutableArray.Create(subpattern.GetLocation()),
[subpattern.GetLocation()],
properties: null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private void AnalyzeArrayInitializerExpression(SyntaxNodeAnalysisContext context
initializer.OpenBraceToken.GetLocation(),
option.Notification,
context.Options,
additionalLocations: ImmutableArray.Create(initializer.GetLocation()),
additionalLocations: [initializer.GetLocation()],
properties: changesSemantics ? ChangesSemantics : null));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void AnalyzeMemberAccess(SyntaxNodeAnalysisContext context, INamedTypeSy
memberAccess.Name.Identifier.GetLocation(),
option.Notification,
context.Options,
additionalLocations: ImmutableArray.Create(nodeToReplace.GetLocation()),
additionalLocations: [nodeToReplace.GetLocation()],
properties: changesSemantics ? ChangesSemantics : null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void AnalyzeMemberAccess(SyntaxNodeAnalysisContext context, INamedTypeSy
memberAccess.Name.Identifier.GetLocation(),
option.Notification,
context.Options,
additionalLocations: ImmutableArray.Create(invocation.GetLocation()),
additionalLocations: [invocation.GetLocation()],
properties: analysisResult.Value.ChangesSemantics ? ChangesSemantics : null));

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
objectCreation.Type.GetLocation(),
styleOption.Notification,
context.Options,
ImmutableArray.Create(objectCreation.GetLocation()),
[objectCreation.GetLocation()],
properties: null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void ProcessBlockLikeStatement(SyntaxTreeAnalysisContext context, Notifi
GetDiagnosticLocation(block),
notificationOption,
context.Options,
additionalLocations: ImmutableArray.Create(nextToken.GetLocation()),
additionalLocations: [nextToken.GetLocation()],
properties: null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void CheckToken(SyntaxTreeAnalysisContext context, NotificationOption2 n
Location.Create(badTrivia.SyntaxTree!, new TextSpan(badTrivia.SpanStart, 0)),
notificationOption,
context.Options,
additionalLocations: ImmutableArray.Create(token.GetLocation()),
additionalLocations: [token.GetLocation()],
properties: null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void AnalyzeAssignment(SyntaxNodeAnalysisContext context)
assignmentToken.GetLocation(),
option.Notification,
context.Options,
additionalLocations: ImmutableArray.Create(assignment.GetLocation()),
additionalLocations: [assignment.GetLocation()],
properties: ImmutableDictionary.Create<string, string?>()
.Add(UseCompoundAssignmentUtilities.Increment, UseCompoundAssignmentUtilities.Increment)));
return;
Expand All @@ -180,7 +180,7 @@ private void AnalyzeAssignment(SyntaxNodeAnalysisContext context)
assignmentToken.GetLocation(),
option.Notification,
context.Options,
additionalLocations: ImmutableArray.Create(assignment.GetLocation()),
additionalLocations: [assignment.GetLocation()],
properties: ImmutableDictionary.Create<string, string?>()
.Add(UseCompoundAssignmentUtilities.Decrement, UseCompoundAssignmentUtilities.Decrement)));
return;
Expand All @@ -193,7 +193,7 @@ private void AnalyzeAssignment(SyntaxNodeAnalysisContext context)
assignmentToken.GetLocation(),
option.Notification,
context.Options,
additionalLocations: ImmutableArray.Create(assignment.GetLocation()),
additionalLocations: [assignment.GetLocation()],
properties: null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void AnalyzeOperation(OperationAnalysisContext context)
ifStatement.GetFirstToken().GetLocation(),
option.Notification,
context.Options,
additionalLocations: ImmutableArray.Create(ifStatement.GetLocation()),
additionalLocations: [ifStatement.GetLocation()],
properties: canSimplify ? UseConditionalExpressionHelpers.CanSimplifyProperties : null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ private void AnalyzeIfStatement(
ifStatement.GetFirstToken().GetLocation(),
option.Notification,
context.Options,
ImmutableArray.Create(
ifStatement.GetLocation(),
trueStatement.GetLocation(),
whenPartMatch.GetLocation()),
[ifStatement.GetLocation(), trueStatement.GetLocation(), whenPartMatch.GetLocation()],
properties));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public async Task TrackingService_GetLatestSpansAsync(bool scheduleInitialTracki

spanProvider.GetBaseActiveStatementSpansImpl = (_, documentIds) =>
[
ImmutableArray.Create(
new ActiveStatementSpan(new ActiveStatementId(0), span11, ActiveStatementFlags.NonLeafFrame),
new ActiveStatementSpan(new ActiveStatementId(1), span12, ActiveStatementFlags.LeafFrame)),
[
new ActiveStatementSpan(new ActiveStatementId(0), span11, ActiveStatementFlags.NonLeafFrame),
new ActiveStatementSpan(new ActiveStatementId(1), span12, ActiveStatementFlags.LeafFrame),
],
[],
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void F () {}
var documentInfo = DocumentInfo.Create(
DocumentId.CreateNewId(project.Id),
name: "file.razor.g.cs",
folders: Array.Empty<string>(),
folders: [],
sourceCodeKind: SourceCodeKind.Regular,
loader: TextLoader.From(TextAndVersion.Create(sourceText, VersionStamp.Create(), "file.razor.g.cs")),
filePath: "file.razor.g.cs")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void GetItems_Windows_Network()
searchPaths: [],
baseDirectoryOpt: null,
allowableExtensions: [".cs"],
drives: Array.Empty<string>(),
drives: [],
directories: new[]
{
@"\\server\share",
Expand Down Expand Up @@ -191,7 +191,7 @@ public void GetItems_Unix1()
searchPaths: [@"/A", @"/B"],
baseDirectoryOpt: @"/C",
allowableExtensions: [".abc", ".def"],
drives: Array.Empty<string>(),
drives: [],
directories: new[]
{
@"/A",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1830,8 +1830,8 @@ .method public instance int32[] F( // 3
r2 = MetadataReference.CreateFromImage(bytes);
}

var c1 = (Compilation)CS.CSharpCompilation.Create("comp1", Array.Empty<SyntaxTree>(), [NetFramework.mscorlib, r1]);
var c2 = (Compilation)CS.CSharpCompilation.Create("comp2", Array.Empty<SyntaxTree>(), [NetFramework.mscorlib, r2]);
var c1 = (Compilation)CS.CSharpCompilation.Create("comp1", [], [NetFramework.mscorlib, r1]);
var c2 = (Compilation)CS.CSharpCompilation.Create("comp2", [], [NetFramework.mscorlib, r2]);
var type1 = (ITypeSymbol)c1.GlobalNamespace.GetMembers("C").Single();
var type2 = (ITypeSymbol)c2.GlobalNamespace.GetMembers("C").Single();

Expand Down
2 changes: 1 addition & 1 deletion src/EditorFeatures/Text/Extensions.SnapshotSourceText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private IReadOnlyList<TextChangeRange> GetChangeRanges(ITextImage? oldImage, int
{
// Claim its all changed
Logger.Log(FunctionId.Workspace_SourceText_GetChangeRanges, "Invalid Snapshots");
return ImmutableArray.Create(new TextChangeRange(new TextSpan(0, oldTextLength), this.Length));
return [new TextChangeRange(new TextSpan(0, oldTextLength), this.Length)];
}
else if (AreSameReiteratedVersion(oldImage, newImage))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private FixAllProvider()
}

public override IEnumerable<FixAllScope> GetSupportedFixAllScopes()
=> ImmutableArray.Create(FixAllScope.Solution);
=> [FixAllScope.Solution];

public override Task<CodeAction?> GetFixAsync(FixAllContext fixAllContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ protected override async Task<IEnumerable<CodeActionOperation>> ComputeOperation
var oldText = await OriginalDocument.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
var newText = await updatedDocument.GetValueTextAsync(cancellationToken).ConfigureAwait(false);

return ImmutableArray.Create<CodeActionOperation>(
new InstallPackageAndAddImportOperation(
OriginalDocument.Id, oldText, newText, _installOperation));
return [new InstallPackageAndAddImportOperation(
OriginalDocument.Id, oldText, newText, _installOperation)];
}

private sealed class InstallPackageAndAddImportOperation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ private SuppressionFixAllProvider()
}

public override IEnumerable<FixAllScope> GetSupportedFixAllScopes()
=> ImmutableArray.Create(FixAllScope.Document, FixAllScope.Project,
FixAllScope.Solution, FixAllScope.ContainingMember, FixAllScope.ContainingType);
=> [FixAllScope.Document, FixAllScope.Project, FixAllScope.Solution, FixAllScope.ContainingMember, FixAllScope.ContainingType];

public override async Task<CodeAction> GetFixAsync(FixAllContext fixAllContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
context.ReportDiagnostic(DiagnosticHelper.Create(
Descriptor, thisExpression.GetLocation(), notification,
context.Options,
ImmutableArray.Create(memberAccessExpression.GetLocation()),
[memberAccessExpression.GetLocation()],
builder.ToImmutable()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected static IReadOnlyList<SyntaxNode> WalkUpScopeBlocks(
blockFacts.IsScopeBlock(parent) &&
blockFacts.GetExecutableBlockStatements(parent).Count == statements.Count)
{
statements = ImmutableArray.Create(parent);
statements = [parent];
}

return statements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected sealed override async Task<SyntaxNode> GetChangedRootAsync(
if (!blockFacts.IsExecutableBlock(ifOrElseIf.Parent))
{
// In order to insert a new statement, we have to be inside a block.
editor.ReplaceNode(ifOrElseIf, (currentNode, _) => generator.ScopeBlock(ImmutableArray.Create(currentNode)));
editor.ReplaceNode(ifOrElseIf, (currentNode, _) => generator.ScopeBlock([currentNode]));
}

editor.InsertAfter(ifOrElseIf, secondIfStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ await localWorkspace.ChangeSolutionAsync(localWorkspace.CurrentSolution
mockEncService.GetBaseActiveStatementSpansImpl = (solution, documentIds) =>
{
AssertEx.Equal(new[] { documentId, inProcOnlyDocumentId }, documentIds);
return [ImmutableArray.Create(activeStatementSpan1)];
return [[activeStatementSpan1]];
};

var baseActiveSpans = await sessionProxy.GetBaseActiveStatementSpansAsync(localWorkspace.CurrentSolution, [documentId, inProcOnlyDocumentId], CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ internal static DocumentInfo CreateDesignTimeOnlyDocument(ProjectId projectId, s
return DocumentInfo.Create(
DocumentId.CreateNewId(projectId, name),
name: name,
folders: Array.Empty<string>(),
folders: [],
sourceCodeKind: SourceCodeKind.Regular,
loader: TextLoader.From(TextAndVersion.Create(sourceText, VersionStamp.Create(), path)),
filePath: path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void M()
Uri = ProtocolConversions.CreateAbsoluteUri($"C:\\{TestSpanMapper.GeneratedFileName}"),
Range = new LSP.Range { Start = position, End = position }
});
AssertLocationsEqual(ImmutableArray.Create(TestSpanMapper.MappedFileLocation), results);
AssertLocationsEqual([TestSpanMapper.MappedFileLocation], results);
}

[Theory, CombinatorialData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void IA.M()
Uri = ProtocolConversions.CreateAbsoluteUri($"C:\\{TestSpanMapper.GeneratedFileName}"),
Range = new LSP.Range { Start = position, End = position }
});
AssertLocationsEqual(ImmutableArray.Create(TestSpanMapper.MappedFileLocation), results);
AssertLocationsEqual([TestSpanMapper.MappedFileLocation], results);
}

[Theory, CombinatorialData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,39 @@ internal void VerifyEncLog(IEnumerable<EditAndContinueLogEntry>? expected = null
=> Verify(() =>
{
AssertEx.Equal(
expected ?? Array.Empty<EditAndContinueLogEntry>(),
expected ?? [],
MetadataReader.GetEditAndContinueLogEntries(), itemInspector: EncLogRowToString, message: GetAssertMessage("EncLog doesn't match"));
});

internal void VerifyEncMap(IEnumerable<EntityHandle>? expected = null)
=> Verify(() =>
{
AssertEx.Equal(
expected ?? Array.Empty<EntityHandle>(),
expected ?? [],
MetadataReader.GetEditAndContinueMapEntries(), itemInspector: EncMapRowToString, message: GetAssertMessage("EncMap doesn't match"));
});

internal void VerifyEncLogDefinitions(IEnumerable<EditAndContinueLogEntry>? expected = null)
=> Verify(() =>
{
AssertEx.Equal(
expected ?? Array.Empty<EditAndContinueLogEntry>(),
expected ?? [],
MetadataReader.GetEditAndContinueLogEntries().Where(e => IsDefinition(e.Handle.Kind)), itemInspector: EncLogRowToString, message: GetAssertMessage("EncLog definitions don't match"));
});

internal void VerifyEncMapDefinitions(IEnumerable<EntityHandle>? expected = null)
=> Verify(() =>
{
AssertEx.Equal(
expected ?? Array.Empty<EntityHandle>(),
expected ?? [],
MetadataReader.GetEditAndContinueMapEntries().Where(e => IsDefinition(e.Kind)), itemInspector: EncMapRowToString, message: GetAssertMessage("EncMap definitions don't match"));
});

internal void VerifyCustomAttributes(IEnumerable<CustomAttributeRow>? expected = null)
=> Verify(() =>
{
AssertEx.Equal(
expected ?? Array.Empty<CustomAttributeRow>(),
expected ?? [],
MetadataReader.GetCustomAttributeRows(), itemInspector: AttributeRowToString);
});

Expand Down
Loading
Loading