DEV Community

Thiago Massari Guedes
Thiago Massari Guedes

Posted on

Developing in Rust using Visual Studio Code

Developing in Rust using Visual Studio Code

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

Source of this post: http://thiago.rocks/view/20200512_vscode_with_rust

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
Enter fullscreen mode Exit fullscreen mode

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:

auto complete 1

And now with documentation

auto complete 2

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"
      ]
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

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

  • To build: Press Ctrl + Shift + B
  • Toggle breakpoints: F9
  • To debug: Press F5

This is the debugger inspecting the content of the variable

debug

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

Latest comments (0)