Visual Studio Code

Credits

This guide assumes that you've completed the steps described in Prerequisites.

  1. If you're using nix-shell, make sure you can launch the editor from the command line so it inherits your $PATH. On Linux, code command is automatically available after VSCode installation. On macOS, follow the instruction
  2. Install the Haskell extension
  3. Close the editor and re-open it in the project folder
    cd <your-projects-dir>
    code .
    
    Note: if you're using nix-shell, make sure to run it first.

If everything is fine you should get auto-completion and other features working 🎉


Additional Troubleshooting Steps

In the event the above steps result in the Visual Studio Code Editor not displaying definitions.

Tested with

Ubuntu                                          v20.x
Windows                                         v10.x
Nix                                             v2.3.10
Visual Studio Code                              v1.55.2
VSCode Extension Haskell                        v1.2.0
VSCode Extension Haskell Syntax Highlighting    v3.4.0

How to Check

Select a function in the Visual Studio Code Editor and right-click and choose Go to Definition or highlight a function and press F12.

Example: bindMaybe displays the error No definition found for 'bindMabye' even though it is defined only a few lines up.

bindMaybe :: Maybe a -> (a -> Maybe b) -> Maybe b
bindMaybe Nothing _ = Nothing
bindMaybe (Just x) f = f x

foo :: String -> String -> String -> Maybe Int
foo x y z =  readMaybe x `bindMaybe` \num1 ->
             readMaybe y `bindMaybe` \num2 ->
             readMaybe z `bindMaybe` \num3 ->
             Just (num1 + num2 + num3)

Possible Solution

  1. Open the built-in terminal inside your Visual Studio Code by pressing control + ~ at the same time or by going to Terminal > New Terminal within the file menu.

  2. From the built-in terminal, navigate to your plutus directory or clone a new copy of the plutus repository.

  3. From the plutus root directory, run the following command nix-shell. (This command requires access to the default.nix, shell.nix files that are part of every plutus repository forks or clones.)

nix-shell Example: Should look something like this.

[nix-shell:~/<your file path>/plutus-pioneer-program/code/week04]$ |

  1. Once in the nix-shell instance navigate back to your plutus-pioneer-program/code/weekxx/ folder and run code . (Note: This will launch a new Visual Studio Code Window. It is now safe to close the prior Visual Studio Code instance.)

  2. :boom:

Your Visual Studio Code instance should now have access to definitions. Test this by selecting a function an pressing F12.

Definition Example: When pressing F12 or while hovering the function name.

bindMaybe :: forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
Defined at /<your path>/plutus-pioneer-program/code/week04/src/Week04/Maybe.hs:19:1