From 7984975a2fa8e4c526359edf471a493307c0529c Mon Sep 17 00:00:00 2001 From: Steven Sojka Date: Wed, 24 Mar 2021 09:12:03 -0500 Subject: feat(install): allow ignore list when installing parsers (#1098) --- lua/nvim-treesitter/utils.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lua/nvim-treesitter/utils.lua') diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua index 8d5191d0..f82c2d4a 100644 --- a/lua/nvim-treesitter/utils.lua +++ b/lua/nvim-treesitter/utils.lua @@ -141,4 +141,29 @@ function M.index_of(tbl, obj) end end +-- Filters a list based on the given predicate +-- @param tbl The list to filter +-- @param predicate The predicate to filter with +function M.filter(tbl, predicate) + local result = {} + + for i, v in ipairs(tbl) do + if predicate(v, i) then + table.insert(result, v) + end + end + + return result +end + +-- Returns a list of all values from the first list +-- that are not present in the second list. +-- @params tbl1 The first table +-- @params tbl2 The second table +function M.difference(tbl1, tbl2) + return M.filter(tbl1, function(v) + return not vim.tbl_contains(tbl2, v) + end) +end + return M -- cgit v1.2.3