Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSCode setting to specify path to Cargo.toml #2649

Closed
oxalica opened this issue Dec 23, 2019 · 14 comments
Closed

VSCode setting to specify path to Cargo.toml #2649

oxalica opened this issue Dec 23, 2019 · 14 comments

Comments

@oxalica
Copy link
Contributor

oxalica commented Dec 23, 2019

Sometimes Cargo.toml is not in the workspace root, instead, inside some sub-directory.
Since the project contains non-rust code, it is not good idea to always create Cargo.toml workspace file in the root.

Is there any way to specify the directory or path to Cargo.toml processed by rust-analyzer?

@edwin0cheng
Copy link
Member

edwin0cheng commented Dec 23, 2019

Is there any way to specify the directory or path to Cargo.toml processed by rust-analyzer?

If I understand correctly, there is still no way to do that: see #2533

@matklad
Copy link
Member

matklad commented Dec 23, 2019

Yeah, there's no such setting (yet), it should be not that hard to add.

@menoude
Copy link

menoude commented Apr 13, 2020

@matklad do you know if this is on the roadmap? I can try to implement it if not (and if it happens to be simple). Sadly this is what keeps our team from using rust-analyzer!

@matklad
Copy link
Member

matklad commented Apr 15, 2020

Sure, a PR would be welcome!

Here's the current code for determining the set of projects to analyze:

https://github.com/rust-analyzer/rust-analyzer/blob/61cb87e50629f510c8a1231102ba66ded524bec2/crates/rust-analyzer/src/bin/main.rs#L74-L82

@matklad
Copy link
Member

matklad commented Jun 8, 2020

Fixed in today's release:

{
    "rust-analyzer.linkedProjects": [
        "/home/matklad/tmp/hello/Cargo.toml"
    ]
}

(you can link more than one project)

@azzamsa
Copy link
Contributor

azzamsa commented Sep 13, 2020

Fixed in today's release:

{
    "rust-analyzer.linkedProjects": [
        "/home/matklad/tmp/hello/Cargo.toml"
    ]
}

(you can link more than one project)

How to achieve the same thing in Emacs? Other than using rust-project.json. I don't find it in the manual

@matklad
Copy link
Member

matklad commented Sep 24, 2020

@azzamsa tbh, I don't know how to pass settings to lang servers via lsp mode. I guess it should be documented somewhere here: https://emacs-lsp.github.io/lsp-mode/.

A PR to rust-analyzer's manual clarifying this would help!

@flodiebold
Copy link
Member

There are specific emacs defcustoms for most settings. Probably not for linkedProjects though (can't check, not at my computer), and I don't know if it makes sense to handle it that way since it would always have to be defined with dir-locals... Might be worth opening an issue about there.

@zqyzsj
Copy link

zqyzsj commented Jun 15, 2022

Is this problem solved? I don't know how to specify the root of a non-standard cargo project in emacs.

@flodiebold
Copy link
Member

You should be able to use lsp-rust-analyzer-linked-projects in a dir-local.

@zqyzsj
Copy link

zqyzsj commented Jun 15, 2022

You should be able to use lsp-rust-analyzer-linked-projects in a dir-local.

I tested the lsp-rust-analyzer-linked-projects config in my emacs config file, and it works. But it seems that I only can set a fixed path in the emacs config file. So if I open another rust project I need to change the emacs config file, which is strange. Is there any way to automate set the path of the cargo.toml?
Following is my config of lsp-rust-analyzer-linked-projects:
(lsp-rust-analyzer-linked-projects ["/my/path/to/some/project's/Cargo.toml"])

@flodiebold
Copy link
Member

That's why you should set it in .dir-locals.el, not globally 🙂

@zqyzsj
Copy link

zqyzsj commented Jun 16, 2022

Thanks @flodiebold . I'll try it.

@yhslai
Copy link

yhslai commented Oct 7, 2023

How to specify this in emacs? The above comments mentioned lsp-rust-analyzer-linked-projects, but what's the equivalent to eglot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants