Skip to content

Commit

Permalink
feat: expand_crate_moves_cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
saecki committed Oct 19, 2023
1 parent 58bf989 commit 6d9c4dd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lua/crates/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ local M = {Config = {TextConfig = {}, HighlightConfig = {}, DiagnosticConfig = {






local Config = M.Config
Expand Down Expand Up @@ -357,6 +358,13 @@ entry(M.schema, "max_parallel_requests", {
Maximum number of parallel requests.
]],
})
entry(M.schema, "expand_crate_moves_cursor", {
type = "boolean",
default = true,
description = [[
Whether to move the cursor on |crates.expand_plain_crate_to_inline_table()|.
]],
})
entry(M.schema, "open_programs", {
type = "table",
default = { "xdg-open", "open" },
Expand Down
8 changes: 7 additions & 1 deletion lua/crates/edit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,16 @@ function M.expand_plain_crate_to_inline_table(buf, crate)
return
end

local text = crate.explicit_name .. ' = { version = "' .. crate.vers.text .. '" }'
vim.api.nvim_buf_set_text(
buf, crate.lines.s, crate.vers.decl_col.s, crate.lines.s, crate.vers.decl_col.e,
{ crate.explicit_name .. ' = { version = "' .. crate.vers.text .. '" }' })
{ text })


if state.cfg.expand_crate_moves_cursor then
local pos = { crate.lines.s + 1, #text - 2 }
vim.api.nvim_win_set_cursor(0, pos)
end
end

function M.extract_crate_into_table(buf, crate)
Expand Down
8 changes: 8 additions & 0 deletions teal/crates/config.tl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local record M
curl_args: {string}
open_programs: {string}
max_parallel_requests: integer
expand_crate_moves_cursor: boolean
disable_invalid_feature_diagnostic: boolean
enable_update_available_warning: boolean
text: TextConfig
Expand Down Expand Up @@ -357,6 +358,13 @@ entry(M.schema, "max_parallel_requests", {
Maximum number of parallel requests.
]],
})
entry(M.schema, "expand_crate_moves_cursor", {
type = "boolean",
default = true,
description = [[
Whether to move the cursor on |crates.expand_plain_crate_to_inline_table()|.
]],
})
entry(M.schema, "open_programs", {
type = "table",
default = { "xdg-open", "open" },
Expand Down
8 changes: 7 additions & 1 deletion teal/crates/edit.tl
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,16 @@ function M.expand_plain_crate_to_inline_table(buf: integer, crate: toml.Crate)
return
end

local text = crate.explicit_name .. ' = { version = "' .. crate.vers.text .. '" }'
vim.api.nvim_buf_set_text(
buf, crate.lines.s, crate.vers.decl_col.s, crate.lines.s, crate.vers.decl_col.e,
{ crate.explicit_name .. ' = { version = "' .. crate.vers.text .. '" }' }
{ text }
)

if state.cfg.expand_crate_moves_cursor then
local pos = { crate.lines.s + 1, #text - 2 }
vim.api.nvim_win_set_cursor(0, pos)
end
end

function M.extract_crate_into_table(buf: integer, crate: toml.Crate)
Expand Down

0 comments on commit 6d9c4dd

Please sign in to comment.