1

I am writing an extension in VS Code that has a graphical editor (similar to a flow chart) that persists its data in a text file. All editing is done via the graphical editor. The text file is too cryptic for users to work with. I would like to implement a debugger for the underlying file, which means users should be able to set breakpoints on the steps within the graphical editor and proceed from step to step within the editor. A couple of questions: 1) Am I way off base here? Does the VS Code debug framework only support setting breakpoints in text files? 2) Can breakpoints be set programmatically (if so, how)?

I have looked at Ballerina which has both a text editor and a graphical editor that are synchronized. I can set breakpoints in the text editor only.

Thanks for any help.

BarryDrez
  • 21
  • 3
  • I don't think you're off base, but what you're trying to accomplish seems very hard, and it's certainly too broad a question for a site like StackOverflow. Good luck though, get back to us with your solution! – Guillaume CR Mar 26 '19 at 20:32
  • @GuillaumeCR - thanks. The VS Code Extension API (https://code.visualstudio.com/api) page suggests posting questions here. I will try other places to invoke a response, and I will certainly post any reasonable solution(s) here. – BarryDrez Mar 26 '19 at 21:04
  • BarryDrez Yes, debug points can be set programmatically. You need to build a debug extension. Check https://code.visualstudio.com/api/extension-guides/debugger-extension – Aruna Herath Mar 27 '19 at 06:39
  • Thanks @ArunaHerath. I have been looking at this page, but there is no indication as to how to set breakpoints programmatically. – BarryDrez Mar 27 '19 at 11:03
  • Hey, have you made any progress with this? – Omar Dulaimi Mar 18 '22 at 12:24

2 Answers2

1

Fortunately, @weinand on the gitter.im/Microsoft/vscode channel. He pointed me to: github.com/Microsoft/vscode/blob/master/src/vs/vscode.d.ts - addBreakpoints. This is what I was looking for

BarryDrez
  • 21
  • 3
  • Hey, have you managed to get it to work? I would really appreciate a working snippet. – Omar Dulaimi Mar 18 '22 at 12:12
  • Tried it out, does not work. I am able to get the breakpoints I set myself via vscode.debug.addBreapoints from the vscode.debug.breakpoints variable and I can set a change event handler with vscode.debug.onDidChangeBreakpoints, but the breakpoints I set manually are not accessible there & also when I set one manually the debugger doesn't break. So it seems this is not the way to do it. – tietze111 Jun 07 '22 at 12:26
  • 1
    I just had an idea that worked, I wanted to set a breakpoint when a specific function is called. Since VSCode is based on electron & chrome, this works: https://stackoverflow.com/questions/10050465/how-to-set-a-javascript-breakpoint-from-code-in-chrome I was able to break when a function was called by just executing `debug(myFunction)` – tietze111 Jun 07 '22 at 12:30
-1

I may be a bit late to the party, but this link from Microsoft's official documentation has the answer to this question.

Essentially, you have to access the list of breakpoints of your debugger object and use the Add method to create new ones:

EnvDTE.Debugger debugger = (EnvDTE.Debugger)dte.Debugger;

debugger.Breakpoints.Add("","Target001.cs", 13, 1, "",   
                             EnvDTE.dbgBreakpointConditionType.dbgBreakpointConditionTypeWhenTrue,   
                             "C#","", 0, "", 0, EnvDTE.dbgHitCountType.dbgHitCountTypeNone);  
ggmendez
  • 601
  • 7
  • 18