summaryrefslogtreecommitdiff
path: root/lua/nvim-treesitter/utils.lua
diff options
context:
space:
mode:
authorSteven Sojka <steelsojka@users.noreply.github.com>2021-03-24 09:12:03 -0500
committerGitHub <noreply@github.com>2021-03-24 09:12:03 -0500
commit7984975a2fa8e4c526359edf471a493307c0529c (patch)
tree46bb699428271a031b1bca60a5a942c86505049a /lua/nvim-treesitter/utils.lua
parent09045354c0245ca866104c526bc57c2a06d7f381 (diff)
feat(install): allow ignore list when installing parsers (#1098)
Diffstat (limited to 'lua/nvim-treesitter/utils.lua')
-rw-r--r--lua/nvim-treesitter/utils.lua25
1 files changed, 25 insertions, 0 deletions
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