Skip to content

Commit 69b22bc

Browse files
authored
feat!: remove open_programs and use vim.ui.open() (#145)
1 parent 1c924d5 commit 69b22bc

File tree

6 files changed

+37
-57
lines changed

6 files changed

+37
-57
lines changed

doc/crates.txt

+3-7
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ For more information about individual config options see |crates-config|.
8888
notification_title = "crates.nvim",
8989
curl_args = { "-sL", "--retry", "1" },
9090
max_parallel_requests = 80,
91-
open_programs = { "xdg-open", "open" },
9291
expand_crate_moves_cursor = true,
9392
enable_update_available_warning = true,
9493
on_attach = function(bufnr) end,
@@ -624,12 +623,6 @@ max_parallel_requests *crates-config-max_parallel_requests*
624623
Maximum number of parallel requests.
625624

626625

627-
open_programs *crates-config-open_programs*
628-
Type: `string[]`, Default: `{ "xdg-open", "open" }`
629-
630-
A list of programs that used to open urls.
631-
632-
633626
expand_crate_moves_cursor *crates-config-expand_crate_moves_cursor*
634627
Type: `boolean`, Default: `true`
635628

@@ -705,6 +698,9 @@ text.error *crates-config-text-error*
705698
Format string used when there was an error loading crate information.
706699

707700

701+
open_programs *crates-config-open_programs*
702+
DEPRECATED
703+
708704
highlight *crates-config-highlight*
709705
Section type: `HighlightConfig`
710706

docgen/wiki/Documentation-unstable.md

-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ require("crates").setup {
168168
notification_title = "crates.nvim",
169169
curl_args = { "-sL", "--retry", "1" },
170170
max_parallel_requests = 80,
171-
open_programs = { "xdg-open", "open" },
172171
expand_crate_moves_cursor = true,
173172
enable_update_available_warning = true,
174173
on_attach = function(bufnr) end,

lua/crates/config/init.lua

+31-26
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ local M = {}
5454
---@class Deprecated
5555
---@field new_field string[]?
5656
---@field hard boolean?
57+
---@field msg string?
5758

5859
---@param schema table<string,SchemaElement>|SchemaElement[]
5960
---@param elem SchemaElement
@@ -210,14 +211,6 @@ entry(M.schema, {
210211
Maximum number of parallel requests.
211212
]],
212213
})
213-
entry(M.schema, {
214-
name = "open_programs",
215-
type = STRING_ARRAY_TYPE,
216-
default = { "xdg-open", "open" },
217-
description = [[
218-
A list of programs that used to open urls.
219-
]],
220-
})
221214
entry(M.schema, {
222215
name = "expand_crate_moves_cursor",
223216
type = BOOLEAN_TYPE,
@@ -324,6 +317,15 @@ entry(schema_text, {
324317
Format string used when there was an error loading crate information.
325318
]],
326319
})
320+
-- DEPRECATED
321+
entry(M.schema, {
322+
name = "open_programs",
323+
type = STRING_ARRAY_TYPE,
324+
deprecated = {
325+
msg = ", `vim.ui.open()` is used instead",
326+
hard = true,
327+
},
328+
})
327329

328330

