rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.26k stars 1.61k forks source link

How to get --all-features to work again? #7791

Open krkhan opened 3 years ago

krkhan commented 3 years ago

Tried the suggestions in #3897 as well but no matter what I try I cannot get rust-analyzer to activate all features.

nvim_lsp.rust_analyzer.setup {
    on_attach = custom_attach,
    root_dir = nvim_lsp.util.root_pattern("Cargo.toml", "rust-project.json"),
    settings = {
      ["rust-analyzer"] = {
          ["cargo"] = {
              ["allFeatures"] = true,
          },
          ["checkOnSave"] = {
              ["allFeatures"] = true,
              ["extraArgs"] = {"--all-features"},
          }
      }
    }
}

image

Currently at commit aa38fa1

flodiebold commented 3 years ago

rust-analyzer.cargo.allFeatures would be the correct setting for this. Are you sure this is the right way to set settings in nvim-lsp? You could e.g. try setting rust-analyzer.diagostics.enable to false just to see if it's working; if the settings are sent correctly then that should hide the diagnostics completely.

lnicola commented 3 years ago

The syntax looks fine to me, I have:

nvim_lsp.rust_analyzer.setup({
    on_attach=on_attach,
    settings = {
        ["rust-analyzer"] = {
            assist = {
                importMergeBehavior = "last",
                importPrefix = "by_self",
            },
            cargo = {
                loadOutDirsFromCheck = true
            },
            procMacro = {
                enable = true
            },
        }
    }
})
lnicola commented 3 years ago

I get the same thing in Code:

image

krkhan commented 3 years ago

Setting rust-analyzer.diagostics.enable to false indeed turns off the diagnostics. The syntax is correct but according to https://github.com/rust-analyzer/rust-analyzer/issues/3897#issuecomment-655317883 :

rust-analyzer.checkOnSave.allFeatures was disabled in #4711 because a lot of people were working on projects with incompatible features (e.g. game engine backends) or that had a nightly feature. See also the discussion in #4704.

rust-analyzer.cargo.allFeatures was disabled in the same PR to keep things consistent, although it's less bad to have it always enabled.

The recommendation seemed to be to use rust-analyzer.checkOnSave.extraArgs but that is not helping either.

lnicola commented 3 years ago

No, no, it should work. rust-analyzer.cargo.allFeatures is disabled by default, but you can enable it, and rust-analyzer.checkOnSave.allFeatures is unset and unless you change it, has the same value as rust-analyzer.cargo.allFeatures.

rust-analyzer.cargo.allFeatures controls our analysis of the code (which includes those "inactive due to #[cfg]" diagnostics) and rust-analyzer.checkOnSave.allFeatures is used when we run cargo check during save. You want the first one, but it might have stopped working.

lnicola commented 3 years ago

@krkhan can you check whether your with_ctap1 feature is declared in Cargo.toml? I'm only able to reproduce this when it's not.

krkhan commented 3 years ago

@lnicola Yes it does seem to be: https://github.com/google/OpenSK/blob/stable/Cargo.toml#L29

jhscheer commented 3 years ago

This was bugging me as well. Code behind

#[cfg(...)]
#[test]

wasn't regocnized at all with the default settings. Finally this worked for me:

nvim_lsp.rust_analyzer.setup({
capabilities=capabilities,
on_attach=on_attach,
settings = {
    ["rust-analyzer"] = {
        cargo = {
            allFeatures = true,
            },
        },
    },
})