Skip to content

feat: fetch crate versions and deps using sparse registry index #137

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

Merged
merged 14 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading