From a26f09ee0b768048e76b3158ea548cc3f51bf759 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Tue, 25 Aug 2026 15:14:17 -0700 Subject: [PATCH 1/2] Unify samples analyzer configuration more with Roslyn, and ensure correctness build reports issues --- eng/validate-roslyn-sdk-samples.ps1 | 2 + src/RoslynSdk/Directory.Packages.props | 3 -- .../Directory.Packages.props | 8 ++++ src/RoslynSdk/Samples/.editorconfig | 38 +++---------------- .../SimpleAdditionalFileAnalyzer.cs | 2 +- .../XmlAdditionalFileAnalyzer.cs | 2 +- .../CodeBlockStartedAnalyzer.cs | 2 +- ...rtedAnalyzerWithCompilationWideAnalysis.cs | 2 +- .../StatelessAnalyzers/CompilationAnalyzer.cs | 2 +- .../StatelessAnalyzers/IOperationAnalyzer.cs | 2 +- .../StatelessAnalyzers/SymbolAnalyzer.cs | 2 +- .../StatelessAnalyzers/SyntaxNodeAnalyzer.cs | 2 +- .../StatelessAnalyzers/SyntaxTreeAnalyzer.cs | 2 +- .../Converting/Converter.NodeVisitor.cs | 17 --------- .../Converting/Converter.StatementVisitor.cs | 21 ---------- .../CSharp/ConsoleClassifier/Program.cs | 6 +-- ...rtToAutoPropertyCodeRefactoringProvider.cs | 5 +-- .../PropertyRewriter.cs | 1 - ...ertToConditionalCodeRefactoringProvider.cs | 2 +- .../Samples/CSharp/FormatSolution/Program.cs | 4 +- .../ApplicableActionFinder.cs | 4 +- .../Framework/NotifyTaskCompletion.cs | 2 +- .../Framework/ViewModel_CommandBindings.cs | 13 +++++++ .../Properties/AssemblyInfo.cs | 1 - .../Services/WorkspaceService.cs | 4 +- .../ViewModels/DocumentViewModel.cs | 2 +- .../ViewModels/HierarchyItemViewModel.cs | 2 +- .../ViewModels/MainWindowViewModel.cs | 8 ++-- .../AutoNotifyGenerator.cs | 1 - .../SourceGeneratorSamples/CsvGenerator.cs | 2 - .../SourceGeneratorSamples/MathsGenerator.cs | 20 +++++----- .../SettingsXmlGenerator.cs | 1 - .../CSharp/TreeTransforms/Transforms.cs | 2 +- src/RoslynSdk/Samples/Directory.Build.props | 2 +- .../Samples/Directory.Packages.props | 2 + .../Samples/VisualBasic/APISamples/FAQ.vb | 3 +- .../APISamples/SymbolsAndSemantics.vb | 7 ++-- .../VisualBasic/APISamples/SyntaxTrees.vb | 1 - .../SimpleAdditionalFileAnalyzer.vb | 4 +- .../XmlAdditionalFileAnalyzer.vb | 4 +- .../CodeBlockStartedAnalyzer.vb | 4 +- .../CompilationStartedAnalyzer.vb | 2 + ...rtedAnalyzerWithCompilationWideAnalysis.vb | 22 ++++++----- .../StatelessAnalyzers/CodeBlockAnalyzer.vb | 2 + .../StatelessAnalyzers/CompilationAnalyzer.vb | 4 +- .../SemanticModelAnalyzer.vb | 4 +- .../StatelessAnalyzers/SymbolAnalyzer.vb | 4 +- .../StatelessAnalyzers/SyntaxNodeAnalyzer.vb | 2 + .../StatelessAnalyzers/SyntaxTreeAnalyzer.vb | 4 +- .../VisualBasic/ConsoleClassifier/Program.vb | 6 +-- .../CodeRefactoringProvider.vb | 8 ++-- .../MakeConst.Test/MakeConstUnitTests.vb | 7 +++- .../MakeConst/MakeConst/MakeConstAnalyzer.vb | 2 + .../SourceGenerators/GeneratedDemo/Program.vb | 6 ++- .../GeneratedDemo/UseAutoNotifyGenerator.vb | 6 ++- .../GeneratedDemo/UseCsvGenerator.vb | 6 ++- .../GeneratedDemo/UseHelloWorldGenerator.vb | 6 ++- .../AutoNotifyGenerator.vb | 6 ++- .../SourceGeneratorSamples/CsvGenerator.vb | 12 ++++-- .../HelloWorldGenerator.vb | 6 ++- .../SettingsXmlGenerator.vb | 6 ++- .../VisualBasic/TreeTransforms/Transforms.vb | 2 +- .../TreeTransforms/TreeTransforms.vb | 1 - .../Converter.vb | 2 +- .../NodeConvertingVisitor.vb | 21 +++++----- .../QueryClauseConvertingVisitor.vb | 5 +-- .../UnitTest1.vb | 9 +++-- 67 files changed, 188 insertions(+), 187 deletions(-) create mode 100644 src/RoslynSdk/Microsoft.CodeAnalysis.Testing/Directory.Packages.props diff --git a/eng/validate-roslyn-sdk-samples.ps1 b/eng/validate-roslyn-sdk-samples.ps1 index 36889a087cc5d..0f6cfbc3e27e7 100644 --- a/eng/validate-roslyn-sdk-samples.ps1 +++ b/eng/validate-roslyn-sdk-samples.ps1 @@ -61,6 +61,8 @@ $buildArgs = @( $solutionPath "-c", $configuration "--no-incremental" + "--warnaserror" + "/p:RoslynEnforceCodeStyle=true" ) if ($ci) { diff --git a/src/RoslynSdk/Directory.Packages.props b/src/RoslynSdk/Directory.Packages.props index daf697078b7d3..2e01f2d07d3ba 100644 --- a/src/RoslynSdk/Directory.Packages.props +++ b/src/RoslynSdk/Directory.Packages.props @@ -3,9 +3,6 @@ - - false - 7.0.3 6.3.4 diff --git a/src/RoslynSdk/Microsoft.CodeAnalysis.Testing/Directory.Packages.props b/src/RoslynSdk/Microsoft.CodeAnalysis.Testing/Directory.Packages.props new file mode 100644 index 0000000000000..b9c74ffcf19c7 --- /dev/null +++ b/src/RoslynSdk/Microsoft.CodeAnalysis.Testing/Directory.Packages.props @@ -0,0 +1,8 @@ + + + + + + false + + diff --git a/src/RoslynSdk/Samples/.editorconfig b/src/RoslynSdk/Samples/.editorconfig index e65e8e2387f57..62b8e69edadf8 100644 --- a/src/RoslynSdk/Samples/.editorconfig +++ b/src/RoslynSdk/Samples/.editorconfig @@ -1,37 +1,11 @@ -# Avoid "this." and "Me." if not necessary -dotnet_style_qualification_for_field = true:error -dotnet_style_qualification_for_property = true:error -dotnet_style_qualification_for_method = true:error -dotnet_style_qualification_for_event = true:error +[*.{cs,vb}] -# Use language keywords instead of framework type names for type references -dotnet_style_predefined_type_for_locals_parameters_members = true:error -dotnet_style_predefined_type_for_member_access = true:error +# Samples consume public Roslyn APIs and cannot use the internal alternatives required by the main repo. +dotnet_diagnostic.RS0030.severity = none -# Suggest more modern language features when available -dotnet_style_object_initializer = true:error -dotnet_style_collection_initializer = true:error -dotnet_style_coalesce_expression = true:error -dotnet_style_null_propagation = true:error -dotnet_style_explicit_tuple_names = true:error - -# CSharp code style settings: -[*.cs] -# Prefer "var" everywhere -csharp_style_var_for_built_in_types = false:error -csharp_style_var_when_type_is_apparent = false:error -csharp_style_var_elsewhere = false:error - -# Suggest more modern language features when available -csharp_style_pattern_matching_over_is_with_cast_check = true:error -csharp_style_pattern_matching_over_as_with_null_check = true:error -csharp_style_inlined_variable_declaration = true:error -csharp_style_throw_expression = true:error -csharp_style_conditional_delegate_call = true:error +# Samples do not use the repository-internal MEF construction convention. +dotnet_diagnostic.RS0033.severity = none +dotnet_diagnostic.RS0034.severity = none # Samples preserve unused parameters to demonstrate extensibility points. dotnet_diagnostic.IDE0060.severity = none - -# Require the repository license header in all sample source files. -file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.\nSee the LICENSE file in the project root for more information. -dotnet_diagnostic.IDE0073.severity = error diff --git a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/SimpleAdditionalFileAnalyzer.cs b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/SimpleAdditionalFileAnalyzer.cs index 7425d1f0eea5d..8d5e4f532823e 100644 --- a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/SimpleAdditionalFileAnalyzer.cs +++ b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/SimpleAdditionalFileAnalyzer.cs @@ -22,7 +22,7 @@ namespace Sample.Analyzers class SimpleAdditionalFileAnalyzer : DiagnosticAnalyzer { private const string Title = "Type name contains invalid term"; - private const string MessageFormat = "The term '{0}' is not allowed in a type name."; + private const string MessageFormat = "The term '{0}' is not allowed in a type name"; private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor( diff --git a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/XmlAdditionalFileAnalyzer.cs b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/XmlAdditionalFileAnalyzer.cs index db3754b5bb4c8..075dd55fd4a1e 100644 --- a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/XmlAdditionalFileAnalyzer.cs +++ b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/XmlAdditionalFileAnalyzer.cs @@ -24,7 +24,7 @@ namespace Sample.Analyzers class XmlAdditionalFileAnalyzer : DiagnosticAnalyzer { private const string Title = "Type name contains invalid term"; - private const string MessageFormat = "The term '{0}' is not allowed in a type name."; + private const string MessageFormat = "The term '{0}' is not allowed in a type name"; private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor( diff --git a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.cs b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.cs index 0ae5a7ef049e6..09ff204e72dcc 100644 --- a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.cs +++ b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.cs @@ -27,7 +27,7 @@ namespace Sample.Analyzers public class CodeBlockStartedAnalyzer : DiagnosticAnalyzer { private const string Title = "Remove unused parameters"; - public const string MessageFormat = "Parameter '{0}' is unused in the method '{1}'."; + public const string MessageFormat = "Parameter '{0}' is unused in the method '{1}'"; private const string Description = "Remove unused parameters."; internal static DiagnosticDescriptor Rule = diff --git a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzerWithCompilationWideAnalysis.cs b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzerWithCompilationWideAnalysis.cs index 41c1c8fd17a9f..d83c348bd16bc 100644 --- a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzerWithCompilationWideAnalysis.cs +++ b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzerWithCompilationWideAnalysis.cs @@ -33,7 +33,7 @@ namespace Sample.Analyzers public class CompilationStartedAnalyzerWithCompilationWideAnalysis : DiagnosticAnalyzer { private const string Title = "Secure types must not implement interfaces with unsecure methods"; - public const string MessageFormat = "Type '{0}' is a secure type as it implements interface '{1}', but it also implements interface '{2}' which has unsecure method(s)."; + public const string MessageFormat = "Type '{0}' is a secure type as it implements interface '{1}', but it also implements interface '{2}' which has unsecure method(s)"; private const string Description = "Secure types must not implement interfaces with unsecure methods."; internal static DiagnosticDescriptor Rule = diff --git a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CompilationAnalyzer.cs b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CompilationAnalyzer.cs index 6a4c61217bd23..f11f0da050835 100644 --- a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CompilationAnalyzer.cs +++ b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CompilationAnalyzer.cs @@ -21,7 +21,7 @@ namespace Sample.Analyzers public class CompilationAnalyzer : DiagnosticAnalyzer { private const string Title = "Dont suppress analyzer diagnostics"; - public const string MessageFormat = "Analyzer diagnostic '{0}' is suppressed, consider removing this compilation wide suppression."; + public const string MessageFormat = "Analyzer diagnostic '{0}' is suppressed, consider removing this compilation wide suppression"; private const string Description = "Dont suppress analyzer diagnostics."; internal static DiagnosticDescriptor Rule = diff --git a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/IOperationAnalyzer.cs b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/IOperationAnalyzer.cs index 5e58c61317bba..c606f5d0c5733 100644 --- a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/IOperationAnalyzer.cs +++ b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/IOperationAnalyzer.cs @@ -13,7 +13,7 @@ namespace Sample.Analyzers.StatelessAnalyzers public class IOperationAnalyzer : DiagnosticAnalyzer { private const string Title = "Reduce allocations and use Array.Empty"; - private const string MessageFormat = "Replace empty array allocation with Array.Empty."; + private const string MessageFormat = "Replace empty array allocation with Array.Empty"; private const string Description = "Reduce allocations and use Array.Empty."; internal static DiagnosticDescriptor Rule = diff --git a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SymbolAnalyzer.cs b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SymbolAnalyzer.cs index cd915a24ed7cd..ece3902610b68 100644 --- a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SymbolAnalyzer.cs +++ b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SymbolAnalyzer.cs @@ -20,7 +20,7 @@ namespace Sample.Analyzers public class SymbolAnalyzer : DiagnosticAnalyzer { private const string Title = "Do not declare members with same name as containing type"; - public const string MessageFormat = "Type '{0}' has one or more members with the same name, considering renaming the type or the members."; + public const string MessageFormat = "Type '{0}' has one or more members with the same name, considering renaming the type or the members"; private const string Description = "Do not declare members with same name as containing type."; internal static DiagnosticDescriptor Rule = diff --git a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxNodeAnalyzer.cs b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxNodeAnalyzer.cs index c4394b7a30280..a896931c7e2a3 100644 --- a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxNodeAnalyzer.cs +++ b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxNodeAnalyzer.cs @@ -21,7 +21,7 @@ namespace Sample.Analyzers [DiagnosticAnalyzer(LanguageNames.CSharp)] public class SyntaxNodeAnalyzer : DiagnosticAnalyzer { - private const string Title = "Declare explicit type for local declarations."; + private const string Title = "Declare explicit type for local declarations"; public const string MessageFormat = "Local '{0}' is implicitly typed. Consider specifying its type explicitly in the declaration."; private const string Description = "Declare explicit type for local declarations."; diff --git a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxTreeAnalyzer.cs b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxTreeAnalyzer.cs index 80ea06b116da7..9b3e3e08b4c8b 100644 --- a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxTreeAnalyzer.cs +++ b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxTreeAnalyzer.cs @@ -17,7 +17,7 @@ namespace Sample.Analyzers public class SyntaxTreeAnalyzer : DiagnosticAnalyzer { private const string Title = "Do not suppress documentation comment diagnostics"; - public const string MessageFormat = "Enable documentation comment diagnostics on source file '{0}'."; + public const string MessageFormat = "Enable documentation comment diagnostics on source file '{0}'"; private const string Description = "Do not suppress documentation comment diagnostics."; internal static DiagnosticDescriptor Rule = diff --git a/src/RoslynSdk/Samples/CSharp/CSharpToVisualBasicConverter/CSharpToVisualBasicConverter.Lib/Converting/Converter.NodeVisitor.cs b/src/RoslynSdk/Samples/CSharp/CSharpToVisualBasicConverter/CSharpToVisualBasicConverter.Lib/Converting/Converter.NodeVisitor.cs index b8686560ec1f0..8cf565afaf920 100644 --- a/src/RoslynSdk/Samples/CSharp/CSharpToVisualBasicConverter/CSharpToVisualBasicConverter.Lib/Converting/Converter.NodeVisitor.cs +++ b/src/RoslynSdk/Samples/CSharp/CSharpToVisualBasicConverter/CSharpToVisualBasicConverter.Lib/Converting/Converter.NodeVisitor.cs @@ -376,23 +376,6 @@ public override SyntaxNode VisitTypeParameterList(CS.Syntax.TypeParameterListSyn return VB.SyntaxFactory.TypeParameterList(parameters); } - private VB.Syntax.TypeParameterListSyntax ConvertTypeParameters(SeparatedSyntaxList list) - { - VB.Syntax.TypeParameterSyntax[] parameters = list.Select(t => - { - SyntaxToken variance = t.VarianceKeyword.IsKind(CS.SyntaxKind.None) - ? new SyntaxToken() - : t.VarianceKeyword.IsKind(CS.SyntaxKind.InKeyword) - ? VB.SyntaxFactory.Token(VB.SyntaxKind.InKeyword) - : VB.SyntaxFactory.Token(VB.SyntaxKind.OutKeyword); - - // TODO: get the constraints. - return VB.SyntaxFactory.TypeParameter(ConvertIdentifier(t.Identifier)).WithVarianceKeyword(variance); - }).ToArray(); - - return VB.SyntaxFactory.TypeParameterList(parameters); - } - public override SyntaxNode VisitNamespaceDeclaration(CS.Syntax.NamespaceDeclarationSyntax node) { return VB.SyntaxFactory.NamespaceBlock( diff --git a/src/RoslynSdk/Samples/CSharp/CSharpToVisualBasicConverter/CSharpToVisualBasicConverter.Lib/Converting/Converter.StatementVisitor.cs b/src/RoslynSdk/Samples/CSharp/CSharpToVisualBasicConverter/CSharpToVisualBasicConverter.Lib/Converting/Converter.StatementVisitor.cs index 221e34d872355..ae870ba1c3843 100644 --- a/src/RoslynSdk/Samples/CSharp/CSharpToVisualBasicConverter/CSharpToVisualBasicConverter.Lib/Converting/Converter.StatementVisitor.cs +++ b/src/RoslynSdk/Samples/CSharp/CSharpToVisualBasicConverter/CSharpToVisualBasicConverter.Lib/Converting/Converter.StatementVisitor.cs @@ -38,27 +38,6 @@ public StatementVisitor(NodeVisitor nodeVisitor, SourceText text) return Visit(node); } - private static VB.Syntax.StatementSyntax ConvertToStatement(SyntaxNode node) - { - if (node == null) - { - return null; - } - else if (node is VB.Syntax.StatementSyntax) - { - return (VB.Syntax.StatementSyntax)node; - } - else if (node is VB.Syntax.InvocationExpressionSyntax) - { - return VB.SyntaxFactory.ExpressionStatement((VB.Syntax.InvocationExpressionSyntax)node); - } - else - { - // can happen in error scenarios - return CreateBadStatement(((SyntaxNode)node).ToFullString(), typeof(VB.Syntax.StatementSyntax)); - } - } - public override SyntaxList VisitBlock(CS.Syntax.BlockSyntax node) { List statements = node.Statements.SelectMany(VisitStatementEnumerable).ToList(); diff --git a/src/RoslynSdk/Samples/CSharp/ConsoleClassifier/Program.cs b/src/RoslynSdk/Samples/CSharp/ConsoleClassifier/Program.cs index a367b6c3286cb..759ca174d17dc 100644 --- a/src/RoslynSdk/Samples/CSharp/ConsoleClassifier/Program.cs +++ b/src/RoslynSdk/Samples/CSharp/ConsoleClassifier/Program.cs @@ -28,10 +28,10 @@ static void Main() WriteLine(""Hello, World!""); } }"); - document = await Formatter.FormatAsync(document); - SourceText text = await document.GetTextAsync(); + document = await Formatter.FormatAsync(document).ConfigureAwait(false); + SourceText text = await document.GetTextAsync().ConfigureAwait(false); - IEnumerable classifiedSpans = await Classifier.GetClassifiedSpansAsync(document, TextSpan.FromBounds(0, text.Length)); + IEnumerable classifiedSpans = await Classifier.GetClassifiedSpansAsync(document, TextSpan.FromBounds(0, text.Length)).ConfigureAwait(false); Console.BackgroundColor = ConsoleColor.Black; IEnumerable ranges = classifiedSpans.Select(classifiedSpan => diff --git a/src/RoslynSdk/Samples/CSharp/ConvertToAutoProperty/ConvertToAutoProperty.Implementation/ConvertToAutoPropertyCodeRefactoringProvider.cs b/src/RoslynSdk/Samples/CSharp/ConvertToAutoProperty/ConvertToAutoProperty.Implementation/ConvertToAutoPropertyCodeRefactoringProvider.cs index cd6070acf6889..91ebd89901911 100644 --- a/src/RoslynSdk/Samples/CSharp/ConvertToAutoProperty/ConvertToAutoProperty.Implementation/ConvertToAutoPropertyCodeRefactoringProvider.cs +++ b/src/RoslynSdk/Samples/CSharp/ConvertToAutoProperty/ConvertToAutoProperty.Implementation/ConvertToAutoPropertyCodeRefactoringProvider.cs @@ -46,7 +46,6 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex (c) => ConvertToAutoPropertyAsync(document, propertyDeclaration, c))); } - /// /// Returns true if both get and set accessors exist on the given property; otherwise false. /// @@ -74,7 +73,7 @@ private async Task ConvertToAutoPropertyAsync(Document document, Prope AccessorDeclarationSyntax getter = property.AccessorList.Accessors.FirstOrDefault(ad => ad.Kind() == SyntaxKind.GetAccessorDeclaration); // Retrieves the type that contains the specified property - INamedTypeSymbol containingType = semanticModel.GetDeclaredSymbol(property).ContainingType; + INamedTypeSymbol containingType = semanticModel.GetDeclaredSymbol(property, cancellationToken).ContainingType; // Find the backing field of the property ISymbol backingField = await GetBackingFieldAsync(document, getter, containingType, cancellationToken).ConfigureAwait(false); @@ -95,7 +94,7 @@ private async Task GetBackingFieldAsync(Document document, AccessorDecl if (statements.FirstOrDefault() is ReturnStatementSyntax returnStatement && returnStatement.Expression != null) { SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); - SymbolInfo symbolInfo = semanticModel.GetSymbolInfo(returnStatement.Expression); + SymbolInfo symbolInfo = semanticModel.GetSymbolInfo(returnStatement.Expression, cancellationToken); if (symbolInfo.Symbol is IFieldSymbol fieldSymbol && Equals(fieldSymbol.OriginalDefinition.ContainingType, containingType)) { diff --git a/src/RoslynSdk/Samples/CSharp/ConvertToAutoProperty/ConvertToAutoProperty.Implementation/PropertyRewriter.cs b/src/RoslynSdk/Samples/CSharp/ConvertToAutoProperty/ConvertToAutoProperty.Implementation/PropertyRewriter.cs index 4dbf16284e176..fe06a85ab461e 100644 --- a/src/RoslynSdk/Samples/CSharp/ConvertToAutoProperty/ConvertToAutoProperty.Implementation/PropertyRewriter.cs +++ b/src/RoslynSdk/Samples/CSharp/ConvertToAutoProperty/ConvertToAutoProperty.Implementation/PropertyRewriter.cs @@ -7,7 +7,6 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Formatting; - namespace ConvertToAutoProperty { internal class PropertyRewriter : CSharpSyntaxRewriter diff --git a/src/RoslynSdk/Samples/CSharp/ConvertToConditional/ConvertToConditional.Implementation/ConvertToConditionalCodeRefactoringProvider.cs b/src/RoslynSdk/Samples/CSharp/ConvertToConditional/ConvertToConditional.Implementation/ConvertToConditionalCodeRefactoringProvider.cs index 560dbabd84155..9785456835a88 100644 --- a/src/RoslynSdk/Samples/CSharp/ConvertToConditional/ConvertToConditional.Implementation/ConvertToConditionalCodeRefactoringProvider.cs +++ b/src/RoslynSdk/Samples/CSharp/ConvertToConditional/ConvertToConditional.Implementation/ConvertToConditionalCodeRefactoringProvider.cs @@ -58,7 +58,7 @@ private Document ConvertToConditional(Document document, StatementSyntax replacementStatement, CancellationToken cancellationToken) { - SyntaxNode oldRoot = semanticModel.SyntaxTree.GetRoot(); + SyntaxNode oldRoot = semanticModel.SyntaxTree.GetRoot(cancellationToken); SyntaxNode newRoot = oldRoot.ReplaceNode( oldNode: ifStatement, newNode: replacementStatement.WithAdditionalAnnotations(Formatter.Annotation)); diff --git a/src/RoslynSdk/Samples/CSharp/FormatSolution/Program.cs b/src/RoslynSdk/Samples/CSharp/FormatSolution/Program.cs index 590c14ce4438f..7868f7d8af5e5 100644 --- a/src/RoslynSdk/Samples/CSharp/FormatSolution/Program.cs +++ b/src/RoslynSdk/Samples/CSharp/FormatSolution/Program.cs @@ -21,7 +21,7 @@ static async Task Main(string[] args) MSBuildWorkspace workspace = MSBuildWorkspace.Create(); // Open the solution within the workspace. - Solution originalSolution = await workspace.OpenSolutionAsync(args[0]); + Solution originalSolution = await workspace.OpenSolutionAsync(args[0]).ConfigureAwait(false); // Declare a variable to store the intermediate solution snapshot at each step. Solution newSolution = originalSolution; @@ -42,7 +42,7 @@ static async Task Main(string[] args) // Get a transformed version of the document (a new solution snapshot is created // under the covers to contain it - none of the existing objects are modified). - Document newDocument = await Formatter.FormatAsync(document); + Document newDocument = await Formatter.FormatAsync(document).ConfigureAwait(false); // Store the solution implicitly constructed in the previous step as the latest // one so we can continue building it up in the next iteration. diff --git a/src/RoslynSdk/Samples/CSharp/RefOutModifier/RefOutModifier.Implementation/ApplicableActionFinder.cs b/src/RoslynSdk/Samples/CSharp/RefOutModifier/RefOutModifier.Implementation/ApplicableActionFinder.cs index f70e2d4bef7d3..67a9a986c61c5 100644 --- a/src/RoslynSdk/Samples/CSharp/RefOutModifier/RefOutModifier.Implementation/ApplicableActionFinder.cs +++ b/src/RoslynSdk/Samples/CSharp/RefOutModifier/RefOutModifier.Implementation/ApplicableActionFinder.cs @@ -17,7 +17,7 @@ namespace Roslyn.Samples.AddOrRemoveRefOutModifier { internal class ApplicableActionFinder { - private Document document; + private readonly Document document; private readonly int position; private readonly CancellationToken cancellationToken; @@ -128,7 +128,7 @@ private async Task GetArgumentAsync(IMethodSymbol methodSymbol, InvocationExpressionSyntax invocation = result.Single() .Locations - .Cast() + .Select(location => location.Location) .Select(l => l.FindToken().AncestorAndSelf()) .Single(); diff --git a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Framework/NotifyTaskCompletion.cs b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Framework/NotifyTaskCompletion.cs index c55b931e6c2b5..f3c49fa8a0d02 100644 --- a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Framework/NotifyTaskCompletion.cs +++ b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Framework/NotifyTaskCompletion.cs @@ -36,7 +36,7 @@ public NotifyTaskCompletion(Task task) private async Task WatchTaskAsync(Task task) { - await task; + await task.ConfigureAwait(true); PropertyChangedEventHandler handler = PropertyChanged; if (handler == null) diff --git a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Framework/ViewModel_CommandBindings.cs b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Framework/ViewModel_CommandBindings.cs index 45914c919def0..9dad98039ea08 100644 --- a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Framework/ViewModel_CommandBindings.cs +++ b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Framework/ViewModel_CommandBindings.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Threading.Tasks; using System.Windows; using System.Windows.Input; @@ -48,6 +49,18 @@ protected ICommand RegisterCommand(string text, string name, Action executed, Fu canExecute: (s, e) => e.CanExecute = canExecute()); } + protected ICommand RegisterCommand(string text, string name, Func executed, Func canExecute, params InputGesture[] inputGestures) + { +#pragma warning disable VSTHRD100 // WPF command handlers must return void. + async void OnExecuted(object sender, ExecutedRoutedEventArgs e) + => await executed().ConfigureAwait(true); +#pragma warning restore VSTHRD100 + + return RegisterCommand(text, name, inputGestures, + executed: OnExecuted, + canExecute: (s, e) => e.CanExecute = canExecute()); + } + protected ICommand RegisterCommand(string text, string name, Action executed, Func canExecute, params InputGesture[] inputGestures) { T cast(object x) => x != null ? (T)x : default; diff --git a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Properties/AssemblyInfo.cs b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Properties/AssemblyInfo.cs index 24a47e23f7835..95a1a332197c7 100644 --- a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Properties/AssemblyInfo.cs +++ b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Properties/AssemblyInfo.cs @@ -25,7 +25,6 @@ //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - [assembly: ThemeInfo( ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located //(used if a resource is not found in the page, diff --git a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Services/WorkspaceService.cs b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Services/WorkspaceService.cs index 7570f17873849..c3a357bc673e6 100644 --- a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Services/WorkspaceService.cs +++ b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/Services/WorkspaceService.cs @@ -49,7 +49,7 @@ public async Task OpenSolutionAsync(string solutionFilePath) LogHeader(); Stopwatch watch = Stopwatch.StartNew(); - Solution solution = await Workspace.OpenSolutionAsync(solutionFilePath, new LoaderProgress(Logger)); + Solution solution = await Workspace.OpenSolutionAsync(solutionFilePath, new LoaderProgress(Logger)).ConfigureAwait(false); watch.Stop(); Logger.LogInformation($"\r\nSolution opened: {watch.Elapsed:m\\:ss\\.fffffff}"); @@ -60,7 +60,7 @@ public async Task OpenProjectAsync(string projectFilePath) LogHeader(); Stopwatch watch = Stopwatch.StartNew(); - Project project = await Workspace.OpenProjectAsync(projectFilePath, new LoaderProgress(Logger)); + Project project = await Workspace.OpenProjectAsync(projectFilePath, new LoaderProgress(Logger)).ConfigureAwait(false); watch.Stop(); Logger.LogInformation($"\r\nProject opened: {watch.Elapsed:m\\:ss\\.fffffff}"); diff --git a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/DocumentViewModel.cs b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/DocumentViewModel.cs index 07ba7bc3aed1b..7a0ebd5b512db 100644 --- a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/DocumentViewModel.cs +++ b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/DocumentViewModel.cs @@ -28,7 +28,7 @@ public string Language public async Task GetSourceTextAsync() { - Microsoft.CodeAnalysis.Text.SourceText text = await GetDocument().GetTextAsync(); + Microsoft.CodeAnalysis.Text.SourceText text = await GetDocument().GetTextAsync().ConfigureAwait(false); return text.ToString(); } diff --git a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/HierarchyItemViewModel.cs b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/HierarchyItemViewModel.cs index 95159fd033fb6..73e01834f18a5 100644 --- a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/HierarchyItemViewModel.cs +++ b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/HierarchyItemViewModel.cs @@ -13,7 +13,7 @@ internal abstract class HierarchyItemViewModel : ViewModel, IComparable _children; + private readonly ObservableCollection _children; public ReadOnlyObservableCollection Children { get; } protected HierarchyItemViewModel(Workspace workspace, bool isExpanded = true) diff --git a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/MainWindowViewModel.cs b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/MainWindowViewModel.cs index fc9fb57e4c4b0..9999b243544a4 100644 --- a/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/MainWindowViewModel.cs +++ b/src/RoslynSdk/Samples/CSharp/SolutionExplorer/ViewModels/MainWindowViewModel.cs @@ -42,7 +42,7 @@ public MainWindowViewModel(IServiceProvider serviceProvider) OpenProjectCommand = RegisterCommand( text: "Open Project/Solution", name: "Open Project/Solution", - executed: OpenProjectExecuted, + executed: OpenProjectExecutedAsync, canExecute: CanOpenProjectExecute); OpenFileCommand = RegisterCommand( @@ -65,7 +65,7 @@ protected override void OnViewCreated(Window view) private bool CanOpenProjectExecute() => true; - private async void OpenProjectExecuted() + private async System.Threading.Tasks.Task OpenProjectExecutedAsync() { OpenFileDialog dialog = new OpenFileDialog { @@ -86,11 +86,11 @@ private async void OpenProjectExecuted() switch (extension) { case ".sln": - await _workspaceService.OpenSolutionAsync(fileName); + await _workspaceService.OpenSolutionAsync(fileName).ConfigureAwait(true); break; default: - await _workspaceService.OpenProjectAsync(fileName); + await _workspaceService.OpenProjectAsync(fileName).ConfigureAwait(true); break; } diff --git a/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/AutoNotifyGenerator.cs b/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/AutoNotifyGenerator.cs index d70790d4134be..e464bc864a3a3 100644 --- a/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/AutoNotifyGenerator.cs +++ b/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/AutoNotifyGenerator.cs @@ -34,7 +34,6 @@ public AutoNotifyAttribute() } "; - public void Initialize(GeneratorInitializationContext context) { // Register the attribute source diff --git a/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/CsvGenerator.cs b/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/CsvGenerator.cs index 8f71c36b6b573..be6fbe4a88fb3 100644 --- a/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/CsvGenerator.cs +++ b/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/CsvGenerator.cs @@ -77,7 +77,6 @@ namespace CSV { //// Class Definition sb.Append($" public class {className} {{\n"); - if (loadTime == CsvLoadType.Startup) { sb.Append(@$" @@ -137,7 +136,6 @@ public static IEnumerable<{className}> All {{ } - static string StringToValidPropertyName(string s) { s = s.Trim(); diff --git a/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/MathsGenerator.cs b/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/MathsGenerator.cs index 13175df93e67d..6deb751d2b535 100644 --- a/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/MathsGenerator.cs +++ b/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/MathsGenerator.cs @@ -55,7 +55,7 @@ public static void PrintTokens(IEnumerable tokens) } } - static (TokenType, string)[] tokenStrings = { + private static readonly (TokenType, string)[] tokenStrings = { (TokenType.EOL, @"(\r\n|\r|\n)"), (TokenType.Spaces, @"\s+"), (TokenType.Number, @"[+-]?((\d+\.?\d*)|(\.\d+))"), @@ -68,12 +68,12 @@ public static void PrintTokens(IEnumerable tokens) (TokenType.Sum, @"∑") }; - static IEnumerable<(TokenType, Regex)> tokenExpressions = + private static readonly IEnumerable<(TokenType, Regex)> tokenExpressions = tokenStrings.Select( t => (t.Item1, new Regex($"^{t.Item2}", RegexOptions.Compiled | RegexOptions.Singleline))); // Can be optimized with spans to avoid so many allocations ... - static public Tokens Tokenize(string source) + public static Tokens Tokenize(string source) { var currentLine = 1; var currentColumn = 1; @@ -149,7 +149,6 @@ static public Tokens Tokenize(string source) public static class Parser { - public static string Parse(Tokens tokens) { var globalSymbolTable = new SymTable(); @@ -170,7 +169,7 @@ public static string Parse(Tokens tokens) } - private readonly static string Preamble = @" + private const string Preamble = @" using static System.Math; using static Maths.FormulaHelpers; @@ -178,7 +177,7 @@ namespace Maths { public static partial class Formulas { "; - private readonly static string Ending = @" + private const string Ending = @" } }"; @@ -193,10 +192,10 @@ private struct Context private static StringBuilder Error(Token token, TokenType type, string value = "") => throw new Exception($"Expected {type} {(value == "" ? "" : $" with {token.Value}")} at {token.Line},{token.Column} Instead found {token.Type} with value {token.Value}"); - static HashSet validFunctions = + private static readonly HashSet validFunctions = new HashSet(typeof(System.Math).GetMethods().Select(m => m.Name.ToLower())); - static Dictionary replacementStrings = new Dictionary { + private static readonly Dictionary replacementStrings = new Dictionary { {"'''", "Third" }, {"''", "Second" }, {"'", "Prime"} }; @@ -365,9 +364,9 @@ private static void Args(Context ctx) Consume(ctx, TokenType.Identifier); } } - private static Func IsOp = (ctx, op) + private static readonly Func IsOp = (ctx, op) => Peek(ctx, TokenType.Operation, op); - private static Action ConsOp = (ctx, op) + private static readonly Action ConsOp = (ctx, op) => Consume(ctx, TokenType.Operation, op); private static void Expr(Context ctx) @@ -530,4 +529,3 @@ public void Initialize(GeneratorInitializationContext context) } } } - diff --git a/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/SettingsXmlGenerator.cs b/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/SettingsXmlGenerator.cs index 5b1e705146466..6fd9d00f46197 100644 --- a/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/SettingsXmlGenerator.cs +++ b/src/RoslynSdk/Samples/CSharp/SourceGenerators/SourceGeneratorSamples/SettingsXmlGenerator.cs @@ -43,7 +43,6 @@ private void ProcessSettingsFile(AdditionalText xmlFile, GeneratorExecutionConte return; } - // create a class in the XmlSetting class that represnts this entry, and a static field that contains a singleton instance. string fileName = Path.GetFileName(xmlFile.Path); string name = xmlDoc.DocumentElement.GetAttribute("name"); diff --git a/src/RoslynSdk/Samples/CSharp/TreeTransforms/Transforms.cs b/src/RoslynSdk/Samples/CSharp/TreeTransforms/Transforms.cs index fb88955096b46..a16c85e622bb5 100644 --- a/src/RoslynSdk/Samples/CSharp/TreeTransforms/Transforms.cs +++ b/src/RoslynSdk/Samples/CSharp/TreeTransforms/Transforms.cs @@ -38,7 +38,7 @@ public enum TransformKind IntTypeToLongType, } - public class Transforms + public static class Transforms { /// /// Performs a syntax transform of the source code which is passed in as a string. The transform to be performed is also passed as an argument diff --git a/src/RoslynSdk/Samples/Directory.Build.props b/src/RoslynSdk/Samples/Directory.Build.props index 71550821dd9ad..170bfb3fa0890 100644 --- a/src/RoslynSdk/Samples/Directory.Build.props +++ b/src/RoslynSdk/Samples/Directory.Build.props @@ -16,9 +16,9 @@ - + disable true false false diff --git a/src/RoslynSdk/Samples/Directory.Packages.props b/src/RoslynSdk/Samples/Directory.Packages.props index 797a0357b97ac..b93b46f597493 100644 --- a/src/RoslynSdk/Samples/Directory.Packages.props +++ b/src/RoslynSdk/Samples/Directory.Packages.props @@ -6,5 +6,7 @@ + + diff --git a/src/RoslynSdk/Samples/VisualBasic/APISamples/FAQ.vb b/src/RoslynSdk/Samples/VisualBasic/APISamples/FAQ.vb index f90e34f84a817..0f4413f4b89bf 100644 --- a/src/RoslynSdk/Samples/VisualBasic/APISamples/FAQ.vb +++ b/src/RoslynSdk/Samples/VisualBasic/APISamples/FAQ.vb @@ -34,7 +34,6 @@ Namespace APISampleUnitTestsVB End Sub End Class - Private _Mscorlib As MetadataReference Public ReadOnly Property Mscorlib As MetadataReference @@ -1487,7 +1486,7 @@ i (position 0).Value, results) End Function End Class - Public Class MyAnnotation + Public NotInheritable Class MyAnnotation Public Const Kind As String = "MyAnnotation" Public Shared Function Create(position As Integer) As SyntaxAnnotation diff --git a/src/RoslynSdk/Samples/VisualBasic/APISamples/SymbolsAndSemantics.vb b/src/RoslynSdk/Samples/VisualBasic/APISamples/SymbolsAndSemantics.vb index 3b1f009cdd646..ecf4118206755 100644 --- a/src/RoslynSdk/Samples/VisualBasic/APISamples/SymbolsAndSemantics.vb +++ b/src/RoslynSdk/Samples/VisualBasic/APISamples/SymbolsAndSemantics.vb @@ -144,11 +144,10 @@ Class Cat End Class .GetCode() - Dim comp = VisualBasicCompilation.Create( - "test", - syntaxTrees:={SyntaxFactory.ParseSyntaxTree(file1), SyntaxFactory.ParseSyntaxTree(file2)}, - references:={MetadataReference.CreateFromFile(GetType(Object).Assembly.Location)}) + "test", + syntaxTrees:={SyntaxFactory.ParseSyntaxTree(file1), SyntaxFactory.ParseSyntaxTree(file2)}, + references:={MetadataReference.CreateFromFile(GetType(Object).Assembly.Location)}) Dim globalNamespace = comp.SourceModule.GlobalNamespace diff --git a/src/RoslynSdk/Samples/VisualBasic/APISamples/SyntaxTrees.vb b/src/RoslynSdk/Samples/VisualBasic/APISamples/SyntaxTrees.vb index 92110b7df1d34..2a896ad61f28c 100644 --- a/src/RoslynSdk/Samples/VisualBasic/APISamples/SyntaxTrees.vb +++ b/src/RoslynSdk/Samples/VisualBasic/APISamples/SyntaxTrees.vb @@ -151,7 +151,6 @@ End Class End Function End Class - Public Sub TransformTreeUsingSyntaxRewriter() Dim code = diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/SimpleAdditionalFileAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/SimpleAdditionalFileAnalyzer.vb index d49acb4cab409..99bdebacdc863 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/SimpleAdditionalFileAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/SimpleAdditionalFileAnalyzer.vb @@ -21,7 +21,7 @@ Namespace BasicAnalyzers Inherits DiagnosticAnalyzer Private Const Title As String = "Type name contains invalid term" - Private Const MessageFormat As String = "The term '{0}' is not allowed in a type name." + Private Const MessageFormat As String = "The term '{0}' is not allowed in a type name" Private Shared ReadOnly Rule As DiagnosticDescriptor = New DiagnosticDescriptor( @@ -39,6 +39,8 @@ Namespace BasicAnalyzers End Property Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterCompilationStartAction( Sub(compilationStartContext) ' Find the additional file with the terms. diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/XmlAdditionalFileAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/XmlAdditionalFileAnalyzer.vb index dc89b0b8d7d05..9b6e76079a55c 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/XmlAdditionalFileAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/AdditionalFileAnalyzers/XmlAdditionalFileAnalyzer.vb @@ -22,7 +22,7 @@ Namespace BasicAnalyzers Inherits DiagnosticAnalyzer Private Const Title As String = "Type name contains invalid term" - Private Const MessageFormat As String = "The term '{0}' is not allowed in a type name." + Private Const MessageFormat As String = "The term '{0}' is not allowed in a type name" Private Shared ReadOnly Rule As DiagnosticDescriptor = New DiagnosticDescriptor( @@ -40,6 +40,8 @@ Namespace BasicAnalyzers End Property Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterCompilationStartAction( Sub(compilationStartContext) ' Find the additional file with the terms. diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.vb index d01f98f123865..355a1b310fd0a 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.vb @@ -26,7 +26,7 @@ Namespace BasicAnalyzers #Region "Descriptor fields" Friend Shared ReadOnly Title As LocalizableString = "Remove unused parameters" - Friend Shared ReadOnly MessageFormat As LocalizableString = "Parameter '{0}' is unused in the method '{1}'." + Friend Shared ReadOnly MessageFormat As LocalizableString = "Parameter '{0}' is unused in the method '{1}'" Friend Shared ReadOnly Description As LocalizableString = "Remove unused parameters." Friend Shared Rule As New DiagnosticDescriptor(DiagnosticIds.CodeBlockStartedAnalyzerRuleId, Title, MessageFormat, DiagnosticCategories.Stateful, DiagnosticSeverity.Warning, isEnabledByDefault:=True, description:=Description) @@ -39,6 +39,8 @@ Namespace BasicAnalyzers End Property Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterCodeBlockStartAction(Of SyntaxKind)( Sub(startCodeBlockContext) ' We only care about method bodies. diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzer.vb index afc541ed4c5d3..0c251ab4cd803 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzer.vb @@ -38,6 +38,8 @@ Namespace BasicAnalyzers End Property Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterCompilationStartAction( Sub(compilationContext) ' We only care about compilations where interface type "DontInheritInterfaceTypeName" is available. diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzerWithCompilationWideAnalysis.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzerWithCompilationWideAnalysis.vb index 3747699bbe896..71571bb533086 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzerWithCompilationWideAnalysis.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CompilationStartedAnalyzerWithCompilationWideAnalysis.vb @@ -32,7 +32,7 @@ Namespace BasicAnalyzers #Region "Descriptor fields" Friend Shared ReadOnly Title As LocalizableString = "Secure types must not implement interfaces with unsecure methods" - Friend Shared ReadOnly MessageFormat As LocalizableString = "Type '{0}' is a secure type as it implements interface '{1}', but it also implements interface '{2}' which has unsecure method(s)." + Friend Shared ReadOnly MessageFormat As LocalizableString = "Type '{0}' is a secure type as it implements interface '{1}', but it also implements interface '{2}' which has unsecure method(s)" Friend Shared ReadOnly Description As LocalizableString = "Secure types must not implement interfaces with unsecure methods." Friend Shared Rule As New DiagnosticDescriptor(DiagnosticIds.CompilationStartedAnalyzerWithCompilationWideAnalysisRuleId, Title, MessageFormat, DiagnosticCategories.Stateful, DiagnosticSeverity.Warning, isEnabledByDefault:=True, description:=Description, Nothing, WellKnownDiagnosticTags.CompilationEnd) @@ -48,6 +48,8 @@ Namespace BasicAnalyzers End Property Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterCompilationStartAction( Sub(compilationContext) ' Check if the attribute type marking unsecure methods is defined. @@ -84,12 +86,12 @@ Namespace BasicAnalyzers ''' ''' List of secure types in the compilation implementing interface . ''' - Private _secureTypes As List(Of INamedTypeSymbol) + Private ReadOnly _secureTypes As New List(Of INamedTypeSymbol) ''' ''' Set of unsecure interface types in the compilation that have methods with an attribute of . ''' - Private _interfacesWithUnsecureMethods As HashSet(Of INamedTypeSymbol) + Private ReadOnly _interfacesWithUnsecureMethods As New HashSet(Of INamedTypeSymbol) #End Region #Region "State intialization" @@ -97,8 +99,6 @@ Namespace BasicAnalyzers _unsecureMethodAttributeType = unsecureMethodAttributeType _secureTypeInterfaceType = secureTypeInterfaceType - _secureTypes = Nothing - _interfacesWithUnsecureMethods = Nothing End Sub #End Region @@ -109,8 +109,9 @@ Namespace BasicAnalyzers ' Check if the symbol implements "_secureTypeInterfaceType". Dim namedType = DirectCast(context.Symbol, INamedTypeSymbol) If namedType.AllInterfaces.Contains(_secureTypeInterfaceType) Then - _secureTypes = If(_secureTypes, New List(Of INamedTypeSymbol)()) - _secureTypes.Add(namedType) + SyncLock _secureTypes + _secureTypes.Add(namedType) + End SyncLock End If Exit Select @@ -120,8 +121,9 @@ Namespace BasicAnalyzers Dim method = DirectCast(context.Symbol, IMethodSymbol) If method.ContainingType.TypeKind = TypeKind.Interface AndAlso method.GetAttributes().Any(Function(a) a.AttributeClass.Equals(_unsecureMethodAttributeType)) Then - _interfacesWithUnsecureMethods = If(_interfacesWithUnsecureMethods, New HashSet(Of INamedTypeSymbol)()) - _interfacesWithUnsecureMethods.Add(method.ContainingType) + SyncLock _interfacesWithUnsecureMethods + _interfacesWithUnsecureMethods.Add(method.ContainingType) + End SyncLock End If Exit Select @@ -131,7 +133,7 @@ Namespace BasicAnalyzers #Region "End action" Public Sub CompilationEndAction(context As CompilationAnalysisContext) - If _interfacesWithUnsecureMethods Is Nothing OrElse _secureTypes Is Nothing Then + If _interfacesWithUnsecureMethods.Count = 0 OrElse _secureTypes.Count = 0 Then ' No violating types. Return End If diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CodeBlockAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CodeBlockAnalyzer.vb index 8c9b4df64e291..fb6090f4a95ce 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CodeBlockAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CodeBlockAnalyzer.vb @@ -34,6 +34,8 @@ Namespace BasicAnalyzers End Property Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterCodeBlockAction(AddressOf CodeBlockAction) End Sub diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CompilationAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CompilationAnalyzer.vb index 5eb42fcfa83e9..815f5f4c20731 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CompilationAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/CompilationAnalyzer.vb @@ -20,7 +20,7 @@ Namespace BasicAnalyzers #Region "Descriptor fields" Friend Shared ReadOnly Title As LocalizableString = "Dont suppress analyzer diagnostics" - Friend Shared ReadOnly MessageFormat As LocalizableString = "Analyzer diagnostic '{0}' is suppressed, consider removing this compilation wide suppression." + Friend Shared ReadOnly MessageFormat As LocalizableString = "Analyzer diagnostic '{0}' is suppressed, consider removing this compilation wide suppression" Friend Shared ReadOnly Description As LocalizableString = "Do not suppress analyzer diagnostics." Friend Shared Rule As New DiagnosticDescriptor(DiagnosticIds.CompilationAnalyzerRuleId, Title, MessageFormat, DiagnosticCategories.Stateless, DiagnosticSeverity.Warning, isEnabledByDefault:=True, description:=Description, Nothing, WellKnownDiagnosticTags.CompilationEnd) @@ -33,6 +33,8 @@ Namespace BasicAnalyzers End Property Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterCompilationAction(AddressOf AnalyzeCompilation) End Sub diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SemanticModelAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SemanticModelAnalyzer.vb index d01efb9c9378f..b1a5fecfbc2f9 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SemanticModelAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SemanticModelAnalyzer.vb @@ -18,7 +18,7 @@ Namespace BasicAnalyzers #Region "Descriptor fields" Friend Shared ReadOnly Title As LocalizableString = "Source file declaration diagnostics count" - Friend Shared ReadOnly MessageFormat As LocalizableString = "Source file '{0}' has '{1}' declaration diagnostic(s)." + Friend Shared ReadOnly MessageFormat As LocalizableString = "Source file '{0}' has '{1}' declaration diagnostic(s)" Friend Shared ReadOnly Description As LocalizableString = "Source file declaration diagnostic count." Friend Shared Rule As New DiagnosticDescriptor(DiagnosticIds.SemanticModelAnalyzerRuleId, Title, MessageFormat, DiagnosticCategories.Stateless, DiagnosticSeverity.Warning, isEnabledByDefault:=True, description:=Description) @@ -31,6 +31,8 @@ Namespace BasicAnalyzers End Property Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterSemanticModelAction(AddressOf AnalyzeSemanticModel) End Sub diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SymbolAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SymbolAnalyzer.vb index c6ae3b37918db..d364c240dc490 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SymbolAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SymbolAnalyzer.vb @@ -20,7 +20,7 @@ Namespace BasicAnalyzers #Region "Descriptor fields" Friend Shared ReadOnly Title As LocalizableString = "Do not declare members with same name as containing type" - Friend Shared ReadOnly MessageFormat As LocalizableString = "Type '{0}' has one or more members with the same name, considering renaming the type or the members." + Friend Shared ReadOnly MessageFormat As LocalizableString = "Type '{0}' has one or more members with the same name, considering renaming the type or the members" Friend Shared ReadOnly Description As LocalizableString = "Do not declare members with same name as containing type." Friend Shared Rule As New DiagnosticDescriptor(DiagnosticIds.SymbolAnalyzerRuleId, Title, MessageFormat, DiagnosticCategories.Stateless, DiagnosticSeverity.Warning, isEnabledByDefault:=True, description:=Description) @@ -33,6 +33,8 @@ Namespace BasicAnalyzers End Property Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterSymbolAction(AddressOf AnalyzeSymbol, SymbolKind.NamedType) End Sub diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxNodeAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxNodeAnalyzer.vb index e3caee9d78d9b..05f121560f8b0 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxNodeAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxNodeAnalyzer.vb @@ -36,6 +36,8 @@ Namespace BasicAnalyzers End Property Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterSyntaxNodeAction(AddressOf AnalyzeSyntaxNode, SyntaxKind.VariableDeclarator) End Sub diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxTreeAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxTreeAnalyzer.vb index 2d5bce9ae4609..130078325636a 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxTreeAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatelessAnalyzers/SyntaxTreeAnalyzer.vb @@ -18,7 +18,7 @@ Namespace BasicAnalyzers #Region "Descriptor fields" Friend Shared ReadOnly Title As LocalizableString = "Do not suppress documentation comment diagnostics" - Friend Shared ReadOnly MessageFormat As LocalizableString = "Enable documentation comment diagnostics on source file '{0}'." + Friend Shared ReadOnly MessageFormat As LocalizableString = "Enable documentation comment diagnostics on source file '{0}'" Friend Shared ReadOnly Description As LocalizableString = "Do not suppress documentation comment diagnostics." Friend Shared Rule As New DiagnosticDescriptor(DiagnosticIds.SyntaxTreeAnalyzerRuleId, Title, MessageFormat, DiagnosticCategories.Stateless, DiagnosticSeverity.Warning, isEnabledByDefault:=True, description:=Description) @@ -31,6 +31,8 @@ Namespace BasicAnalyzers End Property Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterSyntaxTreeAction(AddressOf AnalyzeSyntaxTree) End Sub diff --git a/src/RoslynSdk/Samples/VisualBasic/ConsoleClassifier/Program.vb b/src/RoslynSdk/Samples/VisualBasic/ConsoleClassifier/Program.vb index 4af7228e91041..cb5a4c3230b9d 100644 --- a/src/RoslynSdk/Samples/VisualBasic/ConsoleClassifier/Program.vb +++ b/src/RoslynSdk/Samples/VisualBasic/ConsoleClassifier/Program.vb @@ -23,10 +23,10 @@ Sub Main() WriteLine(""Hello, World!"") End Sub End Module") - document = Await Formatter.FormatAsync(document) - Dim text As SourceText = Await document.GetTextAsync() + document = Await Formatter.FormatAsync(document).ConfigureAwait(False) + Dim text As SourceText = Await document.GetTextAsync().ConfigureAwait(False) - Dim classifiedSpans As IEnumerable(Of ClassifiedSpan) = Await Classifier.GetClassifiedSpansAsync(document, TextSpan.FromBounds(0, text.Length)) + Dim classifiedSpans As IEnumerable(Of ClassifiedSpan) = Await Classifier.GetClassifiedSpansAsync(document, TextSpan.FromBounds(0, text.Length)).ConfigureAwait(False) Console.BackgroundColor = ConsoleColor.Black Dim ranges = From span As ClassifiedSpan In classifiedSpans diff --git a/src/RoslynSdk/Samples/VisualBasic/ConvertToAutoProperty/ConvertToAutoProperty/CodeRefactoringProvider.vb b/src/RoslynSdk/Samples/VisualBasic/ConvertToAutoProperty/ConvertToAutoProperty/CodeRefactoringProvider.vb index c76b877862ac1..3a6e4f04c97ae 100644 --- a/src/RoslynSdk/Samples/VisualBasic/ConvertToAutoProperty/ConvertToAutoProperty/CodeRefactoringProvider.vb +++ b/src/RoslynSdk/Samples/VisualBasic/ConvertToAutoProperty/ConvertToAutoProperty/CodeRefactoringProvider.vb @@ -66,7 +66,7 @@ Class ConvertToAutoPropertyCodeRefactoringProvider Dim backingField = Await GetBackingFieldAsync(document, propertyAnnotation, cancellationToken).ConfigureAwait(False) ' Retrieve the initializer of the backing field - Dim modifiedIdentifier = CType(backingField.DeclaringSyntaxReferences.Single().GetSyntax(), ModifiedIdentifierSyntax) + Dim modifiedIdentifier = CType(backingField.DeclaringSyntaxReferences.Single().GetSyntax(cancellationToken), ModifiedIdentifierSyntax) Dim variableDeclarator = CType(modifiedIdentifier.Parent, VariableDeclaratorSyntax) Dim initializer = variableDeclarator.Initializer @@ -93,14 +93,14 @@ Class ConvertToAutoPropertyCodeRefactoringProvider Dim propertyGetter = propertyBlock.Accessors.FirstOrDefault(Function(node) node.Kind() = SyntaxKind.GetAccessorBlock) Dim semanticModel = Await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(False) - Dim containingType = semanticModel.GetDeclaredSymbol(propertyBlock).ContainingType + Dim containingType = semanticModel.GetDeclaredSymbol(propertyBlock, cancellationToken).ContainingType Dim statements = propertyGetter.Statements If statements.Count = 1 Then Dim returnStatement = TryCast(statements.FirstOrDefault(), ReturnStatementSyntax) If returnStatement IsNot Nothing AndAlso returnStatement.Expression IsNot Nothing Then - Dim symbol = semanticModel.GetSymbolInfo(returnStatement.Expression).Symbol + Dim symbol = semanticModel.GetSymbolInfo(returnStatement.Expression, cancellationToken).Symbol Dim fieldSymbol = TryCast(symbol, IFieldSymbol) If fieldSymbol IsNot Nothing AndAlso fieldSymbol.ContainingType.Equals(containingType) Then @@ -132,7 +132,7 @@ Class ConvertToAutoPropertyCodeRefactoringProvider Return document End If - Dim modifiedIdentifier = CType(backingField.DeclaringSyntaxReferences.Single().GetSyntax(), ModifiedIdentifierSyntax) + Dim modifiedIdentifier = CType(backingField.DeclaringSyntaxReferences.Single().GetSyntax(cancellationToken), ModifiedIdentifierSyntax) Dim variableDeclarator = CType(modifiedIdentifier.Parent, VariableDeclaratorSyntax) Dim fieldDeclaration = CType(variableDeclarator.Parent, FieldDeclarationSyntax) diff --git a/src/RoslynSdk/Samples/VisualBasic/MakeConst/MakeConst.Test/MakeConstUnitTests.vb b/src/RoslynSdk/Samples/VisualBasic/MakeConst/MakeConst.Test/MakeConstUnitTests.vb index ac8e8ef838ca5..21b450dfb21f1 100644 --- a/src/RoslynSdk/Samples/VisualBasic/MakeConst/MakeConst.Test/MakeConstUnitTests.vb +++ b/src/RoslynSdk/Samples/VisualBasic/MakeConst/MakeConst.Test/MakeConstUnitTests.vb @@ -1,4 +1,8 @@ -Imports Xunit +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Imports Xunit Imports Verify = Microsoft.CodeAnalysis.VisualBasic.Testing.VisualBasicCodeFixVerifier(Of MakeConst.VisualBasic.MakeConstAnalyzer, MakeConst.VisualBasic.MakeConstCodeFixProvider, Microsoft.CodeAnalysis.Testing.DefaultVerifier) Namespace MakeConst.Test @@ -15,7 +19,6 @@ Namespace MakeConst.Test Public Sub TestMethod2() - End Sub End Class diff --git a/src/RoslynSdk/Samples/VisualBasic/MakeConst/MakeConst/MakeConstAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/MakeConst/MakeConst/MakeConstAnalyzer.vb index 73a7e85bfd904..6bcc462ef1a0f 100644 --- a/src/RoslynSdk/Samples/VisualBasic/MakeConst/MakeConst/MakeConstAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/MakeConst/MakeConst/MakeConstAnalyzer.vb @@ -22,6 +22,8 @@ Public Class MakeConstAnalyzer isEnabledByDefault:=True) Public Overrides Sub Initialize(context As AnalysisContext) + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) + context.EnableConcurrentExecution() context.RegisterSyntaxNodeAction(AddressOf AnalyzeNode, SyntaxKind.LocalDeclarationStatement) End Sub diff --git a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/Program.vb b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/Program.vb index fd209d06bd4fb..6115d6a951d16 100644 --- a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/Program.vb +++ b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/Program.vb @@ -1,4 +1,8 @@ -Option Explicit On +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Option Explicit On Option Strict On Option Infer On diff --git a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseAutoNotifyGenerator.vb b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseAutoNotifyGenerator.vb index f810bd4a631e9..443f5b1a93c77 100644 --- a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseAutoNotifyGenerator.vb +++ b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseAutoNotifyGenerator.vb @@ -1,4 +1,8 @@ -Option Explicit On +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Option Explicit On Option Strict On Option Infer On diff --git a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseCsvGenerator.vb b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseCsvGenerator.vb index f4c05583552cf..818bfaba5cd5f 100644 --- a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseCsvGenerator.vb +++ b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseCsvGenerator.vb @@ -1,4 +1,8 @@ -Option Explicit On +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Option Explicit On Option Strict On Option Infer On diff --git a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseHelloWorldGenerator.vb b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseHelloWorldGenerator.vb index 89fa11b478ac5..4a4a1d632631d 100644 --- a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseHelloWorldGenerator.vb +++ b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/GeneratedDemo/UseHelloWorldGenerator.vb @@ -1,4 +1,8 @@ -Public Module UseHelloWorldGenerator +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Public Module UseHelloWorldGenerator Public Sub Run() ' The static call below is generated at build time, and will list the syntax trees used in the compilation diff --git a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/AutoNotifyGenerator.vb b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/AutoNotifyGenerator.vb index f52a287612e50..514c7d7d1ed0b 100644 --- a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/AutoNotifyGenerator.vb +++ b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/AutoNotifyGenerator.vb @@ -1,4 +1,8 @@ -Option Explicit On +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Option Explicit On Option Infer On Option Strict On diff --git a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/CsvGenerator.vb b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/CsvGenerator.vb index d0957f3af672f..47cf7d018a90a 100644 --- a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/CsvGenerator.vb +++ b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/CsvGenerator.vb @@ -1,4 +1,8 @@ -Option Explicit On +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Option Explicit On Option Infer On Option Strict On @@ -80,7 +84,7 @@ Namespace SourceGeneratorSamples Dim sb As New StringBuilder Dim parser As New CsvTextFieldParser(New StringReader(csvText)) - ''' Imports + ' Imports sb.Append("Option Explicit On Option Strict On Option Infer On @@ -90,7 +94,7 @@ Imports System.Collections.Generic Namespace Global.CSV ") - ''' Class Definition + ' Class Definition sb.Append($" Public Class {className} @@ -111,7 +115,7 @@ Namespace Global.CSV sb.AppendLine($" Public Property {StringToValidPropertyName(names(i))} As {types(i)}") Next - ''' Loading data + ' Loading data sb.Append($" Private Shared m_all As IEnumerable(Of {className}) diff --git a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/HelloWorldGenerator.vb b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/HelloWorldGenerator.vb index bbabaa201dda3..b30a8916dae8a 100644 --- a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/HelloWorldGenerator.vb +++ b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/HelloWorldGenerator.vb @@ -1,4 +1,8 @@ -Option Explicit On +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Option Explicit On Option Infer On Option Strict On diff --git a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/SettingsXmlGenerator.vb b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/SettingsXmlGenerator.vb index 2ff3b1371be34..1119670b2788c 100644 --- a/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/SettingsXmlGenerator.vb +++ b/src/RoslynSdk/Samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/SettingsXmlGenerator.vb @@ -1,4 +1,8 @@ -Option Explicit On +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Option Explicit On Option Infer On Option Strict On diff --git a/src/RoslynSdk/Samples/VisualBasic/TreeTransforms/Transforms.vb b/src/RoslynSdk/Samples/VisualBasic/TreeTransforms/Transforms.vb index 24dba5547e4f3..6b7f06ff2e719 100644 --- a/src/RoslynSdk/Samples/VisualBasic/TreeTransforms/Transforms.vb +++ b/src/RoslynSdk/Samples/VisualBasic/TreeTransforms/Transforms.vb @@ -33,7 +33,7 @@ Public Enum TransformKind SingleLineIfToMultiLineIf End Enum -Public Class Transforms +Public NotInheritable Class Transforms ''' ''' Performs a syntax transform of the source code which is passed in as a string. The transform to be performed is also passed as an argument ''' diff --git a/src/RoslynSdk/Samples/VisualBasic/TreeTransforms/TreeTransforms.vb b/src/RoslynSdk/Samples/VisualBasic/TreeTransforms/TreeTransforms.vb index 9dfbe0e654e92..b7514e4ad81cc 100644 --- a/src/RoslynSdk/Samples/VisualBasic/TreeTransforms/TreeTransforms.vb +++ b/src/RoslynSdk/Samples/VisualBasic/TreeTransforms/TreeTransforms.vb @@ -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. - Imports Xunit Public Class TreeTransformTests diff --git a/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/Converter.vb b/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/Converter.vb index 9878079ae11a1..5a673ee1075f7 100644 --- a/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/Converter.vb +++ b/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/Converter.vb @@ -5,7 +5,7 @@ Imports Microsoft.CodeAnalysis Namespace VisualBasicToCSharpConverter - Partial Public Class Converter + Partial Public NotInheritable Class Converter Public Shared Function Convert( tree As SyntaxTree, Optional identifierMap As IDictionary(Of String, String) = Nothing, diff --git a/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/NodeConvertingVisitor.vb b/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/NodeConvertingVisitor.vb index 77ef7bb64abca..95ef9fb6defe4 100644 --- a/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/NodeConvertingVisitor.vb +++ b/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/NodeConvertingVisitor.vb @@ -656,7 +656,6 @@ Namespace VisualBasicToCSharpConverter Public Overrides Function VisitCatchStatement(node As VB.Syntax.CatchStatementSyntax) As SyntaxNode - If node.IdentifierName Is Nothing Then Return Nothing Dim result = CatchDeclaration(VisitSimpleAsClause(node.AsClause)).WithIdentifier(VisitIdentifier(node.IdentifierName.Identifier)) @@ -836,17 +835,16 @@ Namespace VisualBasicToCSharpConverter aliasString = node.AliasName.Token.ValueText End If - Dim dllImportAttribute = Attribute( - ParseName("global::System.Runtime.InteropServices.DllImport"), - AttributeArgumentList(SeparatedList({ - AttributeArgument(LiteralExpression(CS.SyntaxKind.StringLiteralExpression, Literal(node.LibraryName.Token.ToString(), node.LibraryName.Token.ValueText))), - AttributeArgument(charSet).WithNameColon(NameColon(IdentifierName("CharSet"))), - AttributeArgument( - LiteralExpression(CS.SyntaxKind.StringLiteralExpression, Literal("""" & aliasString & """", aliasString))).WithNameColon(NameColon(IdentifierName("EntryPoint")))} - ) - ) - ) + ParseName("global::System.Runtime.InteropServices.DllImport"), + AttributeArgumentList(SeparatedList({ + AttributeArgument(LiteralExpression(CS.SyntaxKind.StringLiteralExpression, Literal(node.LibraryName.Token.ToString(), node.LibraryName.Token.ValueText))), + AttributeArgument(charSet).WithNameColon(NameColon(IdentifierName("CharSet"))), + AttributeArgument( + LiteralExpression(CS.SyntaxKind.StringLiteralExpression, Literal("""" & aliasString & """", aliasString))).WithNameColon(NameColon(IdentifierName("EntryPoint")))} + ) + ) + ) ' TODO: Transfer attributes on the return type to the statement. Return MethodDeclaration(DeriveType(node.Identifier, node.AsClause, node.SubOrFunctionKeyword), VisitIdentifier(node.Identifier)) _ @@ -2365,7 +2363,6 @@ Namespace VisualBasicToCSharpConverter .WithElse(elseOpt) ) - End Function Public Overrides Function VisitSingleLineLambdaExpression(node As VB.Syntax.SingleLineLambdaExpressionSyntax) As SyntaxNode diff --git a/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/QueryClauseConvertingVisitor.vb b/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/QueryClauseConvertingVisitor.vb index 133bba934edf0..df5383f0fa203 100644 --- a/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/QueryClauseConvertingVisitor.vb +++ b/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Lib/QueryClauseConvertingVisitor.vb @@ -24,9 +24,9 @@ Namespace VisualBasicToCSharpConverter Private IsFirstAfterSelect As Boolean Private InitialClause As CS.Syntax.FromClauseSyntax - Private Clauses As New List(Of CS.Syntax.QueryClauseSyntax)() + Private ReadOnly Clauses As New List(Of CS.Syntax.QueryClauseSyntax)() Private Expression As CS.Syntax.ExpressionSyntax - Private RangeVariablesInScope As New List(Of String)() + Private ReadOnly RangeVariablesInScope As New List(Of String)() Private SelectOrGroupClause As CS.Syntax.SelectOrGroupClauseSyntax Private Continuation As CS.Syntax.QueryContinuationSyntax @@ -148,7 +148,6 @@ Namespace VisualBasicToCSharpConverter End Function - Public Overrides Function VisitSelectClause(node As VB.Syntax.SelectClauseSyntax) As Object Dim variables As New List(Of CS.Syntax.ExpressionSyntax)() diff --git a/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Test/UnitTest1.vb b/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Test/UnitTest1.vb index 2d3203efea449..b2b3ca37e6738 100644 --- a/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Test/UnitTest1.vb +++ b/src/RoslynSdk/Samples/VisualBasic/VisualBasicToCSharpConverter/VisualBasicToCSharpConverter.Test/UnitTest1.vb @@ -1,4 +1,8 @@ -Option Strict Off +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Option Strict Off Imports Microsoft.CodeAnalysis Imports VisualBasicToCSharpConverter @@ -16,10 +20,8 @@ Namespace VisualBasicToCSharpConverter.UnitTests.Converting AssertConversion( - , - ) @@ -1136,4 +1138,3 @@ void M() End Class End Namespace - From 900879626a7b1b4f6dd4c1279fa987c6fecf3a87 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Tue, 25 Aug 2026 16:22:04 -0700 Subject: [PATCH 2/2] feedback --- .../Microsoft.CodeAnalysis.Testing/Directory.Packages.props | 6 +++++- .../StatefulAnalyzers/CodeBlockStartedAnalyzer.cs | 3 ++- .../StatefulAnalyzers/CodeBlockStartedAnalyzer.vb | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/RoslynSdk/Microsoft.CodeAnalysis.Testing/Directory.Packages.props b/src/RoslynSdk/Microsoft.CodeAnalysis.Testing/Directory.Packages.props index b9c74ffcf19c7..37653fb235d24 100644 --- a/src/RoslynSdk/Microsoft.CodeAnalysis.Testing/Directory.Packages.props +++ b/src/RoslynSdk/Microsoft.CodeAnalysis.Testing/Directory.Packages.props @@ -2,7 +2,11 @@ - + false diff --git a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.cs b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.cs index 09ff204e72dcc..e958cc6b44359 100644 --- a/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.cs +++ b/src/RoslynSdk/Samples/CSharp/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.cs @@ -42,10 +42,11 @@ public class CodeBlockStartedAnalyzer : DiagnosticAnalyzer public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(Rule); +#pragma warning disable RS1026 // Enable concurrent execution. This analyzer uses mutable per-code-block state. public override void Initialize(AnalysisContext context) +#pragma warning restore RS1026 { context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); - context.EnableConcurrentExecution(); context.RegisterCodeBlockStartAction(startCodeBlockContext => { // We only care about method bodies. diff --git a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.vb b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.vb index 355a1b310fd0a..9738512ebf630 100644 --- a/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.vb +++ b/src/RoslynSdk/Samples/VisualBasic/Analyzers/Analyzers.Implementation/StatefulAnalyzers/CodeBlockStartedAnalyzer.vb @@ -38,9 +38,10 @@ Namespace BasicAnalyzers End Get End Property +#Disable Warning RS1026 ' Enable concurrent execution. This analyzer uses mutable per-code-block state. Public Overrides Sub Initialize(context As AnalysisContext) +#Enable Warning RS1026 context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None) - context.EnableConcurrentExecution() context.RegisterCodeBlockStartAction(Of SyntaxKind)( Sub(startCodeBlockContext) ' We only care about method bodies.