add support for ts/js

This commit is contained in:
2026-06-30 08:44:54 +05:30
parent c2c98ec83c
commit a9651a67c6
8 changed files with 232 additions and 12 deletions

View File

@@ -0,0 +1,160 @@
local M = {}
local fn = vim.fn
local file_path = fn.stdpath("data") .. "/ignored_patterns.json"
function M.load()
if fn.filereadable(file_path) == 0 then
return {
".git",
"node_modules",
}
end
local file = io.open(file_path, "r")
if not file then return {} end
local content = file:read("*a")
file:close()
local ok, data = pcall(fn.json_decode, content)
if ok and type(data) == "table" then
return data
end
return {}
end
function M.save(patterns)
local file = io.open(file_path, "w")
if not file then return end
file:write(fn.json_encode(patterns))
file:close()
end
function M.get_for_nvim_tree()
local patterns = M.load()
local nvim_tree_patterns = {}
for _, p in ipairs(patterns) do
table.insert(nvim_tree_patterns, p)
end
return nvim_tree_patterns
end
function M.get_for_telescope()
local patterns = M.load()
local telescope_patterns = {}
for _, p in ipairs(patterns) do
table.insert(telescope_patterns, p)
-- Also ignore contents if it's a directory
if not p:match("[.*%%]") then
table.insert(telescope_patterns, p .. "/.*")
end
end
return telescope_patterns
end
function M.apply()
local nvim_tree_patterns = M.get_for_nvim_tree()
local telescope_patterns = M.get_for_telescope()
-- Apply to nvim-tree if loaded
local has_nvim_tree, nvim_tree = pcall(require, "nvim-tree")
if has_nvim_tree then
nvim_tree.setup({
git = {
ignore = false,
},
filters = {
dotfiles = false,
custom = nvim_tree_patterns,
},
view = {
adaptive_size = true,
}
})
pcall(require("nvim-tree.api").tree.reload)
end
-- Apply to telescope if loaded
local has_telescope, telescope = pcall(require, "telescope")
if has_telescope then
telescope.setup({
defaults = {
file_ignore_patterns = telescope_patterns,
vimgrep_arguments = {
"rg",
"--color=never",
"--no-heading",
"--with-filename",
"--line-number",
"--column",
"--smart-case",
"--no-ignore",
},
},
pickers = {
find_files = {
no_ignore = true,
},
},
})
end
end
function M.add(pattern)
if not pattern or pattern == "" then return end
local patterns = M.load()
for _, p in ipairs(patterns) do
if p == pattern then
print("Pattern already ignored: " .. pattern)
return
end
end
table.insert(patterns, pattern)
M.save(patterns)
M.apply()
print("Added to ignored patterns: " .. pattern)
end
function M.remove(pattern)
if not pattern or pattern == "" then return end
local patterns = M.load()
local index = nil
for i, p in ipairs(patterns) do
if p == pattern then
index = i
break
end
end
if index then
table.remove(patterns, index)
M.save(patterns)
M.apply()
print("Removed from ignored patterns: " .. pattern)
else
print("Pattern not found in ignores: " .. pattern)
end
end
function M.list()
local patterns = M.load()
if #patterns == 0 then
print("No custom ignored patterns.")
else
print("Ignored patterns:")
for _, p in ipairs(patterns) do
print(" - " .. p)
end
end
end
-- Create the custom commands
vim.api.nvim_create_user_command("IgnoreAdd", function(opts)
M.add(opts.args)
end, { nargs = 1, desc = "Add file/directory pattern to nvim-tree and telescope ignore lists" })
vim.api.nvim_create_user_command("IgnoreRemove", function(opts)
M.remove(opts.args)
end, { nargs = 1, desc = "Remove file/directory pattern from nvim-tree and telescope ignore lists" })
vim.api.nvim_create_user_command("IgnoreList", function()
M.list()
end, { desc = "List all custom ignored patterns" })
return M

View File

@@ -20,6 +20,7 @@ require("config.options")
require("config.keymaps")
require("config.globals")
require("config.autocmds")
require("config.ignored_patterns")
-- Setup lazy.nvim
require("lazy").setup({