Roslyn: Given a source location/line, how to figure out if - and where - breakpoint can be set

402 views Asked by At

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

  1. Is that a source location at which I can actually set a breakpoint?, and
  2. 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

  1. is a certain line in code a location at which I can actually set a breakpoint?, and
  2. if it is, in what line should the breakpoint be set?

Thanks!

1

There are 1 answers

0
Tamas On BEST ANSWER