Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 5655056

Browse files
authored
Merge pull request #8933 from mono/vsts-958245
[Debugger] Handle case when the text snapshot has less lines than the breakpoint location
2 parents a46255b + eaed73b commit 5655056

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

main/src/addins/CSharpBinding/MonoDevelop.CSharp.Debugger/DebuggerCompletionController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ public async Task<CompletionData> GetExpressionCompletionDataAsync (string exp,
123123
return null;
124124
var solution = document.Project.Solution;
125125
var textSnapshot = textBuffer.CurrentSnapshot;
126+
127+
if (location.EndLine > textSnapshot.LineCount)
128+
return null;
129+
126130
var text = textSnapshot.GetText (new Span (0, textSnapshot.Length));
127131
var insertOffset = await GetAdjustedContextPointAsync (textSnapshot.GetLineFromLineNumber (location.EndLine - 1).Start.Position + location.EndColumn - 1, document, token).ConfigureAwait(false);
128132
text = text.Insert (insertOffset, ";" + exp + ";");

main/tests/MonoDevelop.CSharpBinding.Tests/MonoDevelop.CSharpBinding.Debugging/DebuggerCompletionControllerTests.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,82 @@ static void Method2 (int a)
113113
Assert.That (items, Contains.Item ("Method2"));
114114
Assert.AreEqual (1, completionResult.ExpressionLength);
115115
}
116+
117+
[Test]
118+
public async Task HandlesWhenTextBufferChangesAndContainsLessLines ()
119+
{
120+
var contentType = MimeTypeCatalog.Instance.GetContentTypeForMimeType ("text/x-csharp");
121+
122+
var text = @"
123+
namespace console61
124+
{
125+
class MainClass
126+
{
127+
static void MethodA (int a)
128+
{
129+
}
130+
131+
static void MethodB (int a)
132+
{
133+
}
134+
135+
static void MethodC (int a)
136+
{
137+
}
138+
139+
public static void Main (string [] args)
140+
{
141+
$Console.WriteLine(2);$
142+
}
143+
144+
static void Method2 (int a)
145+
{
146+
}
147+
}
148+
}
149+
";
150+
151+
var textAfter = @"
152+
namespace console61
153+
{
154+
class MainClass
155+
{
156+
}
157+
158+
static void MethodZ (int a)
159+
{
160+
}
161+
}
162+
";
163+
164+
int startOfStatement = text.IndexOf ('$');
165+
if (startOfStatement >= 0)
166+
text = text.Substring (0, startOfStatement) + text.Substring (startOfStatement + 1);
167+
int endOfStatement = text.IndexOf ('$');
168+
if (endOfStatement >= 0)
169+
text = text.Substring (0, endOfStatement) + text.Substring (endOfStatement + 1);
170+
171+
var buffer = PlatformCatalog.Instance.TextBufferFactoryService.CreateTextBuffer (text, contentType);
172+
var doc = GetAnalysisDocument (text);
173+
174+
var snapshot = buffer.CurrentSnapshot;
175+
var startLine = snapshot.GetLineFromPosition (startOfStatement);
176+
var startColumn = startOfStatement - startLine.Start.Position;
177+
var endLine = snapshot.GetLineFromPosition (endOfStatement);
178+
var endColumn = endOfStatement - endLine.Start.Position;
179+
180+
// get the stack frame
181+
var stackFrame = new StackFrame (0, new SourceLocation ("", "", startLine.LineNumber, startColumn, endLine.LineNumber, endColumn), "C#");
182+
183+
// now, alter the source so that the stack frame's location appear after the last line in the buffer
184+
var bufferAfter = PlatformCatalog.Instance.TextBufferFactoryService.CreateTextBuffer (textAfter, contentType);
185+
var docAfter = GetAnalysisDocument (textAfter);
186+
var controller = new DebuggerCompletionProvider (docAfter, bufferAfter);
187+
188+
var completionResult =
189+
await controller.GetExpressionCompletionDataAsync ("a", stackFrame, default);
190+
191+
Assert.IsNull (completionResult);
192+
}
116193
}
117194
}

0 commit comments

Comments
 (0)