提交 46858dd3 编写于 作者: A Artur Spychaj

Merge pull request #6531 from drognanar/bug4230

Support removal namespace in interactive mode
......@@ -622,6 +622,29 @@ static void Foo(int a)
edits.VerifyRudeDiagnostics(active);
}
[WpfFact]
public void Delete_EntireNamespace()
{
string src1 = @"
namespace N
{
class C
{
static void Main(String[] args)
{
<AS:0>Console.WriteLine(1);</AS:0>
}
}
}";
string src2 = @"<AS:0></AS:0>";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.Delete, null, "namespace"));
}
#endregion
#region Constructors
......
......@@ -112,7 +112,8 @@ internal static int[] GetIds(string ids)
var ids = GetIds(match.Groups["Id"].Value);
int absoluteOffset = offset + markedSyntax.Index;
yield return ValueTuple.Create(new TextSpan(absoluteOffset, markedSyntax.Length), ids);
var span = markedSyntax.Length != 0 ? new TextSpan(absoluteOffset, markedSyntax.Length) : new TextSpan();
yield return ValueTuple.Create(span, ids);
foreach (var nestedSpan in GetSpansRecursive(regex, contentGroupName, markedSyntax.Value, absoluteOffset))
{
......
......@@ -554,16 +554,17 @@ private SyntaxNode FindStatement(SyntaxNode declarationBody, int position, out i
Debug.Assert(updatedMethods.Count == 0);
var updatedTrackingSpans = new List<KeyValuePair<ActiveStatementId, TextSpan>>();
BitVector editedActiveStatements = BitVector.Create(newActiveStatements.Length);
for (int i = 0; i < script.Edits.Length; i++)
{
var edit = script.Edits[i];
AnalyzeUpdatedActiveMethodBodies(script, i, editMap, oldText, newText, documentId, trackingService, oldActiveStatements, newActiveStatements, newExceptionRegions, updatedMethods, updatedTrackingSpans, diagnostics);
AnalyzeUpdatedActiveMethodBodies(script, i, editMap, oldText, newText, documentId, trackingService, oldActiveStatements, ref editedActiveStatements, newActiveStatements, newExceptionRegions, updatedMethods, updatedTrackingSpans, diagnostics);
ReportSyntacticRudeEdits(diagnostics, script.Match, edit, editMap);
}
UpdateUneditedSpans(diagnostics, script.Match, oldText, newText, documentId, trackingService, oldActiveStatements, newActiveStatements, newExceptionRegions, updatedTrackingSpans);
UpdateUneditedSpans(diagnostics, script.Match, oldText, newText, documentId, trackingService, oldActiveStatements, editedActiveStatements, newActiveStatements, newExceptionRegions, updatedTrackingSpans);
if (updatedTrackingSpans.Count > 0)
{
......@@ -579,6 +580,7 @@ private SyntaxNode FindStatement(SyntaxNode declarationBody, int position, out i
DocumentId documentId,
IActiveStatementTrackingService trackingService,
ImmutableArray<ActiveStatementSpan> oldActiveStatements,
BitVector editedActiveStatements,
[In, Out]LinePositionSpan[] newActiveStatements,
[In, Out]ImmutableArray<LinePositionSpan>[] newExceptionRegions,
[In, Out]List<KeyValuePair<ActiveStatementId, TextSpan>> updatedTrackingSpans)
......@@ -591,7 +593,7 @@ private SyntaxNode FindStatement(SyntaxNode declarationBody, int position, out i
for (int i = 0; i < newActiveStatements.Length; i++)
{
if (newActiveStatements[i] == default(LinePositionSpan))
if (!editedActiveStatements[i])
{
Debug.Assert(newExceptionRegions[i].IsDefault);
......@@ -840,6 +842,7 @@ internal struct UpdatedMemberInfo
DocumentId documentId,
IActiveStatementTrackingService trackingService,
ImmutableArray<ActiveStatementSpan> oldActiveStatements,
ref BitVector editedActiveStatements,
[Out]LinePositionSpan[] newActiveStatements,
[Out]ImmutableArray<LinePositionSpan>[] newExceptionRegions,
[Out]List<UpdatedMemberInfo> updatedMembers,
......@@ -886,8 +889,8 @@ internal struct UpdatedMemberInfo
// TODO: VB field multi-initializers break this
// Debug.Assert(newActiveStatements[i] == default(LinePositionSpan));
Debug.Assert(newSpan != default(TextSpan));
newActiveStatements[i] = newText.Lines.GetLinePositionSpan(newSpan);
editedActiveStatements[i] = true;
newExceptionRegions[i] = ImmutableArray.Create<LinePositionSpan>();
}
}
......@@ -906,6 +909,7 @@ internal struct UpdatedMemberInfo
{
Debug.Assert(newActiveStatements[i] == default(LinePositionSpan) && newSpan != default(TextSpan));
newActiveStatements[i] = newText.Lines.GetLinePositionSpan(newSpan);
editedActiveStatements[i] = true;
newExceptionRegions[i] = ImmutableArray.Create<LinePositionSpan>();
}
}
......@@ -1084,6 +1088,7 @@ internal struct UpdatedMemberInfo
Debug.Assert(newActiveStatements[ordinal] == default(LinePositionSpan) && newSpan != default(TextSpan));
newActiveStatements[ordinal] = newText.Lines.GetLinePositionSpan(newSpan);
editedActiveStatements[ordinal] = true;
// Update tracking span if we found a matching active statement whose span is different.
// It could have been deleted or moved out of the method/lambda body, in which case we set it to empty.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册