Skip to content

Commit

Permalink
Mitigate breaks in bootstrapped Roslyn
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz committed May 21, 2024
1 parent 5595cbd commit a9556fa
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void DiagnosticAnalyzerAllInOne()
missingSyntaxKinds.Add(SyntaxKind.SpreadElement);

var analyzer = new CSharpTrackingDiagnosticAnalyzer();
var options = new AnalyzerOptions(new[] { new TestAdditionalText() }.ToImmutableArray<AdditionalText>());
var options = new AnalyzerOptions([new TestAdditionalText()]);
CreateCompilationWithMscorlib45(source).VerifyAnalyzerDiagnostics(new[] { analyzer }, options);
analyzer.VerifyAllAnalyzerMembersWereCalled();
analyzer.VerifyAnalyzeSymbolCalledForAllSymbolKinds();
Expand Down Expand Up @@ -99,7 +99,7 @@ public class C
public void AnalyzerDriverIsSafeAgainstAnalyzerExceptions()
{
var compilation = CreateCompilationWithMscorlib45(TestResource.AllInOneCSharpCode);
var options = new AnalyzerOptions(new[] { new TestAdditionalText() }.ToImmutableArray<AdditionalText>());
var options = new AnalyzerOptions([new TestAdditionalText()]);

ThrowingDiagnosticAnalyzer<SyntaxKind>.VerifyAnalyzerEngineIsSafeAgainstExceptions(analyzer =>
compilation.GetAnalyzerDiagnostics(new[] { analyzer }, options));
Expand All @@ -111,7 +111,7 @@ public void AnalyzerOptionsArePassedToAllAnalyzers()
var text = new StringText(string.Empty, encodingOpt: null);
AnalyzerOptions options = new AnalyzerOptions
(
new[] { new TestAdditionalText("myfilepath", text) }.ToImmutableArray<AdditionalText>()
[new TestAdditionalText("myfilepath", text)]
);

var compilation = CreateCompilationWithMscorlib45(TestResource.AllInOneCSharpCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.UnitTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.UnitTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.UnitTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void InitializeTest()
var parseOptions = new CSharpParseOptions(kind: SourceCodeKind.Regular, documentationMode: DocumentationMode.None)
.WithFeatures(new[] { new KeyValuePair<string, string>("IOperation", "true") });
var compilation = CreateCompilation(code, parseOptions: parseOptions);
var options = new AnalyzerOptions(new[] { new TestAdditionalText() }.ToImmutableArray<AdditionalText>());
var options = new AnalyzerOptions([new TestAdditionalText()]);

Verify(compilation, options, nameof(AnalysisContext.RegisterCodeBlockAction));
Verify(compilation, options, nameof(AnalysisContext.RegisterCodeBlockStartAction));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ internal static T[] Copy<T>(this T[] array, int start, int length)
return newArray;
}

public static int IndexOf<T>(this T[] array, T value)
=> Array.IndexOf(array, value);

public static bool Contains<T>(this T[] array, T value)
=> Array.IndexOf(array, value) >= 0;

internal static T[] InsertAt<T>(this T[] array, int position, T item)
{
T[] newArray = new T[array.Length + 1];
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/Test/Core/TargetFrameworkUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.CodeAnalysis.CodeGen;
using System.Reflection;
using System.Collections.Concurrent;
using Roslyn.Utilities;

namespace Roslyn.Test.Utilities
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.QuickInfo;
using Roslyn.LanguageServer.Protocol;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.LanguageServer.Handler
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/GenerateRulesMissingDocumentation/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ await checkHelpLinkAsync(helpLinkUri).ConfigureAwait(false))
{
// We consider having "extra" entries as valid. This is to prevent CI failures due to rules being documented.
// However, we consider "missing" entries as invalid. This is to force updating the file when new rules are added.
if (!actualContent.Contains(line))
if (Array.IndexOf(actualContent, line) < 0)
{
await Console.Error.WriteLineAsync($"Missing entry in '{fileWithPath}'. Please add the below entry to this file to fix the build:").ConfigureAwait(false);
await Console.Error.WriteLineAsync(line).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CodeRefactorings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Linq;
using System.Reflection;
using System.Threading;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Host.Mef;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;
using Xunit.Abstractions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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.Diagnostics.CodeAnalysis;

namespace Microsoft.CodeAnalysis.Shared.Extensions;
Expand All @@ -11,7 +10,4 @@ internal static class ArrayExtensions
{
public static bool IsNullOrEmpty<T>([NotNullWhen(returnValue: false)] this T[]? array)
=> array == null || array.Length == 0;

public static bool Contains<T>(this T[] array, T item)
=> Array.IndexOf(array, item) >= 0;
}

0 comments on commit a9556fa

Please sign in to comment.