Skip to content

Allow opening rust-analyzer on a single file #6388

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
jyn514 opened this issue Oct 27, 2020 · 7 comments · Fixed by #8955
Closed

Allow opening rust-analyzer on a single file #6388

jyn514 opened this issue Oct 27, 2020 · 7 comments · Fixed by #8955
Labels
C-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) E-hard S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@jyn514
Copy link
Member

jyn514 commented Oct 27, 2020

Currently, code x.rs (where x.rs is any self-contained source file) gives the error Cannot activate rust-analyzer: no folder is opened. It would be nice to have this work if x.rs doesn't require any external dependencies. That would allow running rust-analyzer even on projects not using cargo.

@lnicola
Copy link
Member

lnicola commented Oct 28, 2020

Note that there is a way to run rust-analyzer on projects not using cargo, but it's probably not easier than making a Cargo.toml: https://rust-analyzer.github.io/manual.html#non-cargo-based-projects.

@jyn514
Copy link
Member Author

jyn514 commented Oct 28, 2020

Those docs are intended for using some build system other than cargo, like x.py or bazel or something. I'm asking for support for very small projects that have no dependencies, only a single rust file.

@petr-tik
Copy link
Contributor

Another use case would be for org-babel the emacs + org-mode literate programming environment that creates files in temp and enables users to write short snippets. Adding rust-analyzer support for individual files would be great for this as well.

@jomala
Copy link

jomala commented Dec 14, 2020

Can rust-analyzer not just default to the directory containing Cargo.toml as cargo would?

@jyn514
Copy link
Member Author

jyn514 commented Dec 14, 2020

@jomala this is for projects not using cargo, where there is no Cargo.toml file.

@flodiebold flodiebold added C-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) E-hard S-unactionable Issue requires feedback, design decisions or is blocked on other work labels Dec 21, 2020
@bors bors bot closed this as completed in 05fc97e May 24, 2021
@zzzachzzz
Copy link

The error I was receiving was: [rust-analyzer unlinked-file] [E] file not included in module tree, and due to this linting was not working while trying to edit a single main.rs file in my home directory.

I resolved the issue by creating a file named rust-project.json alongside my main.rs file with the contents:

{
    "sysroot_src": "/home/<YOUR-USER>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library",
    "crates": [
        {
            "root_module": "main.rs",
            "edition": "2018",
            "deps": []
        }
    ]
}

@lnicola
Copy link
Member

lnicola commented Jul 10, 2021

@zzzachzzz this works for me without a rust-project.json with the exception of editing new files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) E-hard S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants