Skip to content

Commit

Permalink
feat: fetch crate versions and deps using sparse registry index (#137)
Browse files Browse the repository at this point in the history
* feat: [WIP] fetch crate versions and deps using sparse registry index

* feat: correctly handle `dep:<crate_name>` features in popup

* feat: correctly handle `dep:<crate_name>` features in completion

* refactor: remove unused function

* chore: update todos

* refactor: clean up feature toggling

* feat: fetch missing metadata from api

* refactor: rename misleading variables

* fix: version, feature, and feature members sorting

* test: update json_spec

* fix: rely in api version ordering instead of manually sorting

* fix: don't allow twice as many parallel requests

* test: add Cargo.toml with tricky dependencies

* fix: add missing default feature at first position
  • Loading branch information
saecki authored Jun 30, 2024
1 parent df9937e commit dcc451c
Show file tree
Hide file tree
Showing 21 changed files with 6,887 additions and 941 deletions.
9 changes: 0 additions & 9 deletions doc/crates.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ For more information about individual config options see |crates-config|.
max_parallel_requests = 80,
open_programs = { "xdg-open", "open" },
expand_crate_moves_cursor = true,
disable_invalid_feature_diagnostic = false,
enable_update_available_warning = true,
on_attach = function(bufnr) end,
text = {
Expand Down Expand Up @@ -637,14 +636,6 @@ expand_crate_moves_cursor *crates-config-expand_crate_moves_cursor*
Whether to move the cursor on |crates.expand_plain_crate_to_inline_table()|.


*crates-config-disable_invalid_feature_diagnostic*
disable_invalid_feature_diagnostic
Type: `boolean`, Default: `false`

This is a temporary solution for:
https://github.com/Saecki/crates.nvim/issues/14


*crates-config-enable_update_available_warning*
enable_update_available_warning
Type: `boolean`, Default: `true`
Expand Down
1 change: 0 additions & 1 deletion docgen/wiki/Documentation-unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ require("crates").setup {
max_parallel_requests = 80,
open_programs = { "xdg-open", "open" },
expand_crate_moves_cursor = true,
disable_invalid_feature_diagnostic = false,
enable_update_available_warning = true,
on_attach = function(bufnr) end,
text = {
Expand Down
34 changes: 26 additions & 8 deletions lua/crates/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ function M.open_homepage()
local crates = util.get_line_crates(buf, Span.pos(line))
local _, crate = next(crates)
if crate then
local crate_info = state.api_cache[crate:package()]
if crate_info and crate_info.homepage then
util.open_url(crate_info.homepage)
local api_crate = state.api_cache[crate:package()]
if api_crate and api_crate.homepage then
util.open_url(api_crate.homepage)
else
util.notify(vim.log.levels.INFO, "The crate '%s' has no homepage specified", crate:package())
end
Expand All @@ -129,9 +129,9 @@ function M.open_repository()
local crates = util.get_line_crates(buf, Span.pos(line))
local _, crate = next(crates)
if crate then
local crate_info = state.api_cache[crate:package()]
if crate_info and crate_info.repository then
util.open_url(crate_info.repository)
local api_crate = state.api_cache[crate:package()]
if api_crate and api_crate.repository then
util.open_url(api_crate.repository)
else
util.notify(vim.log.levels.INFO, "The crate '%s' has no repository specified", crate:package())
end
Expand All @@ -144,8 +144,8 @@ function M.open_documentation()
local crates = util.get_line_crates(buf, Span.pos(line))
local _, crate = next(crates)
if crate then
local crate_info = state.api_cache[crate:package()]
local url = crate_info and crate_info.documentation
local api_crate = state.api_cache[crate:package()]
local url = api_crate and api_crate.documentation
url = url or util.docs_rs_url(crate:package())
util.open_url(url)
end
Expand Down Expand Up @@ -209,6 +209,19 @@ local function remove_feature_action(buf, crate, feat)
end
end

---@param buf integer
---@param crate TomlCrate
---@param feat TomlFeature
---@return fun()
local function remove_feature_dep_prefix_action(buf, crate, feat)
return function()
local line = crate.feat.line
local col_start = crate.feat.col.s + feat.col.s
local col_end = col_start + 4
vim.api.nvim_buf_set_text(buf, line, col_start, line, col_end, {})
end
end

---@return CratesAction[]
function M.get_actions()
---@type CratesAction[]
Expand Down Expand Up @@ -270,6 +283,11 @@ function M.get_actions()
name = "remove_invalid_feature",
action = remove_feature_action(buf, crate, d.data["feat"]),
})
elseif crate and d.kind == CratesDiagnosticKind.FEAT_EXPLICIT_DEP then
table.insert(actions, {
name = "remove_`dep:`_prefix",
action = remove_feature_dep_prefix_action(buf, crate, d.data["feat"]),
})
end

::continue::
Expand Down
Loading

0 comments on commit dcc451c

Please sign in to comment.