crates.nvim icon indicating copy to clipboard operation
crates.nvim copied to clipboard

Some feature wrongly considered invalid

Open clement-buchart opened this issue 4 years ago • 6 comments

Hello,

Current behavior

Some features are considered invalid, but are in fact valid, and documented on the crate's doc.rs page. For example :

  • the "uuidv07" of crate diesel v1.4.8
  • the "serde" feature of create uuid v0.8.2

Expected behavior

Features that are listed in docs.rs don't trigger an "Invalid feature" diagnostic

Additional context/Screenshots

image

Neovim version

nvim --version
NVIM v0.6.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Thanks for the great plugin. Cheers.

clement-buchart avatar Jan 03 '22 20:01 clement-buchart

So the Cargo.toml of diesel looks like this:

[dependencies.uuid]
features = ["use_std"]
optional = true
version = ">=0.2.0, <0.7.0"

[dependencies.uuidv07]
optional = true
package = "uuid"
version = ">=0.7.0, <0.9.0"

but when fetching dependencies from crates.io all we get is:

{
  "crate_id": "uuid",
  "default_features": true,
  "downloads": 0,
  "features": [
    "use_std"
  ],
  "id": 2871490,
  "kind": "normal",
  "optional": true,
  "req": ">=0.2.0, <0.7.0",
  "target": null,
  "version_id": 427827
},
{
  "crate_id": "uuid",
  "default_features": true,
  "downloads": 0,
  "features": [],
  "id": 2871491,
  "kind": "normal",
  "optional": true,
  "req": ">=0.7.0, <0.9.0",
  "target": null,
  "version_id": 427827
}

The dependency alias isn't accessible using the api.

I don't see an easy way to retrieve that information for now. Until I found some way to work around this I see two options:

  • Don't push diagnostics for invalid features
  • Live with false positives

It probably makes sense to let the user choose using a config flag called diagnostics.invalid_features. And document why that is an option.

saecki avatar Jan 04 '22 00:01 saecki

For uuid there was a bug in parsing dependencies. That should be fixed by the linked PR.

saecki avatar Jan 04 '22 00:01 saecki

Thanks for looking into this. Can confirm the serde feature for uuid is OK now

For the diesel one, I don't know if that's actionable but one could get the optional dependencies out of the cargo metadata output as a way to filter out errors maybe :

❯ cargo metadata --format-version=1 | jq -r '.packages[] | select(.name=="diesel") | .dependencies[] | select((.optional==true) and (.rename != null and .rename != "")) | .rename'

uuidv07

clement-buchart avatar Jan 04 '22 08:01 clement-buchart

I think it's worth looking into this, since that would also allow a way to retrieve metadata for path- and git-dependencies.

saecki avatar Jan 04 '22 12:01 saecki

So I added a flag to disable invalid feature diagnostics until this is properly fixed.

saecki avatar Jan 15 '22 09:01 saecki

Linking https://github.com/rust-lang/crates.io/issues/1539, just so I remember

saecki avatar Dec 17 '23 15:12 saecki