Skip to content

Commit

Permalink
fix: compatibility layer for vim.list_contains
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Oct 28, 2023
1 parent fadb76e commit 7e0364c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lua/rustaceanvim/commands/crate_graph.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local config = require('rustaceanvim.config.internal')
local compat = require('rustaceanvim.compat')

local M = {}

Expand Down Expand Up @@ -32,7 +33,7 @@ local function handler_factory(backend, output, pipe)
vim.notify('no crate graph backend specified.', vim.log.levels.ERROR)
return
end
if not vim.list_contains(config.tools.crate_graph.enabled_graphviz_backends, backend) then
if not compat.list_contains(config.tools.crate_graph.enabled_graphviz_backends, backend) then
vim.notify('crate graph backend not recognized as valid: ' .. vim.inspect(backend), vim.log.levels.ERROR)
return
end
Expand Down
11 changes: 11 additions & 0 deletions lua/rustaceanvim/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ M.system = vim.system
return systemObj
end

M.list_contains = vim.list_contains
or function(t, value)
vim.validate { t = { t, 't' } }
for _, v in ipairs(t) do
if v == value then
return true
end
end
return false
end

return M
11 changes: 6 additions & 5 deletions lua/rustaceanvim/dap.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local config = require('rustaceanvim.config.internal')
local compat = require('rustaceanvim.compat')

local function scheduled_error(err)
vim.schedule(function()
Expand Down Expand Up @@ -43,12 +44,12 @@ local function get_cargo_args_from_runnables_args(runnable_args)
local cargo_args = runnable_args.cargoArgs

local message_json = '--message-format=json'
if not vim.list_contains(cargo_args, message_json) then
if not compat.list_contains(cargo_args, message_json) then
table.insert(cargo_args, message_json)
end

for _, value in ipairs(runnable_args.cargoExtraArgs) do
if not vim.list_contains(cargo_args, value) then
if not compat.list_contains(cargo_args, value) then
table.insert(cargo_args, value)
end
end
Expand Down Expand Up @@ -91,10 +92,10 @@ function M.start(args)
goto loop_end
end

local is_binary = vim.list_contains(artifact.target.crate_types, 'bin')
local is_build_script = vim.list_contains(artifact.target.kind, 'custom-build')
local is_binary = compat.list_contains(artifact.target.crate_types, 'bin')
local is_build_script = compat.list_contains(artifact.target.kind, 'custom-build')
local is_test = ((artifact.profile.test == true) and (artifact.executable ~= nil))
or vim.list_contains(artifact.target.kind, 'test')
or compat.list_contains(artifact.target.kind, 'test')
-- only add executable to the list if we want a binary debug and it is a binary
-- or if we want a test debug and it is a test
if
Expand Down

0 comments on commit 7e0364c

Please sign in to comment.