329331
local schema_hl = section_entry(M.schema, {
@@ -1746,41 +1748,44 @@ local function validate_schema(path, schema, user_config)
17461748
local dep = elem.deprecated
17471749

17481750
if dep then
1749-
if dep.new_field then
1750-
---@type string
1751-
local dep_text
1752-
if dep.hard then
1753-
dep_text = "deprecated and won't work anymore"
1754-
else
1755-
dep_text = "deprecated and will stop working soon"
1756-
end
1751+
---@type string
1752+
local msg
1753+
if dep.msg then
1754+
msg = dep.msg
1755+
elseif dep.hard or not dep.new_field then
1756+
msg = " and won't work anymore"
1757+
else
1758+
msg = " and will stop working soon"
1759+
end
17571760

1761+
if dep.new_field then
17581762
warn(
1759-
"'%s' is now %s, please use '%s'",
1763+
"`%s` is now deprecated%s\nPlease use `%s`",
17601764
table.concat(p, "."),
1761-
dep_text,
1765+
msg,
17621766
table.concat(dep.new_field, ".")
17631767
)
17641768
else
17651769
warn(
1766-
"'%s' is now deprecated, ignoring",
1767-
table.concat(p, ".")
1770+
"`%s` is now deprecated%s",
1771+
table.concat(p, "."),
1772+
msg
17681773
)
17691774
end
17701775
elseif elem.type.config_type == "section" then
17711776
if value_type == "table" then
17721777
validate_schema(p, elem.fields, v)
17731778
else
17741779
warn(
1775-
"Config field '%s' was expected to be of type 'table' but was '%s', using default value.",
1780+
"Config field `%s` was expected to be of type `table` but was `%s`, using default value.",
17761781
table.concat(p, "."),
17771782
value_type
17781783
)
17791784
end
17801785
else
17811786
if not matches_type(value_type, elem.type) then
17821787
warn(
1783-
"Config field '%s' was expected to be of type '%s' but was '%s', using default value.",
1788+
"Config field `%s` was expected to be of type `%s` but was `%s`, using default value.",
17841789
table.concat(p, "."),
17851790
to_user_config_type_string(elem.type),
17861791
value_type
@@ -1789,7 +1794,7 @@ local function validate_schema(path, schema, user_config)
17891794
end
17901795
else
17911796
warn(
1792-
"Ignoring invalid config key '%s'",
1797+
"Ignoring invalid config key `%s`",
17931798
table.concat(p, ".")
17941799
)
17951800
end
@@ -1800,15 +1805,15 @@ end
18001805
---@return Config
18011806
local function setup_neoconf(config)
18021807
---@type boolean, table
1803-
local ok, neoconf = pcall(require, 'neoconf')
1808+
local ok, neoconf = pcall(require, "neoconf")
18041809
if not ok then
18051810
return config
18061811
end
18071812

18081813
-- enables neodev to autocomplete settings in .neoconf.json
18091814
pcall(function()
18101815
---@type table
1811-
local neoconf_plugins = require('neoconf.plugins')
1816+
local neoconf_plugins = require("neoconf.plugins")
18121817
neoconf_plugins.register {
18131818
on_schema = function(schema)
18141819
schema:import("crates", config)
@@ -1871,7 +1876,7 @@ function M.build(user_config)
18711876
user_config = user_config or {}
18721877
local user_config_type = type(user_config)
18731878
if user_config_type ~= "table" then
1874-
warn("Expected config of type 'table' found '%s'", user_config_type)
1879+
warn("Expected config of type `table` found `%s`", user_config_type)
18751880
user_config = {}
18761881
end
18771882

lua/crates/config/types.lua

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
---@field notification_title string
1717
---@field curl_args string[]
1818
---@field max_parallel_requests integer
19-
---@field open_programs string[]
2019
---@field expand_crate_moves_cursor boolean
2120
---@field enable_update_available_warning boolean
2221
---@field on_attach fun(bufnr: integer)
@@ -231,7 +230,6 @@
231230
---@field public notification_title? string
232231
---@field public curl_args? string[]
233232
---@field public max_parallel_requests? integer
234-
---@field public open_programs? string[]
235233
---@field public expand_crate_moves_cursor? boolean
236234
---@field public enable_update_available_warning? boolean
237235
---@field public on_attach? fun(bufnr: integer)

lua/crates/health.lua

-14
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ function M.check()
1717
else
1818
vim.health.error("curl not found")
1919
end
20-
21-
local num = 0
22-
for _, prg in ipairs(state.cfg.open_programs) do
23-
if util.binary_installed(prg) then
24-
vim.health.ok(string.format("%s installed", prg))
25-
---@type integer
26-
num = num + 1
27-
end
28-
end
29-
30-
if num == 0 then
31-
local programs = table.concat(state.cfg.open_programs, " ")
32-
vim.health.warn("none of the following are installed " .. programs)
33-
end
3420
end
3521

3622
return M

lua/crates/util.lua

+3-7
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,10 @@ end
233233

234234
---@param url string
235235
function M.open_url(url)
236-
for _, prg in ipairs(state.cfg.open_programs) do
237-
local ok, result = pcall(vim.cmd, string.format("silent !%s %s", prg, url))
238-
if ok == true then
239-
return
240-
end
236+
local _cmd, err = vim.ui.open(url)
237+
if err then
238+
M.notify(vim.log.levels.ERROR, "Couldn't open url: %s", err)
241239
end
242-
243-
M.notify(vim.log.levels.WARN, "Couldn't open url")
244240
end
245241

246242
return M

0 commit comments

Comments
 (0)