提交 855744d1 编写于 作者: M Manish Vasani

Fix callsites not updated by code fix (TODO: File a bug for the code fixer)

上级 a9ee8d88
...@@ -76,7 +76,7 @@ public FixAll(AbstractFormattingCodeFixProvider formattingCodeFixProvider) ...@@ -76,7 +76,7 @@ public FixAll(AbstractFormattingCodeFixProvider formattingCodeFixProvider)
protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics) protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> 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 syntaxRoot = await document.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
var updatedSyntaxRoot = Formatter.Format(syntaxRoot, _formattingCodeFixProvider.SyntaxFormattingService, options, fixAllContext.CancellationToken); var updatedSyntaxRoot = Formatter.Format(syntaxRoot, _formattingCodeFixProvider.SyntaxFormattingService, options, fixAllContext.CancellationToken);
return updatedSyntaxRoot; return updatedSyntaxRoot;
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Differencing; using Microsoft.CodeAnalysis.Differencing;
using Microsoft.CodeAnalysis.Emit; using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Test.Utilities;
...@@ -15,6 +14,7 @@ ...@@ -15,6 +14,7 @@
using Roslyn.Test.Utilities; using Roslyn.Test.Utilities;
using Roslyn.Utilities; using Roslyn.Utilities;
using Xunit; using Xunit;
using static Microsoft.CodeAnalysis.EditAndContinue.AbstractEditAndContinueAnalyzer;
namespace Microsoft.CodeAnalysis.EditAndContinue.UnitTests namespace Microsoft.CodeAnalysis.EditAndContinue.UnitTests
{ {
...@@ -96,8 +96,8 @@ internal abstract class EditAndContinueTestHelpers ...@@ -96,8 +96,8 @@ internal abstract class EditAndContinueTestHelpers
var diagnostics = new List<RudeEditDiagnostic>(); var diagnostics = new List<RudeEditDiagnostic>();
var actualNewActiveStatements = new ActiveStatement[oldActiveStatements.Length]; var actualNewActiveStatements = new ActiveStatement[oldActiveStatements.Length];
var actualNewExceptionRegions = new ImmutableArray<LinePositionSpan>[oldActiveStatements.Length]; var actualNewExceptionRegions = new ImmutableArray<LinePositionSpan>[oldActiveStatements.Length];
var updatedActiveMethodMatches = new List<AbstractEditAndContinueAnalyzer.UpdatedMemberInfo>(); var updatedActiveMethodMatches = new List<UpdatedMemberInfo>();
var editMap = Analyzer.BuildEditMap(editScript); var editMap = BuildEditMap(editScript);
var documentId = DocumentId.CreateNewId(ProjectId.CreateNewId("TestEnCProject"), "TestEnCDocument"); var documentId = DocumentId.CreateNewId(ProjectId.CreateNewId("TestEnCProject"), "TestEnCDocument");
...@@ -179,7 +179,7 @@ internal abstract class EditAndContinueTestHelpers ...@@ -179,7 +179,7 @@ internal abstract class EditAndContinueTestHelpers
var newText = SourceText.From(newSource); var newText = SourceText.From(newSource);
var diagnostics = new List<RudeEditDiagnostic>(); var diagnostics = new List<RudeEditDiagnostic>();
var editMap = Analyzer.BuildEditMap(editScript); var editMap = BuildEditMap(editScript);
var triviaEdits = new List<(SyntaxNode OldNode, SyntaxNode NewNode)>(); var triviaEdits = new List<(SyntaxNode OldNode, SyntaxNode NewNode)>();
var actualLineEdits = new List<LineChange>(); var actualLineEdits = new List<LineChange>();
...@@ -213,7 +213,7 @@ internal abstract class EditAndContinueTestHelpers ...@@ -213,7 +213,7 @@ internal abstract class EditAndContinueTestHelpers
{ {
activeStatements ??= ActiveStatementsDescription.Empty; activeStatements ??= ActiveStatementsDescription.Empty;
var editMap = Analyzer.BuildEditMap(editScript); var editMap = BuildEditMap(editScript);
var oldRoot = editScript.Match.OldRoot; var oldRoot = editScript.Match.OldRoot;
var newRoot = editScript.Match.NewRoot; var newRoot = editScript.Match.NewRoot;
...@@ -244,7 +244,7 @@ internal abstract class EditAndContinueTestHelpers ...@@ -244,7 +244,7 @@ internal abstract class EditAndContinueTestHelpers
var newModel = newCompilation.GetSemanticModel(newRoot.SyntaxTree); var newModel = newCompilation.GetSemanticModel(newRoot.SyntaxTree);
var oldActiveStatements = activeStatements.OldStatements.AsImmutable(); var oldActiveStatements = activeStatements.OldStatements.AsImmutable();
var updatedActiveMethodMatches = new List<AbstractEditAndContinueAnalyzer.UpdatedMemberInfo>(); var updatedActiveMethodMatches = new List<UpdatedMemberInfo>();
var triviaEdits = new List<(SyntaxNode OldNode, SyntaxNode NewNode)>(); var triviaEdits = new List<(SyntaxNode OldNode, SyntaxNode NewNode)>();
var actualLineEdits = new List<LineChange>(); var actualLineEdits = new List<LineChange>();
var actualSemanticEdits = new List<SemanticEdit>(); var actualSemanticEdits = new List<SemanticEdit>();
...@@ -365,8 +365,8 @@ private static string DisplaySpan(string source, TextSpan span) ...@@ -365,8 +365,8 @@ private static string DisplaySpan(string source, TextSpan span)
internal static IEnumerable<KeyValuePair<SyntaxNode, SyntaxNode>> GetMethodMatches(AbstractEditAndContinueAnalyzer analyzer, Match<SyntaxNode> bodyMatch) internal static IEnumerable<KeyValuePair<SyntaxNode, SyntaxNode>> GetMethodMatches(AbstractEditAndContinueAnalyzer analyzer, Match<SyntaxNode> bodyMatch)
{ {
Dictionary<SyntaxNode, AbstractEditAndContinueAnalyzer.LambdaInfo> lazyActiveOrMatchedLambdas = null; Dictionary<SyntaxNode, LambdaInfo> lazyActiveOrMatchedLambdas = null;
var map = analyzer.GetTestAccessor().ComputeMap(bodyMatch, Array.Empty<AbstractEditAndContinueAnalyzer.ActiveNode>(), ref lazyActiveOrMatchedLambdas, new List<RudeEditDiagnostic>()); var map = analyzer.GetTestAccessor().ComputeMap(bodyMatch, Array.Empty<ActiveNode>(), ref lazyActiveOrMatchedLambdas, new List<RudeEditDiagnostic>());
var result = new Dictionary<SyntaxNode, SyntaxNode>(); var result = new Dictionary<SyntaxNode, SyntaxNode>();
foreach (var pair in map.Forward) foreach (var pair in map.Forward)
......
...@@ -287,7 +287,7 @@ private IEnumerable<StatementSyntax> CleanupCode(IEnumerable<StatementSyntax> st ...@@ -287,7 +287,7 @@ private IEnumerable<StatementSyntax> CleanupCode(IEnumerable<StatementSyntax> st
statements = postProcessor.RemoveRedundantBlock(statements); statements = postProcessor.RemoveRedundantBlock(statements);
statements = postProcessor.RemoveDeclarationAssignmentPattern(statements); statements = postProcessor.RemoveDeclarationAssignmentPattern(statements);
statements = postProcessor.RemoveInitializedDeclarationAndReturnPattern(statements); statements = PostProcessor.RemoveInitializedDeclarationAndReturnPattern(statements);
return statements; return statements;
} }
......
...@@ -56,7 +56,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) ...@@ -56,7 +56,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
var (matches, localName) = CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.Instance.AnalyzeExpression( var (matches, localName) = CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.Instance.AnalyzeExpression(
semanticModel, isExpression, cancellationToken); semanticModel, isExpression, cancellationToken);
var updatedSemanticModel = CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.Instance.ReplaceMatches( var updatedSemanticModel = CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.ReplaceMatches(
semanticModel, isExpression, localName, matches, cancellationToken); semanticModel, isExpression, localName, matches, cancellationToken);
var updatedRoot = updatedSemanticModel.SyntaxTree.GetRoot(cancellationToken); var updatedRoot = updatedSemanticModel.SyntaxTree.GetRoot(cancellationToken);
......
...@@ -84,7 +84,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext context) ...@@ -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 // See if this is an 'is' expression that would be handled by the analyzer. If so
// we don't need to do anything. // we don't need to do anything.
if (CSharpIsAndCastCheckDiagnosticAnalyzer.Instance.TryGetPatternPieces( if (CSharpIsAndCastCheckDiagnosticAnalyzer.TryGetPatternPieces(
isExpression, out _, out _, out _, out _)) isExpression, out _, out _, out _, out _))
{ {
return; return;
......
...@@ -45,7 +45,7 @@ private class State ...@@ -45,7 +45,7 @@ private class State
ContainingType = selectedMembers[0].ContainingType; ContainingType = selectedMembers[0].ContainingType;
var rules = await document.GetNamingRulesAsync(cancellationToken).ConfigureAwait(false); var rules = await document.GetNamingRulesAsync(cancellationToken).ConfigureAwait(false);
var parametersForSelectedMembers = service.DetermineParameters(selectedMembers, rules); var parametersForSelectedMembers = DetermineParameters(selectedMembers, rules);
if (!selectedMembers.All(IsWritableInstanceFieldOrProperty) || if (!selectedMembers.All(IsWritableInstanceFieldOrProperty) ||
ContainingType == null || ContainingType == null ||
......
...@@ -394,7 +394,7 @@ private async Task<ImmutableArray<SymbolReference>> GetReferencesForMatchingExte ...@@ -394,7 +394,7 @@ private async Task<ImmutableArray<SymbolReference>> GetReferencesForMatchingExte
ImmutableArray<SymbolResult<IMethodSymbol>> methodSymbols, ITypeSymbol typeSymbol) ImmutableArray<SymbolResult<IMethodSymbol>> methodSymbols, ITypeSymbol typeSymbol)
{ {
return GetViableExtensionMethodsWorker(methodSymbols).WhereAsArray( return GetViableExtensionMethodsWorker(methodSymbols).WhereAsArray(
s => _owner.IsViableExtensionMethod(s.Symbol, typeSymbol)); s => IsViableExtensionMethod(s.Symbol, typeSymbol));
} }
private ImmutableArray<SymbolResult<IMethodSymbol>> GetViableExtensionMethodsWorker( private ImmutableArray<SymbolResult<IMethodSymbol>> GetViableExtensionMethodsWorker(
......
...@@ -26,7 +26,7 @@ public ChangeSignatureCodeAction(AbstractChangeSignatureService changeSignatureS ...@@ -26,7 +26,7 @@ public ChangeSignatureCodeAction(AbstractChangeSignatureService changeSignatureS
public override string Title => FeaturesResources.Change_signature; public override string Title => FeaturesResources.Change_signature;
public override object GetOptions(CancellationToken cancellationToken) public override object GetOptions(CancellationToken cancellationToken)
=> _changeSignatureService.GetChangeSignatureOptions(_context) => AbstractChangeSignatureService.GetChangeSignatureOptions(_context)
?? new ChangeSignatureOptionsResult(null!, false); ?? new ChangeSignatureOptionsResult(null!, false);
protected override Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(object options, CancellationToken cancellationToken) protected override Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(object options, CancellationToken cancellationToken)
......
...@@ -166,7 +166,7 @@ public Task DocumentResetAsync(Document document, CancellationToken cancellation ...@@ -166,7 +166,7 @@ public Task DocumentResetAsync(Document document, CancellationToken cancellation
// let other components knows about this event // let other components knows about this event
ClearCompilationsWithAnalyzersCache(); ClearCompilationsWithAnalyzersCache();
var documentHadDiagnostics = _stateManager.OnDocumentReset(stateSets, document); var documentHadDiagnostics = StateManager.OnDocumentReset(stateSets, document);
RaiseDiagnosticsRemovedIfRequiredForClosedOrResetDocument(document, stateSets, documentHadDiagnostics); RaiseDiagnosticsRemovedIfRequiredForClosedOrResetDocument(document, stateSets, documentHadDiagnostics);
} }
...@@ -201,7 +201,7 @@ public Task RemoveDocumentAsync(DocumentId documentId, CancellationToken cancell ...@@ -201,7 +201,7 @@ public Task RemoveDocumentAsync(DocumentId documentId, CancellationToken cancell
// let other components knows about this event // let other components knows about this event
ClearCompilationsWithAnalyzersCache(); 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 // if there was no diagnostic reported for this document, nothing to clean up
// this is Perf to reduce raising events unnecessarily. // this is Perf to reduce raising events unnecessarily.
......
...@@ -62,7 +62,7 @@ private class State ...@@ -62,7 +62,7 @@ private class State
} }
var rules = await document.GetNamingRulesAsync(cancellationToken).ConfigureAwait(false); var rules = await document.GetNamingRulesAsync(cancellationToken).ConfigureAwait(false);
Parameters = service.DetermineParameters(selectedMembers, rules); Parameters = DetermineParameters(selectedMembers, rules);
MatchingConstructor = GetMatchingConstructorBasedOnParameterTypes(ContainingType, Parameters); MatchingConstructor = GetMatchingConstructorBasedOnParameterTypes(ContainingType, Parameters);
// We are going to create a new contructor and pass part of the parameters into DelegatedConstructor, // 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. // so parameters should be compared based on types since we don't want get a type mismatch error after the new constructor is genreated.
......
...@@ -72,7 +72,7 @@ private partial class State ...@@ -72,7 +72,7 @@ private partial class State
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
TypeToGenerateIn = await SymbolFinder.FindSourceDefinitionAsync(TypeToGenerateIn, document.Project.Solution, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol; 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; return false;
} }
...@@ -127,7 +127,7 @@ private partial class State ...@@ -127,7 +127,7 @@ private partial class State
// Either we found no matches, or this was ambiguous. Either way, we might be able // 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 // to generate a method here. Determine where the user wants to generate the method
// into, and if it's valid then proceed. // into, and if it's valid then proceed.
if (!service.TryDetermineTypeToGenerateIn( if (!TryDetermineTypeToGenerateIn(
semanticDocument, containingType, simpleNameOrMemberAccessExpression, cancellationToken, semanticDocument, containingType, simpleNameOrMemberAccessExpression, cancellationToken,
out var typeToGenerateIn, out var isStatic)) out var typeToGenerateIn, out var isStatic))
{ {
......
...@@ -199,7 +199,7 @@ internal new class State : AbstractGenerateParameterizedMemberService<TService, ...@@ -199,7 +199,7 @@ internal new class State : AbstractGenerateParameterizedMemberService<TService,
// to generate a method here. Determine where the user wants to generate the method // to generate a method here. Determine where the user wants to generate the method
// into, and if it's valid then proceed. // into, and if it's valid then proceed.
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
if (!service.TryDetermineTypeToGenerateIn( if (!TryDetermineTypeToGenerateIn(
semanticDocument, ContainingType, SimpleNameOrMemberAccessExpression, cancellationToken, semanticDocument, ContainingType, SimpleNameOrMemberAccessExpression, cancellationToken,
out var typeToGenerateIn, out var isStatic)) out var typeToGenerateIn, out var isStatic))
{ {
......
...@@ -61,7 +61,7 @@ protected async Task<bool> TryFinishInitializingStateAsync(TService service, Sem ...@@ -61,7 +61,7 @@ protected async Task<bool> TryFinishInitializingStateAsync(TService service, Sem
return false; return false;
} }
if (!service.ValidateTypeToGenerateIn(TypeToGenerateIn, IsStatic, ClassInterfaceModuleStructTypes)) if (!ValidateTypeToGenerateIn(TypeToGenerateIn, IsStatic, ClassInterfaceModuleStructTypes))
{ {
return false; return false;
} }
......
...@@ -122,7 +122,7 @@ private partial class State ...@@ -122,7 +122,7 @@ private partial class State
TypeToGenerateIn = await SymbolFinder.FindSourceDefinitionAsync(TypeToGenerateIn, document.Project.Solution, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol; 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; return false;
} }
...@@ -247,7 +247,7 @@ internal bool CanGenerateParameter() ...@@ -247,7 +247,7 @@ internal bool CanGenerateParameter()
// to generate a method here. Determine where the user wants to generate the method // to generate a method here. Determine where the user wants to generate the method
// into, and if it's valid then proceed. // into, and if it's valid then proceed.
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
if (!service.TryDetermineTypeToGenerateIn(semanticDocument, ContainingType, SimpleNameOrMemberAccessExpressionOpt, cancellationToken, if (!TryDetermineTypeToGenerateIn(semanticDocument, ContainingType, SimpleNameOrMemberAccessExpressionOpt, cancellationToken,
out var typeToGenerateIn, out var isStatic)) out var typeToGenerateIn, out var isStatic))
{ {
return false; return false;
......
...@@ -300,7 +300,7 @@ private bool GenerateInterface(TService service) ...@@ -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 // If we are generating in a website project, we also want to type to be public so the
// designer files can access the type. // designer files can access the type.
if (documentToBeGeneratedIn.Project != document.Project || if (documentToBeGeneratedIn.Project != document.Project ||
service.GeneratedTypesMustBePublic(documentToBeGeneratedIn.Project)) GeneratedTypesMustBePublic(documentToBeGeneratedIn.Project))
{ {
IsPublicAccessibilityForTypeGeneration = true; IsPublicAccessibilityForTypeGeneration = true;
} }
......
...@@ -11,7 +11,9 @@ namespace Microsoft.CodeAnalysis.ReplaceMethodWithProperty ...@@ -11,7 +11,9 @@ namespace Microsoft.CodeAnalysis.ReplaceMethodWithProperty
{ {
internal abstract class AbstractReplaceMethodWithPropertyService<TMethodDeclarationSyntax> where TMethodDeclarationSyntax : SyntaxNode internal abstract class AbstractReplaceMethodWithPropertyService<TMethodDeclarationSyntax> where TMethodDeclarationSyntax : SyntaxNode
{ {
public static async Task<SyntaxNode> GetMethodDeclarationAsync(CodeRefactoringContext context) #pragma warning disable CA1822 // Mark members as static - implements interface method for sub-types.
public async Task<SyntaxNode> GetMethodDeclarationAsync(CodeRefactoringContext context)
#pragma warning restore CA1822 // Mark members as static
=> await context.TryGetRelevantNodeAsync<TMethodDeclarationSyntax>().ConfigureAwait(false); => await context.TryGetRelevantNodeAsync<TMethodDeclarationSyntax>().ConfigureAwait(false);
protected static string GetWarning(GetAndSetMethods getAndSetMethods) protected static string GetWarning(GetAndSetMethods getAndSetMethods)
......
...@@ -233,7 +233,7 @@ public FixAllContext WithCancellationToken(CancellationToken cancellationToken) ...@@ -233,7 +233,7 @@ public FixAllContext WithCancellationToken(CancellationToken cancellationToken)
} }
internal Task<ImmutableDictionary<Document, ImmutableArray<Diagnostic>>> GetDocumentDiagnosticsToFixAsync() internal Task<ImmutableDictionary<Document, ImmutableArray<Diagnostic>>> GetDocumentDiagnosticsToFixAsync()
=> State.DiagnosticProvider.GetDocumentDiagnosticsToFixAsync(this); => DiagnosticProvider.GetDocumentDiagnosticsToFixAsync(this);
internal Task<ImmutableDictionary<Project, ImmutableArray<Diagnostic>>> GetProjectDiagnosticsToFixAsync() internal Task<ImmutableDictionary<Project, ImmutableArray<Diagnostic>>> GetProjectDiagnosticsToFixAsync()
=> State.DiagnosticProvider.GetProjectDiagnosticsToFixAsync(this); => State.DiagnosticProvider.GetProjectDiagnosticsToFixAsync(this);
......
...@@ -342,7 +342,7 @@ public override SyntaxNode Apply(SyntaxNode root, SyntaxGenerator generator) ...@@ -342,7 +342,7 @@ public override SyntaxNode Apply(SyntaxNode root, SyntaxGenerator generator)
newNodes[i] = _editor.ApplyTrackingToNewNode(newNodes[i]); newNodes[i] = _editor.ApplyTrackingToNewNode(newNodes[i]);
} }
return generator.ReplaceNode(root, current, newNodes); return SyntaxGenerator.ReplaceNode(root, current, newNodes);
} }
} }
......
...@@ -47,7 +47,7 @@ public async ValueTask<PinnedRemotableDataScope> CreatePinnedRemotableDataScopeA ...@@ -47,7 +47,7 @@ public async ValueTask<PinnedRemotableDataScope> CreatePinnedRemotableDataScopeA
{ {
using (Logger.LogBlock(FunctionId.SolutionSynchronizationServiceFactory_CreatePinnedRemotableDataScopeAsync, cancellationToken)) 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); var checksum = await solution.State.GetChecksumAsync(cancellationToken).ConfigureAwait(false);
return PinnedRemotableDataScope.Create(_assetStorages, storage, checksum); return PinnedRemotableDataScope.Create(_assetStorages, storage, checksum);
......
...@@ -109,7 +109,7 @@ protected virtual SyntaxNode TransformReducedNode(SyntaxNode reducedNode, Syntax ...@@ -109,7 +109,7 @@ protected virtual SyntaxNode TransformReducedNode(SyntaxNode reducedNode, Syntax
// prep namespace imports marked for simplification // prep namespace imports marked for simplification
var removeIfUnusedAnnotation = new SyntaxAnnotation(); var removeIfUnusedAnnotation = new SyntaxAnnotation();
var originalRoot = root; var originalRoot = root;
root = this.PrepareNamespaceImportsForRemovalIfUnused(document, root, removeIfUnusedAnnotation, isNodeOrTokenOutsideSimplifySpans); root = PrepareNamespaceImportsForRemovalIfUnused(document, root, removeIfUnusedAnnotation, isNodeOrTokenOutsideSimplifySpans);
var hasImportsToSimplify = root != originalRoot; var hasImportsToSimplify = root != originalRoot;
if (hasImportsToSimplify) if (hasImportsToSimplify)
......
...@@ -12,9 +12,9 @@ internal static partial class IIncrementalAnalyzerExtensions ...@@ -12,9 +12,9 @@ internal static partial class IIncrementalAnalyzerExtensions
public static BackgroundAnalysisScope GetOverriddenBackgroundAnalysisScope(this IIncrementalAnalyzer incrementalAnalyzer, OptionSet options, BackgroundAnalysisScope defaultBackgroundAnalysisScope) public static BackgroundAnalysisScope GetOverriddenBackgroundAnalysisScope(this IIncrementalAnalyzer incrementalAnalyzer, OptionSet options, BackgroundAnalysisScope defaultBackgroundAnalysisScope)
{ {
// Unit testing analyzer has special semantics for analysis scope. // 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; return defaultBackgroundAnalysisScope;
......
...@@ -1472,7 +1472,7 @@ protected virtual void ApplyProjectChanges(ProjectChanges projectChanges) ...@@ -1472,7 +1472,7 @@ protected virtual void ApplyProjectChanges(ProjectChanges projectChanges)
{ {
var document = projectChanges.NewProject.GetDocument(documentId)!; var document = projectChanges.NewProject.GetDocument(documentId)!;
var text = document.GetTextSynchronously(CancellationToken.None); var text = document.GetTextSynchronously(CancellationToken.None);
var info = this.CreateDocumentInfoWithoutText(document); var info = CreateDocumentInfoWithoutText(document);
this.ApplyDocumentAdded(info, text); this.ApplyDocumentAdded(info, text);
} }
...@@ -1481,7 +1481,7 @@ protected virtual void ApplyProjectChanges(ProjectChanges projectChanges) ...@@ -1481,7 +1481,7 @@ protected virtual void ApplyProjectChanges(ProjectChanges projectChanges)
{ {
var document = projectChanges.NewProject.GetAdditionalDocument(documentId)!; var document = projectChanges.NewProject.GetAdditionalDocument(documentId)!;
var text = document.GetTextSynchronously(CancellationToken.None); var text = document.GetTextSynchronously(CancellationToken.None);
var info = this.CreateDocumentInfoWithoutText(document); var info = CreateDocumentInfoWithoutText(document);
this.ApplyAdditionalDocumentAdded(info, text); this.ApplyAdditionalDocumentAdded(info, text);
} }
...@@ -1490,7 +1490,7 @@ protected virtual void ApplyProjectChanges(ProjectChanges projectChanges) ...@@ -1490,7 +1490,7 @@ protected virtual void ApplyProjectChanges(ProjectChanges projectChanges)
{ {
var document = projectChanges.NewProject.GetAnalyzerConfigDocument(documentId)!; var document = projectChanges.NewProject.GetAnalyzerConfigDocument(documentId)!;
var text = document.GetTextSynchronously(CancellationToken.None); var text = document.GetTextSynchronously(CancellationToken.None);
var info = this.CreateDocumentInfoWithoutText(document); var info = CreateDocumentInfoWithoutText(document);
this.ApplyAnalyzerConfigDocumentAdded(info, text); this.ApplyAnalyzerConfigDocumentAdded(info, text);
} }
......
...@@ -20,7 +20,12 @@ namespace Microsoft.CodeAnalysis.Remote ...@@ -20,7 +20,12 @@ namespace Microsoft.CodeAnalysis.Remote
{ {
internal partial class AggregateJsonConverter : JsonConverter internal partial class AggregateJsonConverter : JsonConverter
{ {
static partial void AppendRoslynSpecificJsonConverters(ImmutableDictionary<Type, JsonConverter>.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<Type, JsonConverter>.Builder builder)
#pragma warning restore CA1822 // Mark members as static
{ {
Add(builder, new HighlightSpanJsonConverter()); Add(builder, new HighlightSpanJsonConverter());
Add(builder, new TaggedTextJsonConverter()); Add(builder, new TaggedTextJsonConverter());
......
...@@ -162,7 +162,7 @@ public override AbstractFormattingRule WithOptions(AnalyzerConfigOptions options ...@@ -162,7 +162,7 @@ public override AbstractFormattingRule WithOptions(AnalyzerConfigOptions options
// Semicolons in an empty for statement. i.e. for(;;) // Semicolons in an empty for statement. i.e. for(;;)
if (previousParentKind == SyntaxKind.ForStatement if (previousParentKind == SyntaxKind.ForStatement
&& this.IsEmptyForStatement((ForStatementSyntax)previousToken.Parent!)) && IsEmptyForStatement((ForStatementSyntax)previousToken.Parent!))
{ {
if (currentKind == SyntaxKind.SemicolonToken if (currentKind == SyntaxKind.SemicolonToken
&& (previousKind != SyntaxKind.SemicolonToken && (previousKind != SyntaxKind.SemicolonToken
......
...@@ -19,17 +19,14 @@ private class Rewriter : CSharpSyntaxRewriter ...@@ -19,17 +19,14 @@ private class Rewriter : CSharpSyntaxRewriter
{ {
private readonly ISet<UsingDirectiveSyntax> _unnecessaryUsingsDoNotAccessDirectly; private readonly ISet<UsingDirectiveSyntax> _unnecessaryUsingsDoNotAccessDirectly;
private readonly CancellationToken _cancellationToken; private readonly CancellationToken _cancellationToken;
private readonly CSharpRemoveUnnecessaryImportsService _importsService;
private readonly Document _document; private readonly Document _document;
public Rewriter( public Rewriter(
CSharpRemoveUnnecessaryImportsService importsService,
Document document, Document document,
ISet<UsingDirectiveSyntax> unnecessaryUsings, ISet<UsingDirectiveSyntax> unnecessaryUsings,
CancellationToken cancellationToken) CancellationToken cancellationToken)
: base(visitIntoStructuredTrivia: true) : base(visitIntoStructuredTrivia: true)
{ {
_importsService = importsService;
_document = document; _document = document;
_unnecessaryUsingsDoNotAccessDirectly = unnecessaryUsings; _unnecessaryUsingsDoNotAccessDirectly = unnecessaryUsings;
_cancellationToken = cancellationToken; _cancellationToken = cancellationToken;
...@@ -142,7 +139,7 @@ public override SyntaxNode VisitCompilationUnit(CompilationUnitSyntax node) ...@@ -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 // 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. // type. In this case, remove any newlines preceding the type.
var firstToken = resultCompilationUnit.GetFirstToken(); var firstToken = resultCompilationUnit.GetFirstToken();
var newFirstToken = _importsService.StripNewLines(_document, firstToken); var newFirstToken = StripNewLines(_document, firstToken);
resultCompilationUnit = resultCompilationUnit.ReplaceToken(firstToken, newFirstToken); resultCompilationUnit = resultCompilationUnit.ReplaceToken(firstToken, newFirstToken);
} }
...@@ -176,7 +173,7 @@ public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax ...@@ -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 // 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. // type. In this case, remove any newlines preceding the type.
var firstToken = resultNamespace.Members.First().GetFirstToken(); var firstToken = resultNamespace.Members.First().GetFirstToken();
var newFirstToken = _importsService.StripNewLines(_document, firstToken); var newFirstToken = StripNewLines(_document, firstToken);
resultNamespace = resultNamespace.ReplaceToken(firstToken, newFirstToken); resultNamespace = resultNamespace.ReplaceToken(firstToken, newFirstToken);
} }
......
...@@ -53,7 +53,7 @@ protected override IUnnecessaryImportsProvider UnnecessaryImportsProvider ...@@ -53,7 +53,7 @@ protected override IUnnecessaryImportsProvider UnnecessaryImportsProvider
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var oldRoot = (CompilationUnitSyntax)root; 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(); cancellationToken.ThrowIfCancellationRequested();
return document.WithSyntaxRoot(await FormatResultAsync(document, newRoot, cancellationToken).ConfigureAwait(false)); return document.WithSyntaxRoot(await FormatResultAsync(document, newRoot, cancellationToken).ConfigureAwait(false));
......
...@@ -500,19 +500,19 @@ private IEnumerable<TypeInferenceInfo> InferTypeInArgumentList(ArgumentListSynta ...@@ -500,19 +500,19 @@ private IEnumerable<TypeInferenceInfo> InferTypeInArgumentList(ArgumentListSynta
{ {
case InvocationExpressionSyntax invocation: case InvocationExpressionSyntax invocation:
{ {
var index = this.GetArgumentListIndex(argumentList, previousToken); var index = GetArgumentListIndex(argumentList, previousToken);
return InferTypeInInvocationExpression(invocation, index); return InferTypeInInvocationExpression(invocation, index);
} }
case ObjectCreationExpressionSyntax objectCreation: case ObjectCreationExpressionSyntax objectCreation:
{ {
var index = this.GetArgumentListIndex(argumentList, previousToken); var index = GetArgumentListIndex(argumentList, previousToken);
return InferTypeInObjectCreationExpression(objectCreation, index); return InferTypeInObjectCreationExpression(objectCreation, index);
} }
case ConstructorInitializerSyntax constructorInitializer: case ConstructorInitializerSyntax constructorInitializer:
{ {
var index = this.GetArgumentListIndex(argumentList, previousToken); var index = GetArgumentListIndex(argumentList, previousToken);
return InferTypeInConstructorInitializer(constructorInitializer, index); return InferTypeInConstructorInitializer(constructorInitializer, index);
} }
} }
...@@ -530,7 +530,7 @@ private IEnumerable<TypeInferenceInfo> InferTypeInAttributeArgumentList(Attribut ...@@ -530,7 +530,7 @@ private IEnumerable<TypeInferenceInfo> InferTypeInAttributeArgumentList(Attribut
if (attributeArgumentList.Parent is AttributeSyntax attribute) if (attributeArgumentList.Parent is AttributeSyntax attribute)
{ {
var index = this.GetArgumentListIndex(attributeArgumentList, previousToken); var index = GetArgumentListIndex(attributeArgumentList, previousToken);
return InferTypeInAttribute(attribute, index); return InferTypeInAttribute(attribute, index);
} }
......
...@@ -14,14 +14,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryImports ...@@ -14,14 +14,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryImports
Private ReadOnly _unnecessaryImports As ISet(Of ImportsClauseSyntax) Private ReadOnly _unnecessaryImports As ISet(Of ImportsClauseSyntax)
Private ReadOnly _cancellationToken As CancellationToken Private ReadOnly _cancellationToken As CancellationToken
Private ReadOnly _annotation As New SyntaxAnnotation() Private ReadOnly _annotation As New SyntaxAnnotation()
Private ReadOnly _importsService As VisualBasicRemoveUnnecessaryImportsService
Private ReadOnly _document As Document Private ReadOnly _document As Document
Public Sub New(importsService As VisualBasicRemoveUnnecessaryImportsService, Public Sub New(document As Document,
document As Document,
unnecessaryImports As ISet(Of ImportsClauseSyntax), unnecessaryImports As ISet(Of ImportsClauseSyntax),
cancellationToken As CancellationToken) cancellationToken As CancellationToken)
_importsService = importsService
_document = document _document = document
_unnecessaryImports = unnecessaryImports _unnecessaryImports = unnecessaryImports
_cancellationToken = cancellationToken _cancellationToken = cancellationToken
...@@ -117,7 +114,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryImports ...@@ -117,7 +114,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryImports
If newCompilationUnit.Imports.Count = 0 AndAlso newCompilationUnit.Options.Count = 0 Then If newCompilationUnit.Imports.Count = 0 AndAlso newCompilationUnit.Options.Count = 0 Then
If newCompilationUnit.Attributes.Count > 0 OrElse newCompilationUnit.Members.Count > 0 Then If newCompilationUnit.Attributes.Count > 0 OrElse newCompilationUnit.Members.Count > 0 Then
Dim firstToken = newCompilationUnit.GetFirstToken() Dim firstToken = newCompilationUnit.GetFirstToken()
Dim newFirstToken = _importsService.StripNewLines(_document, firstToken) Dim newFirstToken = StripNewLines(_document, firstToken)
newCompilationUnit = newCompilationUnit.ReplaceToken(firstToken, newFirstToken) newCompilationUnit = newCompilationUnit.ReplaceToken(firstToken, newFirstToken)
End If End If
End If End If
......
...@@ -44,7 +44,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryImports ...@@ -44,7 +44,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryImports
Dim root = Await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False) Dim root = Await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False)
Dim oldRoot = DirectCast(root, CompilationUnitSyntax) 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) newRoot = newRoot.WithAdditionalAnnotations(Formatter.Annotation)
cancellationToken.ThrowIfCancellationRequested() cancellationToken.ThrowIfCancellationRequested()
......
...@@ -48,7 +48,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration ...@@ -48,7 +48,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Return Nothing Return Nothing
End Function 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 members = destination.Members
Dim indices = New List(Of Boolean) Dim indices = New List(Of Boolean)
......
...@@ -41,7 +41,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Editing ...@@ -41,7 +41,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Editing
Return Rewriter.Visit(root) Return Rewriter.Visit(root)
End Function 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. ' name must refer to something that is not a namespace, but be qualified with a namespace.
Dim Symbol = model.GetSymbolInfo(fullName).Symbol Dim Symbol = model.GetSymbolInfo(fullName).Symbol
Dim nsSymbol = TryCast(model.GetSymbolInfo(namespacePart).Symbol, INamespaceSymbol) Dim nsSymbol = TryCast(model.GetSymbolInfo(namespacePart).Symbol, INamespaceSymbol)
......
...@@ -92,7 +92,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation ...@@ -92,7 +92,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation
AddIndentBlockOperations(list, parameterOrArgumentList, indentationDelta) AddIndentBlockOperations(list, parameterOrArgumentList, indentationDelta)
End Sub 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 openBrace = parameterOrArgumentList.GetFirstToken(includeZeroWidth:=True)
Dim closeBrace = parameterOrArgumentList.GetLastToken(includeZeroWidth:=True) Dim closeBrace = parameterOrArgumentList.GetLastToken(includeZeroWidth:=True)
...@@ -211,7 +211,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation ...@@ -211,7 +211,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation
AddAlignTokensOperations(operations, baseToken) AddAlignTokensOperations(operations, baseToken)
End Sub 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( operations.Add(FormattingOperations.CreateAlignTokensOperation(
baseToken, baseToken,
SpecializedCollections.SingletonEnumerable(baseToken.GetNextToken(includeZeroWidth:=True)), SpecializedCollections.SingletonEnumerable(baseToken.GetNextToken(includeZeroWidth:=True)),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册