rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.35k stars 1.62k forks source link

Vscode extension: Looking for runnables... There's no debug target! #16531

Open punowo opened 9 months ago

punowo commented 9 months ago

Hello. I've been encountering this specific problem with "Rust-Analyzer: Debug" no matter what platform I am on. I've been able to replicate this on Windows, and Mac OS. Now I'm on Arch Linux and after updating rust from the official repositories I'm encountering this again.

Put simply, running the command "Rust-Analyzer: Debug" leaves me in this state:

Screenshot from 2024-02-11 13-27-58

while clicking the Debug editor action above fn main() works like intended.

Screenshot from 2024-02-11 13-28-09

[pun@owo ~]$ rust-analyzer --version
rust-analyzer 1 (39ad79bec 2024-02-04)
[pun@owo ~]$ rustc --version
rustc 1.76.0 (07dca489a 2024-02-04) (Arch Linux rust 1:1.76.0-1)

Screenshot from 2024-02-11 13-49-06 I also, cannot generate launch configuration using the rust-analyzer vscode extension, receiving the same error.

If I generate launch configuration with the codelldb vscode extension then it works like expected when I press F5.

Edit: There are the custom vscode settings I currently have for rust. I have the same problem if I try to use the bundled rust-analyzer that comes with the vscode extension.

  "rust-analyzer.debug.engine": "vadimcn.vscode-lldb",
  "rust-analyzer.server.path": "rust-analyzer"
punowo commented 9 months ago

Shouldn't this call also return something related to cargo run ? https://github.com/rust-lang/rust-analyzer/blob/ac998a74b3c8ff4b81c3eeb9a18811d4cc76226d/editors/code/src/run.ts#L166 I'm trying to debug this and it currently returns only

[
  {
    label: "cargo check -p helloworld --all-targets",
    kind: "cargo",
    args: {
      overrideCargo: null,
      workspaceRoot: "/home/pun/Developer/helloworld",
      cargoArgs: [
        "check",
        "--package",
        "helloworld",
        "--all-targets",
      ],
      cargoExtraArgs: [
      ],
      executableArgs: [
      ],
    },
  },
  {
    label: "cargo test -p helloworld --all-targets",
    kind: "cargo",
    args: {
      overrideCargo: null,
      workspaceRoot: "/home/pun/Developer/helloworld",
      cargoArgs: [
        "test",
        "--package",
        "helloworld",
        "--all-targets",
      ],
      cargoExtraArgs: [
      ],
      executableArgs: [
      ],
    },
  },
]

EDIT: I forgot to mention this earlier, but I believe the reason the 'Code Action' is effective is due to the 'Task' having a completely distinct 'flow' within the extension's source code.

henrycharlesworth commented 8 months ago

Same issue for me. Everything had been working but now suddenly getting this.

lnicola commented 8 months ago

I'm not sure, but IIRC it starts working after you use the Debug lens.

punowo commented 8 months ago

I'm not sure, but IIRC it starts working after you use the Debug lens.

If by debug lens you mean the code action above the main function, I cannot replicate this, though on the stable version of the extension that thing is usable.

fireattack commented 6 months ago

I have the same issue using these two commands mentioned by OP with newest Stable and Insider.

CodeLens (that's what you guys referred as "action above") does work.

AspadaX commented 6 months ago

same issue here. it works fine after I installed it yesterday, but all of sudden, it breaks...

mathew-horner commented 6 months ago

Where is your cursor located when you click the command? RA will use that location when deciding which runnables to consider.

fireattack commented 6 months ago

Where is your cursor located when you click the command? RA will use that location when deciding which runnables to consider.

This solves my problem. Thanks

punowo commented 6 months ago

Where is your cursor located when you click the command? RA will use that location when deciding which runnables to consider.

I'm sorry can you expand a little on this. I'm using the neovim vscode plugin.

EDIT: Ok, in my case, the consistency comes from using https://github.com/vscode-neovim/vscode-neovim, when using this extension it doesn't work every time.

If I disable it, have my cursor outside Rust code, in a Rust file, I will get the same error but if the current line is inside Rust code then it will work properly and afterwards it will also work outside Rust code in the same file.

So this is not a bug in rust-analyzer vscode extension but a bug in vscode-neovim ?

mathew-horner commented 6 months ago

If I disable it, have my cursor outside Rust code, in a Rust file, I will get the same error but if the current line is inside Rust code then it will work properly and afterwards it will also work outside Rust code in the same file.

I'm a bit confused. Did you try the opposite? Specifically: did you try to debug with the plugin enabled, your cursor inside main, and it still didn't work? Based off of the screenshot in the original post, it looks like your cursor was on the blank line after main, which currently won't consider main when determining the runnables.

This solves my problem. Thanks

No problem! Though honestly one could probably make the point that the way it currently works is a bit confusing. If I have my file with fn main open, I would expect to be able to use the Debug command from anywhere in that file. Or at least not have to specifically have my cursor in the main function.

punowo commented 6 months ago

The problem I have right now is that it works in both cases with the neovim plugin. Both inside an example main function and both outside while in the same file, on a new test project, just like in the first post of this issue, while yesterday while writing the post you replied to, on the same machine, same vscode, it didn't.

Now even after deleting .config/Code and .vscode, I still cannot recreate it.

I don't know.