Defining keybindings for Rust (rls) in VSCode


#1

With Visual Studio Code and Rust (rls) 3.2 extension, in keybindings.json

{ 
        "key": "f5",
        "command": "???",
        "when": "editorLangId == 'rust'"
}

what do I need to put in place of the question marks to execute cargo build?


#2

I figured it out. Here’s what worked for me

[
    { 
        "key": "f5",
        "command": "workbench.action.tasks.runTask",
        "args": "cargo check",
        "when": "editorLangId == 'rust'"
    },{ 
        "key": "f6",
        "command": "workbench.action.tasks.runTask",
        "args": "cargo build",
        "when": "editorLangId == 'rust'"
    },{ 
        "key": "f7",
        "command": "workbench.action.tasks.runTask",
        "args": "cargo run",
        "when": "editorLangId == 'rust'"
    },{ 
        "key": "f8",
        "command": "workbench.action.tasks.runTask",
        "args": "cargo test",
        "when": "editorLangId == 'rust'"
    }
]

Edit: it doesn’t actually work as expected, since the terminal is re-used and then needs to be closed with a key press which I would really like not having to do. Also cargo check doesn’t work.