Skip to content

How to configure to attach a rust lsp client for single file #5142

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

Closed
lost22git opened this issue Dec 13, 2022 · 7 comments
Closed

How to configure to attach a rust lsp client for single file #5142

lost22git opened this issue Dec 13, 2022 · 7 comments

Comments

@lost22git
Copy link

No description provided.

@kirawi
Copy link
Member

kirawi commented Dec 13, 2022

It's not supported rust-lang/rust-analyzer#6388

@kirawi kirawi closed this as completed Dec 13, 2022
@anstadnik
Copy link

It is though rust-lang/rust-analyzer#8955

@rcorre
Copy link
Contributor

rcorre commented Jan 21, 2024

@anstadnik how do you actually use the feature you linked? The PR doesn't explain it, and it doesn't seem to work out-of-the-box (running rust-analyzer 1 (af40101841 2024-01-07))

@anstadnik
Copy link

I used https://github.com/simrat39/rust-tools.nvim, which supports the standalone feature. I'm not the developer, so I can't tell you how it uses the feature.

@rcorre
Copy link
Contributor

rcorre commented Jan 21, 2024

Ah, I'd assumed you had it working in Helix

@the-mikedavis
Copy link
Member

You can use rust-analyzer with non-cargo projects like single files but you need to tell rust-analyzer about the project with a rust-project.json file: https://rust-analyzer.github.io/manual.html#non-cargo-based-projects

@chaoky
Copy link

chaoky commented May 21, 2025

you could use rust-project.json before that pr, this what using that feature looks like in neovim:

local lsp_conf = require('lspconfig')

lsp_conf.rust_analyzer.setup {
    -- Other setup stuff
    -- ...

    -- To be able to start rust-analyzer at all a root_dir is needed,
    -- I added a star match for testing purposes to match on any file
    -- This could be an lspconfig/Neovim only issue
    root_dir = lsp_conf.util.root_pattern("*"),

    -- LSP Client needs to know the detached files ahead of time on
    -- initialization and pass them to the r-a on startup
    init_options = { detachedFiles = { "/tmp/file.rs" } }
}

from: rust-lang/rust-analyzer#14318 (comment)
the cargo script rfc was merged, so this is probably just a stop gap: rust-lang/rust-analyzer#15318

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

6 participants