I’ve been using Visual Studio Code (VSCode) for the majority of my F# development since December 2016. I have to admit it has become my prototyping tool of choice. Visual Studio Code is a nice lightweight IDE, if you can call it an IDE. It’s more of a text editor with a great set of extensions. VSCode loads very quickly which makes it excellent for testing out those single shot ideas. VSCode is a cross platform editor which contributes to its ease of use. You get relatively the same feel on Windows, Mac OSx, or linux. Visual Studio Code, with a few extensions, has become my main editor for prototyping in F#.
If you haven’t looked at VSCode before, you can get it at https://code.visualstudio.com/.
The very first thing I do after installing VSCode is getting the Ionide-fsharp extension. You can install the extension by going to View -> Extensions in the menu. In the extensions window, enter ionide-fsharp in the search box. The extension should show in the results window with an install button.
Ionide-Fsharp will give you access to F# Interactive (F#’s REPL) from within VSCode. You also get a wide range of benefits such as syntax highlighting, codelens for function types, hover tooltips, and more. When it comes to prototyping though, having immediate feedback of a REPL is the best tool one could have.
I add some custom keybindings in VSCode for interacting with the REPL. My preferred shortcuts are as follows:
- Ctrl+i – Starts / restarts the REPL
- Ctrl+’ – Sends the current line from the editor to the REPL for evaluation
- Ctrl+; – Sends the selection of code from the editor to the REPL
You can modify the keybindings by going into (Mac) Code -> Preferences -> Keyboard Shortcuts or (Windows) File -> Preferences -> Keyboard Shortcuts and adding the code snippet below:
{ "key": "ctrl+;", "command": "fsi.SendSelection", "when": "editorTextFocus" }, { "key": "ctrl+'", "command": "fsi.SendLine", "when": "editorTextFocus" }, { "key": "ctrl+i", "command": "fsi.Start", "when": "editorTextFocus" }
Visual Studio Code and Ionide-Fsharp have truly changed how I prototype ideas. I can load the editor, start the REPL, and begin testing my ideas in mere seconds. This makes VSCode enjoyable and efficient for F# prototyping.