I'm working on a code editor using Roslyn and, for debugging, MDbg.
In the editor, I'm aiming for visual studio-like behavior for setting breakpoints. That is, the user can click on a line, and I will need to figure out
- Is that a source location at which I can actually set a breakpoint?, and
- if it is, in what line should the breakpoint be set?
For example, assuming the user has a document like:
line 01: using System;
line 02:
line 03: public class SomeClass
line 04: {
line 05: public string someMethod()
line 06: {
line 07: return @"
line 08: abcdefg
line 09: ";
line 10: }
line 11: }
When clicking on line 1, nothing should happen - can't really set a breakpoint on a using statement.
When clicking line 3, it should set a breakpoint at line 4 (can't set a breakpoint on the method definition itself, but rather at the start brace token where method execution begins).
When clicking line 7, 8 or 9, it should set a breakpoint on line 7 as this thing is just one statement.
To be honest, at the moment I don't even have any ideas how to approach this at all.. Would anybody have any pointers how to conceptually approach this? I was hoping Roslyn might have some useful helper methods, but I haven't found much in its source related to breakpoints
Just to repeat, the base question I think comes down to figuring out
- is a certain line in code a location at which I can actually set a breakpoint?, and
- if it is, in what line should the breakpoint be set?
Thanks!
As mentioned in the comment, this does exactly what you need: http://sourceroslyn.io/#Microsoft.VisualStudio.LanguageServices.CSharp/Debugging/CSharpBreakpointResolutionService.cs,6a9951745157788a