Stream: t-compiler/wg-rls-2.0

Topic: using RA & vs-code for building and debugging Rust


blitzerr (Apr 27 2019 at 13:54, on Zulip):

Usually I just use nvim for rust but I wanted to use vs-code and rust analyzer for it. I asked in the general topic of this stream to see how people are using it. By using it, I mean writing rust, building it and setting break points to debug it. @Laurențiu Nicola this is how I configured my vs-code and now some of this works. Setting breakpoints give some errors when we stop there. I want to share what I did and others who are doing it already can help me refine my settings :slight_smile:

blitzerr (Apr 27 2019 at 13:56, on Zulip):

added this in my launch.json in vs-code

    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "clang++ build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "clang++ build active file"
        },
        {
            "name": "rustc build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "rustc build active file"
        }
    ]
}
matklad (Apr 27 2019 at 13:57, on Zulip):

rust-analyzer itself does not interact with a debugger in any way, the debugger support is provided by vscode-lldb: https://github.com/vadimcn/vscode-lldb

blitzerr (Apr 27 2019 at 13:59, on Zulip):

This is how my tasks.json looks like

{
  "tasks": [
    {
      "type": "shell",
      "label": "clang++ build active file",
      "command": "/usr/bin/clang++",
      "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "/usr/bin"
      }
    },
    {
      "type": "shell",
      "label": "rustc build active file",
      "command": "<path to rustc>",
      "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "/usr/bin"
      }
    },
    {
      "label": "cargo build",
      "type": "shell",
      "command": "cargo build",
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": []
    },
    {
      "label": "cargo test",
      "type": "shell",
      "command": "cargo test",
      "group": {
        "kind": "test",
        "isDefault": true
      }
    }
  ],
  "version": "2.0.0"
}

Please substitute <path to rustc> with the actual path or just rustc if its already in your system's path

blitzerr (Apr 27 2019 at 14:02, on Zulip):

Thanks @matklad for the link. I will try this.

Laurențiu Nicola (Apr 27 2019 at 15:30, on Zulip):

this worked for me in a quick test

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "gdb",
            "request": "launch",
            "gdbpath": "rust-gdb",
            "name": "Launch Program",
            "target": "./target/debug/test-gdb",
            "cwd": "${workspaceRoot}",
            "valuesFormatting": "parseText"
        }
    ]
}
Laurențiu Nicola (Apr 27 2019 at 15:33, on Zulip):

that's a launch.json file

Laurențiu Nicola (Apr 27 2019 at 15:38, on Zulip):

in tasks.json I have

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "cargo build",
            "type": "process",
            "command": "cargo",
            "args": [
                "build"
            ],
            "problemMatcher": [
                "$rustc"
            ]
        }
    ]
}
Laurențiu Nicola (Apr 27 2019 at 15:38, on Zulip):

there's also a "type": "cargo", but I can't figure out how to use it

Laurențiu Nicola (Apr 27 2019 at 15:39, on Zulip):

can rust-analyzer provide some default tasks? I think extensions are allowed to do that

blitzerr (Apr 28 2019 at 00:58, on Zulip):

@Laurențiu Nicola Thanks for sharing

Jeremy Kolb (Apr 28 2019 at 15:59, on Zulip):

Note that on windows you have to use "native debug" and a completely different set of tasks

blitzerr (Apr 30 2019 at 19:55, on Zulip):

What's the recommended way of updating rust analyzer ? Do we have to rebuild from source ?

matklad (Apr 30 2019 at 20:07, on Zulip):

yeah, building from source is really the only supported mode of distribution right now

blitzerr (May 05 2019 at 17:21, on Zulip):

Cool. Have been doing that.

Last update: Nov 12 2019 at 16:05UTC