diff --git a/src/EditorFeatures/CSharpTest/EditAndContinue/StatementEditingTests.cs b/src/EditorFeatures/CSharpTest/EditAndContinue/StatementEditingTests.cs index 17c798fa60422..ee4df8c5e2fa4 100644 --- a/src/EditorFeatures/CSharpTest/EditAndContinue/StatementEditingTests.cs +++ b/src/EditorFeatures/CSharpTest/EditAndContinue/StatementEditingTests.cs @@ -7153,6 +7153,51 @@ static void Main(int X) capabilities: EditAndContinueTestHelpers.Net6RuntimeCapabilities); } + [Fact] + public void LocalFunctions_Update() + { + var src1 = @" +using System; + +class C +{ + void M() + { + N(3); + + void N(int x) + { + if (x > 3) + { + x.ToString(); + } + else + { + N(x - 1); + } + } + } +}"; + var src2 = @" +using System; + +class C +{ + void M() + { + N(3); + + void N(int x) + { + Console.WriteLine(""Hello""); + } + } +}"; + var edits = GetTopEdits(src1, src2); + + edits.VerifySemantics(SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.M"), preserveLocalVariables: true)); + } + [Fact] public void LocalFunction_In_Parameter_InsertWhole() { @@ -7727,7 +7772,6 @@ public void LocalFunctions_TypeParameter_Reorder() "Reorder [B]@11 -> @9"); GetTopEdits(edits).VerifyRudeDiagnostics( - Diagnostic(RudeEditKind.Move, "B", FeaturesResources.type_parameter), Diagnostic(RudeEditKind.ChangingTypeParameters, "L", FeaturesResources.local_function)); } @@ -7743,7 +7787,6 @@ public void LocalFunctions_TypeParameter_ReorderAndUpdate() "Update [A]@9 -> [C]@11"); GetTopEdits(edits).VerifyRudeDiagnostics( - Diagnostic(RudeEditKind.Move, "B", FeaturesResources.type_parameter), Diagnostic(RudeEditKind.ChangingTypeParameters, "L", FeaturesResources.local_function)); } diff --git a/src/Features/CSharp/Portable/EditAndContinue/CSharpEditAndContinueAnalyzer.cs b/src/Features/CSharp/Portable/EditAndContinue/CSharpEditAndContinueAnalyzer.cs index f07455ff5b6cf..b1a2d53a52b0d 100644 --- a/src/Features/CSharp/Portable/EditAndContinue/CSharpEditAndContinueAnalyzer.cs +++ b/src/Features/CSharp/Portable/EditAndContinue/CSharpEditAndContinueAnalyzer.cs @@ -728,22 +728,6 @@ newNode is MethodDeclarationSyntax && } } - protected override void ReportLocalFunctionsDeclarationRudeEdits(ArrayBuilder diagnostics, Match bodyMatch) - { - var bodyEditsForLambda = bodyMatch.GetTreeEdits(); - var editMap = BuildEditMap(bodyEditsForLambda); - foreach (var edit in bodyEditsForLambda.Edits) - { - if (HasParentEdit(editMap, edit)) - { - return; - } - - var classifier = new EditClassifier(this, diagnostics, edit.OldNode, edit.NewNode, edit.Kind, bodyMatch); - classifier.ClassifyEdit(); - } - } - protected override bool TryMatchActiveStatement( SyntaxNode oldStatement, int statementPart, diff --git a/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs b/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs index 320b1ef6b48f1..4bec59130d607 100644 --- a/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs +++ b/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs @@ -398,8 +398,6 @@ protected virtual string GetSuspensionPointDisplayName(SyntaxNode node, EditKind protected abstract void GetStateMachineInfo(SyntaxNode body, out ImmutableArray suspensionPoints, out StateMachineKinds kinds); protected abstract TextSpan GetExceptionHandlingRegion(SyntaxNode node, out bool coversAllChildren); - protected abstract void ReportLocalFunctionsDeclarationRudeEdits(ArrayBuilder diagnostics, Match bodyMatch); - internal abstract void ReportTopLevelSyntacticRudeEdits(ArrayBuilder diagnostics, Match match, Edit edit, Dictionary editMap); internal abstract void ReportEnclosingExceptionHandlingRudeEdits(ArrayBuilder diagnostics, IEnumerable> exceptionHandlingEdits, SyntaxNode oldStatement, TextSpan newStatementSpan); internal abstract void ReportOtherRudeEditsAroundActiveStatement(ArrayBuilder diagnostics, Match match, SyntaxNode oldStatement, SyntaxNode newStatement, bool isNonLeaf); @@ -1430,7 +1428,7 @@ private Match ComputeBodyMatch( if (IsLocalFunction(match.OldRoot) && IsLocalFunction(match.NewRoot)) { - ReportLocalFunctionsDeclarationRudeEdits(diagnostics, match); + ReportMemberBodyUpdateRudeEdits(diagnostics, match.NewRoot, match.NewRoot.Span); } if (lazyRudeEdits != null) diff --git a/src/Features/VisualBasic/Portable/EditAndContinue/VisualBasicEditAndContinueAnalyzer.vb b/src/Features/VisualBasic/Portable/EditAndContinue/VisualBasicEditAndContinueAnalyzer.vb index 4ed7bcf90254a..465a500547dc6 100644 --- a/src/Features/VisualBasic/Portable/EditAndContinue/VisualBasicEditAndContinueAnalyzer.vb +++ b/src/Features/VisualBasic/Portable/EditAndContinue/VisualBasicEditAndContinueAnalyzer.vb @@ -1415,10 +1415,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EditAndContinue Return True End Select End Function - - Protected Overrides Sub ReportLocalFunctionsDeclarationRudeEdits(diagnostics As ArrayBuilder(Of RudeEditDiagnostic), bodyMatch As Match(Of SyntaxNode)) - ' VB has no local functions so we don't have anything to report - End Sub #End Region #Region "Diagnostic Info"