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

rust-analyzer.files.excludeDirs is (still) not working #14734

Open
willtunnels opened this issue May 4, 2023 · 20 comments · May be fixed by #18998
Open

rust-analyzer.files.excludeDirs is (still) not working #14734

willtunnels opened this issue May 4, 2023 · 20 comments · May be fixed by #18998
Labels
A-vfs Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug

Comments

@willtunnels
Copy link

rust-analyzer.files.excludeDirs does not appear to be working. Issue #7755 discussed this awhile ago and was closed, but the feature is still not working for me. I am using rust-analyzer 0.4.1501-standalone with rustc 1.68.2 in VSCode.

It could be that I misunderstand how to specify directories. My project layout is

.
├── src
        ├── module0

and my rust analyzer setting is

{
  "rust-analyzer.files.excludeDirs: ["src/module0"]
}

I tried also setting files.watcherExclude, as suggested in the documentation, but no luck.

@willtunnels willtunnels added the C-bug Category: bug label May 4, 2023
@jlevon
Copy link

jlevon commented May 5, 2023

same here. I have a tests/ directory with a lot of small, non-rust files, that stops rust-analyzer from being able to resolve symbols (no idea why). If I move the directory out of the way, RA works. But no form of excludeDirs I've found has any effect.

I'm using vim-lsp, e.g.

if executable('rust-analyzer')
  au User lsp_setup call lsp#register_server({
        \   'name': 'Rust Language Server',
        \   'cmd': {server_info->['rust-analyzer']},
        \ 'root_uri':{server_info->lsp#utils#get_default_root_uri()},
        \ 'initialization_options': { "rust-analyzer.files.excludeDirs": [ "tests", "vendor" ] },
        \   'whitelist': ['rust'],
        \ })
endif

with no effect.

@sinesc
Copy link

sinesc commented Aug 7, 2023

I have the same issue with non-rust files I use rust syntax highlighting for. They aren't in src/ and don't initially get checked but as soon as I open one in the editor rust-analyzer generates lot's of syntax errors. excludeDirs does not seem to have any effect at all.

@cloutiertyler
Copy link

I am having the same issue.

@jlevon
Copy link

jlevon commented Sep 30, 2023

This sort of works for me:

if executable('rust-analyzer')
  au User lsp_setup call lsp#register_server({
        \   'name': 'Rust Language Server',
        \   'cmd': {server_info->['rust-analyzer']},
        \   'whitelist': ['rust'],
        \   'initialization_options': {
        \        'files': {
        \            'excludeDirs': ['tests', 'vendor'],
        \        }
        \   }
        \ })
endif
$ rust-analyzer --version
rust-analyzer 1.72.1 (d5c2e9c 2023-09-13)

This does seem to ignore tests/ dir (which happens to basically completely break rust-analyzer, and has no rust sources in it), but rust-analyzer still looks at vendor - presumably because it's referenced from src/

@Andrew15-5
Copy link

I also have this problem. It would be nice if rust-analyzer can also just use entries from the .gitignore.

@wiiznokes
Copy link

I'm having the same problem. It would be nice if files are also supported

@seanchann
Copy link

same problem. Do you have any suggestions for this?

@Veykril Veykril added Broken Window Bugs / technical debt to be addressed immediately A-vfs labels Mar 13, 2024
@Sufhal
Copy link

Sufhal commented Sep 4, 2024

Same problem here.

@hhwyt
Copy link

hhwyt commented Sep 13, 2024

Any workaround for this?

@alibektas alibektas self-assigned this Sep 13, 2024
@cgubbin
Copy link

cgubbin commented Sep 25, 2024

Does anyone have a good workaround for this? I'm using a Nix Flake to define my development environment, and although I have added .direnv to excludeDirs rust analyzer continues to scan .direnv, and subsequently the entire nix store. It essentially never finishes.

@azizur
Copy link

azizur commented Sep 25, 2024

Does anyone have a good workaround for this? I'm using a Nix Flake to define my development environment, and although I have added .direnv to excludeDirs rust analyzer continues to scan .direnv, and subsequently the entire nix store. It essentially never finishes.

Take a look at the approach I am using to make this work.

See my comments here #3113 (comment)

@cgubbin
Copy link

cgubbin commented Sep 25, 2024

