2

Is there a way to run my .fs file with either a breakpoint or a command like System.Diagnostics.Debugger.Launch() in it so that I can use FSI to examine values, apply functions to them, plot them, etc.?

I know this question has been asked before but I tried the answers and could not make them work. Clear instructions or a link to a write-up explaining the process would be of great help not only to myself, but also, I believe, to all beginners.

Soldalma
  • 4,636
  • 3
  • 25
  • 38

2 Answers2

1

Unfortunately, you cannot hit a breakpoint and jump into FSI. The context of a running .NET program is quite different to that of an interactive FSI session and they are not compatible enough to just switch between one or the other. I can understand an expectation of this kind of debugging when coming from other dynamic/interpreted languages such as JavaScript, Python etc. It is a really powerful feature.

As you have already noted, you can use the VS immediate window but you need to use its C#-like syntax and respect its limitations. Also, since it's not F#, you need to understand the F# to .NET conversion in order to make full use of it.

If you use Paket for dependency management in your project you have another option: Add generate_load_scripts: true to your paket.dependencies. This will give you a file like .paket\load\net452\main.group.fsx, which you can load into FSI to get all of the dependencies for your project. However, you are still responsible for loading in your own source files and building up some state similar to what is found at your desired breakpoint.

TheQuickBrownFox
  • 10,544
  • 1
  • 22
  • 35
  • Thanks. Just to clarify, is there an advantage of the Paket method you are suggesting over using #load and #r commands? – Soldalma Jul 31 '17 at 01:09
  • 2
    @Soldalma - If you have multiple dependencies in your project, keeping track of all the different `#r` commands can start to become a hassle, and then you have to update all of them by hand if you add a new dependency (and if you have a dozen scripts, it's easy to forget to update one script out of a dozen). The scripts that Paket generates put all the `#r` commands together in one place, so that you can just run `#load (path)/main.group.fsx` at the top of each script -- and every time you add a new dependency, Paket keeps the `main.group.fsx` file up-to-date for you automatically. – rmunn Jul 31 '17 at 04:21
0

To hit a break point, in visual studio or visual studio code, you just click to the left of the line number you want to set your breakpoint. This is very much a supported feature in .fs files.

JosephStevens
  • 1,668
  • 1
  • 15
  • 17
  • I know how to set and use breakpoints. My question was about `FSI`. – Soldalma Jul 28 '17 at 22:38
  • Ah, my apologies. So you want to use the FSharp interactive window to test your code in your .FS files? – JosephStevens Jul 28 '17 at 22:56
  • I want to use FSI to debug my files. That is, set a breakpoint, then instead of using the Locals window, the Immediate window, and the Watch window I would like to use FSI. – Soldalma Jul 28 '17 at 23:06
  • Apologies, but I don't think Fsharp Interactive works that way. The FSI window is for running a few lines of code at a time, that lets you explore your code without the need for breakpoints. – JosephStevens Jul 29 '17 at 12:43