From 7e0364c32bb5f55a376e98a4258fab26a463d875 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Sat, 28 Oct 2023 12:14:00 +0200 Subject: [PATCH] fix: compatibility layer for vim.list_contains --- lua/rustaceanvim/commands/crate_graph.lua | 3 ++- lua/rustaceanvim/compat.lua | 11 +++++++++++ lua/rustaceanvim/dap.lua | 11 ++++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lua/rustaceanvim/commands/crate_graph.lua b/lua/rustaceanvim/commands/crate_graph.lua index 7f02a281..de31be96 100644 --- a/lua/rustaceanvim/commands/crate_graph.lua +++ b/lua/rustaceanvim/commands/crate_graph.lua @@ -1,4 +1,5 @@ local config = require('rustaceanvim.config.internal') +local compat = require('rustaceanvim.compat') local M = {} @@ -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 diff --git a/lua/rustaceanvim/compat.lua b/lua/rustaceanvim/compat.lua index 4b656388..9118e6a0 100644 --- a/lua/rustaceanvim/compat.lua +++ b/lua/rustaceanvim/compat.lua @@ -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 diff --git a/lua/rustaceanvim/dap.lua b/lua/rustaceanvim/dap.lua index dfc4e3f0..682a778e 100644 --- a/lua/rustaceanvim/dap.lua +++ b/lua/rustaceanvim/dap.lua @@ -1,4 +1,5 @@ local config = require('rustaceanvim.config.internal') +local compat = require('rustaceanvim.compat') local function scheduled_error(err) vim.schedule(function() @@ -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 @@ -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