Does anyone have a good workaround for this? I'm using a Nix Flake to define my development environment, and although I have added .direnv to excludeDirs rust analyzer continues to scan .direnv, and subsequently the entire nix store. It essentially never finishes.

Take a look at the approach I am using to make this work.

See my comments here #3113 (comment)

I saw this yes, I have added the folders to the excludeDirs. I'm using neovim, so this is slightly different, but the expected effect is the same.

opts = {
     default_settings = {
            ["rust-analyzer"] = {
                files = {
                    excludeDirs = {
                        ".cargo",
                        ".direnv",
                        ".git",
                        "target",
                    },
                },
     },
}

@azizur
Copy link

azizur commented Sep 25, 2024

Before you open the editor, try running 'cargo clean'.

@cgubbin
Copy link

cgubbin commented Sep 26, 2024

Before you open the editor, try running 'cargo clean'.

I have also tried doing this and it doesn't seem to change the situation.

However I noticed that after cleaning, the progress indicator displayed by rust-analyzer does not reset. For the specific project I am testing with it displays 42/45: .direnv before and after cleaning. Does that mean that the clean command is somehow not resetting the cache in the way it should? I also tried manually deleting the target folder but the behaviour persists.

@duncanawoods
Copy link

This bug is preventing working around another bug:

#8161

In my case, flatpak creates temporary folders containing symbolic links which then breaks RA but can't be excluded.

Does it also mean RA is wandering around horrendous folders like node_modules?

@cgubbin
Copy link

cgubbin commented Nov 13, 2024

This is still an issue for me, but I am currently using a simple fix which I'm posting here in case it helps somebody else.

I couldn't get rust-analyzer to stop scanning the .direnv folder, so in the end I placed my entire crate in a subfolder one level below the flake.nix file and .direnv folder. I did this using cranes guide to placing a Cargo.toml in a non-standard location.

This has stopped the problem for me, as the .direnv folder is no longer in the workspace root. Not an ideal solution but at least something actionable.

@uttarayan21
Copy link

uttarayan21 commented Nov 14, 2024

I was actually having this issue due to using rustaceanvim plugin and it fixed itself when I switched to the rust-analyzer lsp plugin instead. Here is my config for both rustaceanvim and nvim-lspconfig.rust_analyzer using nixvim.
Enabling the rustaceanvim plugin makes it also search the .direnv folder even though it's in the excludeDirs

antoineco added a commit to antoineco/dotfiles that referenced this issue Nov 30, 2024
The usage of nix-direnv currently breaks rust-analyzer when the language
server is configured by rustaceanvim[1]. It also slows down the server's
startup when configured via nvim-lspconfig.

Adding as a future improvement; the setting is currently not working[2]
as of rust-analyzer 1.83.0.

[1]: mrcjkb/rustaceanvim#586
[2]: rust-lang/rust-analyzer#14734
@rszyma
Copy link

rszyma commented Jan 21, 2025

Still an issue.

I have a vendored crate in the workspace that I absolutely don't want to get diagnostics for, and none of rust-analyzer.files.excludeDirs or files.exclude or files.watcherExclude or workspace.exclude (in Cargo.toml) works.


I'm not sure how the issues are prioritized in rust-analyzer, I'm sure the team has a lot of work going on. I'd just like to emphasize, that this is one of the issues that just do not have a workaround - so when it hits, it hits really hard.

@ChayimFriedman2
Copy link
Contributor

ChayimFriedman2 commented Jan 21, 2025

I have a vendored crate in the workspace that I absolutely don't want to get diagnostics for, and none of rust-analyzer.files.excludeDirs or files.exclude or files.watcherExclude or workspace.exclude (in Cargo.toml) works.

Note that if you exclude it (well, if it would work) you won't get any smart code services for code that depends on it (and you might get diagnostics for them). Also, there shouldn't be diagnostics if this crate compiles.

@alibektas alibektas removed their assignment Jan 22, 2025
@rszyma
Copy link

rszyma commented Jan 22, 2025

Note that if you exclude it (well, if it would work) you won't get any smart code services for code that depends on it

OK, I think my use case is slightly different then - I want smart code services for the vendored crate, but to not show any warnings at all, or alternatively show, but only if I enter the file, and clear if file is closed. So it's a separate issue it seems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-vfs Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.