[Thiago Cafe] Programming is fun!

Developing in Rust using Visual Studio Code

Created by thiago on 2020-05-12 17:20:00

Tags:

Two of the best features when using an IDE are auto completing and debugging. Fortunately, we can have both with VSCode.

Install Rust

Go to rust website and follow the install procedure

Then use nightly channel to get the latest version of the toolchain.

 # Install nightly toolchain
 $ rustup toolchain install nightly

 # Set nightly toolchain as default
 $ rustup default nightly

Install related Visual Studio Code extensions

Install those 2 extensions:

After installing, open a rust file in the editor and you will be asked:

Some rust components not installed. Install it?

Click Yes

Auto completing the code

This is how auto complete looks:

And now with documentation

Debugging the code

Creating the run configuration for the project

First: Create a launch.json using lldb

Press Ctrl + Shift + P and select Debug: Open launch.json

Paste this content and replace hello with the name of your project

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "lldb",
      "request": "launch",
      "name": "Launch",
      "args": [],
      "program": "${workspaceFolder}/target/debug/hello",
      "windows": {
        "program": "${workspaceFolder}/target/debug/hello.exe"
      },
      "cwd": "${workspaceFolder}",
      "stopOnEntry": false,
      "sourceLanguages": [
        "rust"
      ]
    }
  ]
}

Now, you have to build and run with lldb debugger attached.

This is the debugger inspecting the content of the variable

That's all. Quite simple, with a bit of tweaking.

Tell me your opinion!

Reach me on Twitter - @thiedri