Does rust-analyzer have an editor-independent config file?

Hi! I'd like to add an editor-independent configuration for rust-analyzer to my project! However, I'm not sure if this can be done - I couldn't find any instances of it with a quick web search. I only found .vscode/settings.json files, which are not editor-independent. Does anyone know anything about this?

Many thanks,

There is no such config file. You can start multiple instances of rust-analyzer and send commands to each instance separately via stdin using the Language Server Protocol.

Here is a related thread:

1 Like

That thread seems to perfectly describe my problem, thanks! I'd like to see if anyone has some really hacky workaround or something before I give up, though! :slight_smile:

Are you trying to create a config file that every single instance of RA on a user's machine will read on startup? If so, that's not possible, unless you patch the RA source code to do that, but then that wouldn't affect unpatched versions.

On the other hand, if you are creating a code editor or something similar, you can control what happens every time an instance of your editor launches RA. This is basically what VS Code can do through its global config.

1 Like

No, I'm not doing anything particularly fancy. In many projects, especially those using Flatpak, rust-analyzer will continue to scan infinitely through symbolic links without some configuration preventing it. I documented my "fix" here.

However, it'd be nice to include an editor-independent fix for my project. Instead of making contributors add this to their editor's configuration before it crashes, it'd be much easier to let rust-analyzer read from a global configuration file which applies the fix to all instances of rust-analyzer, no matter the editor!

For me, the infinite scanning issue is particularly scary, as it causes my not-so-stable Asahi Linux machine to freeze completely, requiring a full reboot - which gets rid of all my work. Helping others to avoid this problem would be awesome - especially on the templates I mentioned in my issue, but also for all Rust users in general! Of course, the real fix would be on rust-analyzer's end - a limit of scanning depth, small recursion checks, or not respecting symbolic links would be a preferable solution. These solutions are difficult, though, as it's easy to imagine some unconventional projects that break. For now, though, it's up to me!

Yeah, that's a good catch.

It does seem like a fix upstream is the best solution. Ideally there should be some convenient way to set a list of directories to exclude when starting up RA, as well as a hard-coded list of default directories that are ignored.

In the meantime, there may be a hacky fix. Apparently, there is a way to configure RA on a per-project basis using rust-project.json

Place rust-project.json file at the root of the project, and rust-analyzer will discover it.

You can read the documentation and the source code below to figure out how to set the exclude_dirs variable. It's still not ideal because it doesn't apply globally, but it is independent of a particular editor at least.

1 Like

rust-project.json is not a config file, it's a replacement for Cargo.toml for non-Cargo projects.

An editor-independent configuration file is planned, but so far doesn't exist. (A global editor-independent config file is not really planned, though, I think.)

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.