From 855744d1e0d3a1e081528bd49d8b9050a9b72602 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Wed, 20 May 2020 08:26:54 -0700 Subject: [PATCH] Fix callsites not updated by code fix (TODO: File a bug for the code fixer) --- .../Core/CodeFixes/FormattingCodeFixProvider.cs | 2 +- .../EditAndContinueTestHelpers.cs | 16 ++++++++-------- .../CSharpMethodExtractor.CSharpCodeGenerator.cs | 2 +- ...rpIsAndCastCheckWithoutNameCodeFixProvider.cs | 2 +- ...sAndCastCheckWithoutNameDiagnosticAnalyzer.cs | 2 +- ...rsFromMembersCodeRefactoringProvider.State.cs | 2 +- .../Portable/AddImport/SymbolReferenceFinder.cs | 2 +- .../ChangeSignature/ChangeSignatureCodeAction.cs | 2 +- ...ticIncrementalAnalyzer_IncrementalAnalyzer.cs | 4 ++-- ...orFromMembersCodeRefactoringProvider.State.cs | 2 +- .../AbstractGenerateEnumMemberService.State.cs | 4 ++-- .../AbstractGenerateMethodService.State.cs | 2 +- ...ctGenerateParameterizedMemberService.State.cs | 2 +- .../AbstractGenerateVariableService.State.cs | 4 ++-- .../AbstractGenerateTypeService.State.cs | 2 +- .../AbstractReplaceMethodWithPropertyService.cs | 4 +++- .../CodeFixes/FixAllOccurrences/FixAllContext.cs | 2 +- .../Core/Portable/Editing/SyntaxEditor.cs | 2 +- .../Execution/SolutionSynchronizationService.cs | 2 +- .../AbstractSimplificationService.cs | 2 +- .../IIncrementalAnalyzerExtensions.cs | 4 ++-- .../Core/Portable/Workspace/Workspace.cs | 6 +++--- .../Shared/RoslynJsonConverter.RoslynOnly.cs | 7 ++++++- .../Formatting/Rules/SpacingFormattingRule.cs | 2 +- ...rpRemoveUnnecessaryImportsService.Rewriter.cs | 7 ++----- .../CSharpRemoveUnnecessaryImportsService.cs | 2 +- .../CSharpTypeInferenceService.TypeInferrer.cs | 8 ++++---- ...icRemoveUnnecessaryImportsService.Rewriter.vb | 7 ++----- ...VisualBasicRemoveUnnecessaryImportsService.vb | 2 +- .../VisualBasicCodeGenerationService.vb | 2 +- .../Portable/Editing/VisualBasicImportAdder.vb | 2 +- .../Indentation/SpecialFormattingOperation.vb | 4 ++-- 32 files changed, 58 insertions(+), 57 deletions(-) diff --git a/src/CodeStyle/Core/CodeFixes/FormattingCodeFixProvider.cs b/src/CodeStyle/Core/CodeFixes/FormattingCodeFixProvider.cs index 27f44e55f9e..1ba29a3c284 100644 --- a/src/CodeStyle/Core/CodeFixes/FormattingCodeFixProvider.cs +++ b/src/CodeStyle/Core/CodeFixes/FormattingCodeFixProvider.cs @@ -76,7 +76,7 @@ public FixAll(AbstractFormattingCodeFixProvider formattingCodeFixProvider) protected override async Task FixAllInDocumentAsync(FixAllContext fixAllContext, Document document, ImmutableArray diagnostics) { - var options = await _formattingCodeFixProvider.GetOptionsAsync(document, fixAllContext.CancellationToken).ConfigureAwait(false); + var options = await GetOptionsAsync(document, fixAllContext.CancellationToken).ConfigureAwait(false); var syntaxRoot = await document.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false); var updatedSyntaxRoot = Formatter.Format(syntaxRoot, _formattingCodeFixProvider.SyntaxFormattingService, options, fixAllContext.CancellationToken); return updatedSyntaxRoot; diff --git a/src/EditorFeatures/TestUtilities/EditAndContinue/EditAndContinueTestHelpers.cs b/src/EditorFeatures/TestUtilities/EditAndContinue/EditAndContinueTestHelpers.cs index b9864c029c7..8e1271cb012 100644 --- a/src/EditorFeatures/TestUtilities/EditAndContinue/EditAndContinueTestHelpers.cs +++ b/src/EditorFeatures/TestUtilities/EditAndContinue/EditAndContinueTestHelpers.cs @@ -7,7 +7,6 @@ using System.Collections.Immutable; using System.Linq; using System.Threading; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Differencing; using Microsoft.CodeAnalysis.Emit; using Microsoft.CodeAnalysis.Test.Utilities; @@ -15,6 +14,7 @@ using Roslyn.Test.Utilities; using Roslyn.Utilities; using Xunit; +using static Microsoft.CodeAnalysis.EditAndContinue.AbstractEditAndContinueAnalyzer; namespace Microsoft.CodeAnalysis.EditAndContinue.UnitTests { @@ -96,8 +96,8 @@ internal abstract class EditAndContinueTestHelpers var diagnostics = new List(); var actualNewActiveStatements = new ActiveStatement[oldActiveStatements.Length]; var actualNewExceptionRegions = new ImmutableArray[oldActiveStatements.Length]; - var updatedActiveMethodMatches = new List(); - var editMap = Analyzer.BuildEditMap(editScript); + var updatedActiveMethodMatches = new List(); + var editMap = BuildEditMap(editScript); var documentId = DocumentId.CreateNewId(ProjectId.CreateNewId("TestEnCProject"), "TestEnCDocument"); @@ -179,7 +179,7 @@ internal abstract class EditAndContinueTestHelpers var newText = SourceText.From(newSource); var diagnostics = new List(); - var editMap = Analyzer.BuildEditMap(editScript); + var editMap = BuildEditMap(editScript); var triviaEdits = new List<(SyntaxNode OldNode, SyntaxNode NewNode)>(); var actualLineEdits = new List(); @@ -213,7 +213,7 @@ internal abstract class EditAndContinueTestHelpers { activeStatements ??= ActiveStatementsDescription.Empty; - var editMap = Analyzer.BuildEditMap(editScript); + var editMap = BuildEditMap(editScript); var oldRoot = editScript.Match.OldRoot; var newRoot = editScript.Match.NewRoot; @@ -244,7 +244,7 @@ internal abstract class EditAndContinueTestHelpers var newModel = newCompilation.GetSemanticModel(newRoot.SyntaxTree); var oldActiveStatements = activeStatements.OldStatements.AsImmutable(); - var updatedActiveMethodMatches = new List(); + var updatedActiveMethodMatches = new List(); var triviaEdits = new List<(SyntaxNode OldNode, SyntaxNode NewNode)>(); var actualLineEdits = new List(); var actualSemanticEdits = new List(); @@ -365,8 +365,8 @@ private static string DisplaySpan(string source, TextSpan span) internal static IEnumerable> GetMethodMatches(AbstractEditAndContinueAnalyzer analyzer, Match bodyMatch) { - Dictionary lazyActiveOrMatchedLambdas = null; - var map = analyzer.GetTestAccessor().ComputeMap(bodyMatch, Array.Empty(), ref lazyActiveOrMatchedLambdas, new List()); + Dictionary lazyActiveOrMatchedLambdas = null; + var map = analyzer.GetTestAccessor().ComputeMap(bodyMatch, Array.Empty(), ref lazyActiveOrMatchedLambdas, new List()); var result = new Dictionary(); foreach (var pair in map.Forward) diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs index 002397af813..e61dc205307 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs @@ -287,7 +287,7 @@ private IEnumerable CleanupCode(IEnumerable st statements = postProcessor.RemoveRedundantBlock(statements); statements = postProcessor.RemoveDeclarationAssignmentPattern(statements); - statements = postProcessor.RemoveInitializedDeclarationAndReturnPattern(statements); + statements = PostProcessor.RemoveInitializedDeclarationAndReturnPattern(statements); return statements; } diff --git a/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameCodeFixProvider.cs b/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameCodeFixProvider.cs index 70167595c4d..840580769f8 100644 --- a/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameCodeFixProvider.cs @@ -56,7 +56,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) var (matches, localName) = CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.Instance.AnalyzeExpression( semanticModel, isExpression, cancellationToken); - var updatedSemanticModel = CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.Instance.ReplaceMatches( + var updatedSemanticModel = CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.ReplaceMatches( semanticModel, isExpression, localName, matches, cancellationToken); var updatedRoot = updatedSemanticModel.SyntaxTree.GetRoot(cancellationToken); diff --git a/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.cs b/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.cs index 3f250e4e6ce..20324e92913 100644 --- a/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.cs +++ b/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.cs @@ -84,7 +84,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext context) // See if this is an 'is' expression that would be handled by the analyzer. If so // we don't need to do anything. - if (CSharpIsAndCastCheckDiagnosticAnalyzer.Instance.TryGetPatternPieces( + if (CSharpIsAndCastCheckDiagnosticAnalyzer.TryGetPatternPieces( isExpression, out _, out _, out _, out _)) { return; diff --git a/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.State.cs b/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.State.cs index 58b6ad950fb..b66db3c8f76 100644 --- a/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.State.cs +++ b/src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.State.cs @@ -45,7 +45,7 @@ private class State ContainingType = selectedMembers[0].ContainingType; var rules = await document.GetNamingRulesAsync(cancellationToken).ConfigureAwait(false); - var parametersForSelectedMembers = service.DetermineParameters(selectedMembers, rules); + var parametersForSelectedMembers = DetermineParameters(selectedMembers, rules); if (!selectedMembers.All(IsWritableInstanceFieldOrProperty) || ContainingType == null || diff --git a/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs b/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs index 6652e8edfb8..11af0720308 100644 --- a/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs +++ b/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs @@ -394,7 +394,7 @@ private async Task> GetReferencesForMatchingExte ImmutableArray> methodSymbols, ITypeSymbol typeSymbol) { return GetViableExtensionMethodsWorker(methodSymbols).WhereAsArray( - s => _owner.IsViableExtensionMethod(s.Symbol, typeSymbol)); + s => IsViableExtensionMethod(s.Symbol, typeSymbol)); } private ImmutableArray> GetViableExtensionMethodsWorker( diff --git a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs index 21ab5d0f207..075adf906d0 100644 --- a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs +++ b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs @@ -26,7 +26,7 @@ public ChangeSignatureCodeAction(AbstractChangeSignatureService changeSignatureS public override string Title => FeaturesResources.Change_signature; public override object GetOptions(CancellationToken cancellationToken) - => _changeSignatureService.GetChangeSignatureOptions(_context) + => AbstractChangeSignatureService.GetChangeSignatureOptions(_context) ?? new ChangeSignatureOptionsResult(null!, false); protected override Task> ComputeOperationsAsync(object options, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs b/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs index 6904bda51e3..475dfe13513 100644 --- a/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs +++ b/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs @@ -166,7 +166,7 @@ public Task DocumentResetAsync(Document document, CancellationToken cancellation // let other components knows about this event ClearCompilationsWithAnalyzersCache(); - var documentHadDiagnostics = _stateManager.OnDocumentReset(stateSets, document); + var documentHadDiagnostics = StateManager.OnDocumentReset(stateSets, document); RaiseDiagnosticsRemovedIfRequiredForClosedOrResetDocument(document, stateSets, documentHadDiagnostics); } @@ -201,7 +201,7 @@ public Task RemoveDocumentAsync(DocumentId documentId, CancellationToken cancell // let other components knows about this event ClearCompilationsWithAnalyzersCache(); - var changed = _stateManager.OnDocumentRemoved(stateSets, documentId); + var changed = StateManager.OnDocumentRemoved(stateSets, documentId); // if there was no diagnostic reported for this document, nothing to clean up // this is Perf to reduce raising events unnecessarily. diff --git a/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.State.cs b/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.State.cs index 8839d07fe28..50d6bc37142 100644 --- a/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.State.cs +++ b/src/Features/Core/Portable/GenerateConstructorFromMembers/AbstractGenerateConstructorFromMembersCodeRefactoringProvider.State.cs @@ -62,7 +62,7 @@ private class State } var rules = await document.GetNamingRulesAsync(cancellationToken).ConfigureAwait(false); - Parameters = service.DetermineParameters(selectedMembers, rules); + Parameters = DetermineParameters(selectedMembers, rules); MatchingConstructor = GetMatchingConstructorBasedOnParameterTypes(ContainingType, Parameters); // We are going to create a new contructor and pass part of the parameters into DelegatedConstructor, // so parameters should be compared based on types since we don't want get a type mismatch error after the new constructor is genreated. diff --git a/src/Features/Core/Portable/GenerateMember/GenerateEnumMember/AbstractGenerateEnumMemberService.State.cs b/src/Features/Core/Portable/GenerateMember/GenerateEnumMember/AbstractGenerateEnumMemberService.State.cs index fd09faaf634..e27a51cb774 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateEnumMember/AbstractGenerateEnumMemberService.State.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateEnumMember/AbstractGenerateEnumMemberService.State.cs @@ -72,7 +72,7 @@ private partial class State cancellationToken.ThrowIfCancellationRequested(); TypeToGenerateIn = await SymbolFinder.FindSourceDefinitionAsync(TypeToGenerateIn, document.Project.Solution, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol; - if (!service.ValidateTypeToGenerateIn(TypeToGenerateIn, true, EnumType)) + if (!ValidateTypeToGenerateIn(TypeToGenerateIn, true, EnumType)) { return false; } @@ -127,7 +127,7 @@ private partial class State // Either we found no matches, or this was ambiguous. Either way, we might be able // to generate a method here. Determine where the user wants to generate the method // into, and if it's valid then proceed. - if (!service.TryDetermineTypeToGenerateIn( + if (!TryDetermineTypeToGenerateIn( semanticDocument, containingType, simpleNameOrMemberAccessExpression, cancellationToken, out var typeToGenerateIn, out var isStatic)) { diff --git a/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateMethodService.State.cs b/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateMethodService.State.cs index bf54f7145e6..452f2a481b3 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateMethodService.State.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateMethodService.State.cs @@ -199,7 +199,7 @@ internal new class State : AbstractGenerateParameterizedMemberService TryFinishInitializingStateAsync(TService service, Sem return false; } - if (!service.ValidateTypeToGenerateIn(TypeToGenerateIn, IsStatic, ClassInterfaceModuleStructTypes)) + if (!ValidateTypeToGenerateIn(TypeToGenerateIn, IsStatic, ClassInterfaceModuleStructTypes)) { return false; } diff --git a/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.State.cs b/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.State.cs index 6335dc26d32..84716abbd3d 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.State.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.State.cs @@ -122,7 +122,7 @@ private partial class State TypeToGenerateIn = await SymbolFinder.FindSourceDefinitionAsync(TypeToGenerateIn, document.Project.Solution, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol; - if (!service.ValidateTypeToGenerateIn(TypeToGenerateIn, IsStatic, ClassInterfaceModuleStructTypes)) + if (!ValidateTypeToGenerateIn(TypeToGenerateIn, IsStatic, ClassInterfaceModuleStructTypes)) { return false; } @@ -247,7 +247,7 @@ internal bool CanGenerateParameter() // to generate a method here. Determine where the user wants to generate the method // into, and if it's valid then proceed. cancellationToken.ThrowIfCancellationRequested(); - if (!service.TryDetermineTypeToGenerateIn(semanticDocument, ContainingType, SimpleNameOrMemberAccessExpressionOpt, cancellationToken, + if (!TryDetermineTypeToGenerateIn(semanticDocument, ContainingType, SimpleNameOrMemberAccessExpressionOpt, cancellationToken, out var typeToGenerateIn, out var isStatic)) { return false; diff --git a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.State.cs b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.State.cs index 16cba8ae1b5..878461bc006 100644 --- a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.State.cs +++ b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.State.cs @@ -300,7 +300,7 @@ private bool GenerateInterface(TService service) // If we are generating in a website project, we also want to type to be public so the // designer files can access the type. if (documentToBeGeneratedIn.Project != document.Project || - service.GeneratedTypesMustBePublic(documentToBeGeneratedIn.Project)) + GeneratedTypesMustBePublic(documentToBeGeneratedIn.Project)) { IsPublicAccessibilityForTypeGeneration = true; } diff --git a/src/Features/Core/Portable/ReplaceMethodWithProperty/AbstractReplaceMethodWithPropertyService.cs b/src/Features/Core/Portable/ReplaceMethodWithProperty/AbstractReplaceMethodWithPropertyService.cs index bf7a62940da..f6076fb028e 100644 --- a/src/Features/Core/Portable/ReplaceMethodWithProperty/AbstractReplaceMethodWithPropertyService.cs +++ b/src/Features/Core/Portable/ReplaceMethodWithProperty/AbstractReplaceMethodWithPropertyService.cs @@ -11,7 +11,9 @@ namespace Microsoft.CodeAnalysis.ReplaceMethodWithProperty { internal abstract class AbstractReplaceMethodWithPropertyService where TMethodDeclarationSyntax : SyntaxNode { - public static async Task GetMethodDeclarationAsync(CodeRefactoringContext context) +#pragma warning disable CA1822 // Mark members as static - implements interface method for sub-types. + public async Task GetMethodDeclarationAsync(CodeRefactoringContext context) +#pragma warning restore CA1822 // Mark members as static => await context.TryGetRelevantNodeAsync().ConfigureAwait(false); protected static string GetWarning(GetAndSetMethods getAndSetMethods) diff --git a/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/FixAllContext.cs b/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/FixAllContext.cs index 7b519f1ba90..a0403d81ebe 100644 --- a/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/FixAllContext.cs +++ b/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/FixAllContext.cs @@ -233,7 +233,7 @@ public FixAllContext WithCancellationToken(CancellationToken cancellationToken) } internal Task>> GetDocumentDiagnosticsToFixAsync() - => State.DiagnosticProvider.GetDocumentDiagnosticsToFixAsync(this); + => DiagnosticProvider.GetDocumentDiagnosticsToFixAsync(this); internal Task>> GetProjectDiagnosticsToFixAsync() => State.DiagnosticProvider.GetProjectDiagnosticsToFixAsync(this); diff --git a/src/Workspaces/Core/Portable/Editing/SyntaxEditor.cs b/src/Workspaces/Core/Portable/Editing/SyntaxEditor.cs index 0b2e32179ad..ca5f52be227 100644 --- a/src/Workspaces/Core/Portable/Editing/SyntaxEditor.cs +++ b/src/Workspaces/Core/Portable/Editing/SyntaxEditor.cs @@ -342,7 +342,7 @@ public override SyntaxNode Apply(SyntaxNode root, SyntaxGenerator generator) newNodes[i] = _editor.ApplyTrackingToNewNode(newNodes[i]); } - return generator.ReplaceNode(root, current, newNodes); + return SyntaxGenerator.ReplaceNode(root, current, newNodes); } } diff --git a/src/Workspaces/Core/Portable/Execution/SolutionSynchronizationService.cs b/src/Workspaces/Core/Portable/Execution/SolutionSynchronizationService.cs index a96f269e2ec..86c3f3e15fb 100644 --- a/src/Workspaces/Core/Portable/Execution/SolutionSynchronizationService.cs +++ b/src/Workspaces/Core/Portable/Execution/SolutionSynchronizationService.cs @@ -47,7 +47,7 @@ public async ValueTask CreatePinnedRemotableDataScopeA { using (Logger.LogBlock(FunctionId.SolutionSynchronizationServiceFactory_CreatePinnedRemotableDataScopeAsync, cancellationToken)) { - var storage = _assetStorages.CreateStorage(solution.State); + var storage = AssetStorages.CreateStorage(solution.State); var checksum = await solution.State.GetChecksumAsync(cancellationToken).ConfigureAwait(false); return PinnedRemotableDataScope.Create(_assetStorages, storage, checksum); diff --git a/src/Workspaces/Core/Portable/Simplification/AbstractSimplificationService.cs b/src/Workspaces/Core/Portable/Simplification/AbstractSimplificationService.cs index 0fe2c91fbb4..32401ec247e 100644 --- a/src/Workspaces/Core/Portable/Simplification/AbstractSimplificationService.cs +++ b/src/Workspaces/Core/Portable/Simplification/AbstractSimplificationService.cs @@ -109,7 +109,7 @@ protected virtual SyntaxNode TransformReducedNode(SyntaxNode reducedNode, Syntax // prep namespace imports marked for simplification var removeIfUnusedAnnotation = new SyntaxAnnotation(); var originalRoot = root; - root = this.PrepareNamespaceImportsForRemovalIfUnused(document, root, removeIfUnusedAnnotation, isNodeOrTokenOutsideSimplifySpans); + root = PrepareNamespaceImportsForRemovalIfUnused(document, root, removeIfUnusedAnnotation, isNodeOrTokenOutsideSimplifySpans); var hasImportsToSimplify = root != originalRoot; if (hasImportsToSimplify) diff --git a/src/Workspaces/Core/Portable/SolutionCrawler/IIncrementalAnalyzerExtensions.cs b/src/Workspaces/Core/Portable/SolutionCrawler/IIncrementalAnalyzerExtensions.cs index a8e0ece448b..d44c735e9f7 100644 --- a/src/Workspaces/Core/Portable/SolutionCrawler/IIncrementalAnalyzerExtensions.cs +++ b/src/Workspaces/Core/Portable/SolutionCrawler/IIncrementalAnalyzerExtensions.cs @@ -12,9 +12,9 @@ internal static partial class IIncrementalAnalyzerExtensions public static BackgroundAnalysisScope GetOverriddenBackgroundAnalysisScope(this IIncrementalAnalyzer incrementalAnalyzer, OptionSet options, BackgroundAnalysisScope defaultBackgroundAnalysisScope) { // Unit testing analyzer has special semantics for analysis scope. - if (incrementalAnalyzer is UnitTestingIncrementalAnalyzer unitTestingAnalyzer) + if (incrementalAnalyzer is UnitTestingIncrementalAnalyzer) { - return unitTestingAnalyzer.GetBackgroundAnalysisScope(options); + return UnitTestingIncrementalAnalyzer.GetBackgroundAnalysisScope(options); } return defaultBackgroundAnalysisScope; diff --git a/src/Workspaces/Core/Portable/Workspace/Workspace.cs b/src/Workspaces/Core/Portable/Workspace/Workspace.cs index 0dc86a4e9af..a7cd9d9a444 100644 --- a/src/Workspaces/Core/Portable/Workspace/Workspace.cs +++ b/src/Workspaces/Core/Portable/Workspace/Workspace.cs @@ -1472,7 +1472,7 @@ protected virtual void ApplyProjectChanges(ProjectChanges projectChanges) { var document = projectChanges.NewProject.GetDocument(documentId)!; var text = document.GetTextSynchronously(CancellationToken.None); - var info = this.CreateDocumentInfoWithoutText(document); + var info = CreateDocumentInfoWithoutText(document); this.ApplyDocumentAdded(info, text); } @@ -1481,7 +1481,7 @@ protected virtual void ApplyProjectChanges(ProjectChanges projectChanges) { var document = projectChanges.NewProject.GetAdditionalDocument(documentId)!; var text = document.GetTextSynchronously(CancellationToken.None); - var info = this.CreateDocumentInfoWithoutText(document); + var info = CreateDocumentInfoWithoutText(document); this.ApplyAdditionalDocumentAdded(info, text); } @@ -1490,7 +1490,7 @@ protected virtual void ApplyProjectChanges(ProjectChanges projectChanges) { var document = projectChanges.NewProject.GetAnalyzerConfigDocument(documentId)!; var text = document.GetTextSynchronously(CancellationToken.None); - var info = this.CreateDocumentInfoWithoutText(document); + var info = CreateDocumentInfoWithoutText(document); this.ApplyAnalyzerConfigDocumentAdded(info, text); } diff --git a/src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.RoslynOnly.cs b/src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.RoslynOnly.cs index 55ff1c2a1c1..ef2aab06fc6 100644 --- a/src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.RoslynOnly.cs +++ b/src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.RoslynOnly.cs @@ -20,7 +20,12 @@ namespace Microsoft.CodeAnalysis.Remote { internal partial class AggregateJsonConverter : JsonConverter { - static partial void AppendRoslynSpecificJsonConverters(ImmutableDictionary.Builder builder) +#pragma warning disable CA1822 // Mark members as static + // this type is shared by multiple teams such as Razor, LUT and etc which have either + // separated/shared/shim repo so some types might not available to those context. this + // partial method let us add Roslyn specific types without breaking them + partial void AppendRoslynSpecificJsonConverters(ImmutableDictionary.Builder builder) +#pragma warning restore CA1822 // Mark members as static { Add(builder, new HighlightSpanJsonConverter()); Add(builder, new TaggedTextJsonConverter()); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/SpacingFormattingRule.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/SpacingFormattingRule.cs index 3deba8b13c0..8dd314892d1 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/SpacingFormattingRule.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/SpacingFormattingRule.cs @@ -162,7 +162,7 @@ public override AbstractFormattingRule WithOptions(AnalyzerConfigOptions options // Semicolons in an empty for statement. i.e. for(;;) if (previousParentKind == SyntaxKind.ForStatement - && this.IsEmptyForStatement((ForStatementSyntax)previousToken.Parent!)) + && IsEmptyForStatement((ForStatementSyntax)previousToken.Parent!)) { if (currentKind == SyntaxKind.SemicolonToken && (previousKind != SyntaxKind.SemicolonToken diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.Rewriter.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.Rewriter.cs index 8c578ec635b..507b55170ff 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.Rewriter.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.Rewriter.cs @@ -19,17 +19,14 @@ private class Rewriter : CSharpSyntaxRewriter { private readonly ISet _unnecessaryUsingsDoNotAccessDirectly; private readonly CancellationToken _cancellationToken; - private readonly CSharpRemoveUnnecessaryImportsService _importsService; private readonly Document _document; public Rewriter( - CSharpRemoveUnnecessaryImportsService importsService, Document document, ISet unnecessaryUsings, CancellationToken cancellationToken) : base(visitIntoStructuredTrivia: true) { - _importsService = importsService; _document = document; _unnecessaryUsingsDoNotAccessDirectly = unnecessaryUsings; _cancellationToken = cancellationToken; @@ -142,7 +139,7 @@ public override SyntaxNode VisitCompilationUnit(CompilationUnitSyntax node) // We've removed all the usings and now the first thing in the namespace is a // type. In this case, remove any newlines preceding the type. var firstToken = resultCompilationUnit.GetFirstToken(); - var newFirstToken = _importsService.StripNewLines(_document, firstToken); + var newFirstToken = StripNewLines(_document, firstToken); resultCompilationUnit = resultCompilationUnit.ReplaceToken(firstToken, newFirstToken); } @@ -176,7 +173,7 @@ public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax // We've removed all the usings and now the first thing in the namespace is a // type. In this case, remove any newlines preceding the type. var firstToken = resultNamespace.Members.First().GetFirstToken(); - var newFirstToken = _importsService.StripNewLines(_document, firstToken); + var newFirstToken = StripNewLines(_document, firstToken); resultNamespace = resultNamespace.ReplaceToken(firstToken, newFirstToken); } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs index fa4c279d885..1b24819fbf7 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs @@ -53,7 +53,7 @@ protected override IUnnecessaryImportsProvider UnnecessaryImportsProvider var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var oldRoot = (CompilationUnitSyntax)root; - var newRoot = (CompilationUnitSyntax)new Rewriter(this, document, unnecessaryImports, cancellationToken).Visit(oldRoot); + var newRoot = (CompilationUnitSyntax)new Rewriter(document, unnecessaryImports, cancellationToken).Visit(oldRoot); cancellationToken.ThrowIfCancellationRequested(); return document.WithSyntaxRoot(await FormatResultAsync(document, newRoot, cancellationToken).ConfigureAwait(false)); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs index e03c2a9a1d5..5d611991f21 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs @@ -500,19 +500,19 @@ private IEnumerable InferTypeInArgumentList(ArgumentListSynta { case InvocationExpressionSyntax invocation: { - var index = this.GetArgumentListIndex(argumentList, previousToken); + var index = GetArgumentListIndex(argumentList, previousToken); return InferTypeInInvocationExpression(invocation, index); } case ObjectCreationExpressionSyntax objectCreation: { - var index = this.GetArgumentListIndex(argumentList, previousToken); + var index = GetArgumentListIndex(argumentList, previousToken); return InferTypeInObjectCreationExpression(objectCreation, index); } case ConstructorInitializerSyntax constructorInitializer: { - var index = this.GetArgumentListIndex(argumentList, previousToken); + var index = GetArgumentListIndex(argumentList, previousToken); return InferTypeInConstructorInitializer(constructorInitializer, index); } } @@ -530,7 +530,7 @@ private IEnumerable InferTypeInAttributeArgumentList(Attribut if (attributeArgumentList.Parent is AttributeSyntax attribute) { - var index = this.GetArgumentListIndex(attributeArgumentList, previousToken); + var index = GetArgumentListIndex(attributeArgumentList, previousToken); return InferTypeInAttribute(attribute, index); } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicRemoveUnnecessaryImportsService.Rewriter.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicRemoveUnnecessaryImportsService.Rewriter.vb index 63911fb2684..e273c9db81a 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicRemoveUnnecessaryImportsService.Rewriter.vb +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicRemoveUnnecessaryImportsService.Rewriter.vb @@ -14,14 +14,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryImports Private ReadOnly _unnecessaryImports As ISet(Of ImportsClauseSyntax) Private ReadOnly _cancellationToken As CancellationToken Private ReadOnly _annotation As New SyntaxAnnotation() - Private ReadOnly _importsService As VisualBasicRemoveUnnecessaryImportsService Private ReadOnly _document As Document - Public Sub New(importsService As VisualBasicRemoveUnnecessaryImportsService, - document As Document, + Public Sub New(document As Document, unnecessaryImports As ISet(Of ImportsClauseSyntax), cancellationToken As CancellationToken) - _importsService = importsService _document = document _unnecessaryImports = unnecessaryImports _cancellationToken = cancellationToken @@ -117,7 +114,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryImports If newCompilationUnit.Imports.Count = 0 AndAlso newCompilationUnit.Options.Count = 0 Then If newCompilationUnit.Attributes.Count > 0 OrElse newCompilationUnit.Members.Count > 0 Then Dim firstToken = newCompilationUnit.GetFirstToken() - Dim newFirstToken = _importsService.StripNewLines(_document, firstToken) + Dim newFirstToken = StripNewLines(_document, firstToken) newCompilationUnit = newCompilationUnit.ReplaceToken(firstToken, newFirstToken) End If End If diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicRemoveUnnecessaryImportsService.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicRemoveUnnecessaryImportsService.vb index 762e95c713c..f2244090225 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicRemoveUnnecessaryImportsService.vb +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicRemoveUnnecessaryImportsService.vb @@ -44,7 +44,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryImports Dim root = Await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False) Dim oldRoot = DirectCast(root, CompilationUnitSyntax) - Dim newRoot = New Rewriter(Me, document, unnecessaryImports, cancellationToken).Visit(oldRoot) + Dim newRoot = New Rewriter(document, unnecessaryImports, cancellationToken).Visit(oldRoot) newRoot = newRoot.WithAdditionalAnnotations(Formatter.Annotation) cancellationToken.ThrowIfCancellationRequested() diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationService.vb b/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationService.vb index 2586517b51f..7ab20928f3c 100644 --- a/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationService.vb +++ b/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationService.vb @@ -48,7 +48,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return Nothing End Function - Private Shared Function GetAvailableInsertionIndices(destination As CompilationUnitSyntax, cancellationToken As CancellationToken) As IList(Of Boolean) + Private Overloads Shared Function GetAvailableInsertionIndices(destination As CompilationUnitSyntax, cancellationToken As CancellationToken) As IList(Of Boolean) Dim members = destination.Members Dim indices = New List(Of Boolean) diff --git a/src/Workspaces/VisualBasic/Portable/Editing/VisualBasicImportAdder.vb b/src/Workspaces/VisualBasic/Portable/Editing/VisualBasicImportAdder.vb index 97d70e2b89f..3fafd8f88c8 100644 --- a/src/Workspaces/VisualBasic/Portable/Editing/VisualBasicImportAdder.vb +++ b/src/Workspaces/VisualBasic/Portable/Editing/VisualBasicImportAdder.vb @@ -41,7 +41,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Editing Return Rewriter.Visit(root) End Function - Private Shared Function GetExplicitNamespaceSymbol(fullName As ExpressionSyntax, namespacePart As ExpressionSyntax, model As SemanticModel) As INamespaceSymbol + Private Overloads Shared Function GetExplicitNamespaceSymbol(fullName As ExpressionSyntax, namespacePart As ExpressionSyntax, model As SemanticModel) As INamespaceSymbol ' name must refer to something that is not a namespace, but be qualified with a namespace. Dim Symbol = model.GetSymbolInfo(fullName).Symbol Dim nsSymbol = TryCast(model.GetSymbolInfo(namespacePart).Symbol, INamespaceSymbol) diff --git a/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb b/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb index 08070a30a77..c5b371a6384 100644 --- a/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb +++ b/src/Workspaces/VisualBasic/Portable/Indentation/SpecialFormattingOperation.vb @@ -92,7 +92,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation AddIndentBlockOperations(list, parameterOrArgumentList, indentationDelta) End Sub - Private Shared Sub AddIndentBlockOperations(list As List(Of IndentBlockOperation), parameterOrArgumentList As SyntaxNode, indentationDelta As Integer) + Private Overloads Shared Sub AddIndentBlockOperations(list As List(Of IndentBlockOperation), parameterOrArgumentList As SyntaxNode, indentationDelta As Integer) Dim openBrace = parameterOrArgumentList.GetFirstToken(includeZeroWidth:=True) Dim closeBrace = parameterOrArgumentList.GetLastToken(includeZeroWidth:=True) @@ -211,7 +211,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation AddAlignTokensOperations(operations, baseToken) End Sub - Private Shared Sub AddAlignTokensOperations(operations As List(Of AlignTokensOperation), baseToken As SyntaxToken) + Private Overloads Shared Sub AddAlignTokensOperations(operations As List(Of AlignTokensOperation), baseToken As SyntaxToken) operations.Add(FormattingOperations.CreateAlignTokensOperation( baseToken, SpecializedCollections.SingletonEnumerable(baseToken.GetNextToken(includeZeroWidth:=True)), -- GitLab