diff --git a/lazy-lock.json b/lazy-lock.json index 2c62387..6a1e1c4 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -5,6 +5,7 @@ "cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" }, "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "conform.nvim": { "branch": "master", "commit": "619363c30309d29ffa631e67c8183f2a72caa373" }, "friendly-snippets": { "branch": "main", "commit": "6cd7280adead7f586db6fccbd15d2cac7e2188b9" }, "gitsigns.nvim": { "branch": "main", "commit": "2038c666bd9d8a0b7349a0b6ee00dc83104b9ecf" }, "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, diff --git a/lua/config/ignored_patterns.lua b/lua/config/ignored_patterns.lua new file mode 100644 index 0000000..5ace81d --- /dev/null +++ b/lua/config/ignored_patterns.lua @@ -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 diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua index 65b4ff8..db21548 100644 --- a/lua/config/lazy.lua +++ b/lua/config/lazy.lua @@ -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({ diff --git a/lua/plugins/barbar.lua b/lua/plugins/barbar.lua index d08d857..e9ac275 100644 --- a/lua/plugins/barbar.lua +++ b/lua/plugins/barbar.lua @@ -6,10 +6,9 @@ return { }, init = function() vim.g.barbar_auto_setup = false end, opts = { - -- lazy.nvim will automatically call setup for you. put your options here, anything missing will use the default: - -- animation = true, - -- insert_at_start = true, - -- …etc. + sidebar_filetypes = { + NvimTree = true, + }, }, version = '^1.0.0', -- optional: only update when a new 1.x version is released }} diff --git a/lua/plugins/format.lua b/lua/plugins/format.lua new file mode 100644 index 0000000..925f4bc --- /dev/null +++ b/lua/plugins/format.lua @@ -0,0 +1,35 @@ +return { + { + "stevearc/conform.nvim", + event = { "BufWritePre" }, + cmd = { "ConformInfo" }, + keys = { + { + "f", + function() + require("conform").format({ async = true, lsp_fallback = true }) + end, + mode = "", + desc = "Format buffer", + }, + }, + opts = { + formatters_by_ft = { + lua = { "stylua" }, + python = { "ruff_format" }, + javascript = { "prettier" }, + typescript = { "prettier" }, + javascriptreact = { "prettier" }, + typescriptreact = { "prettier" }, + html = { "prettier" }, + css = { "prettier" }, + json = { "prettier" }, + markdown = { "prettier" }, + }, + format_on_save = { + timeout_ms = 500, + lsp_fallback = true, + }, + }, + }, +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 54c0970..4bb9a96 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -27,6 +27,8 @@ return { ensure_installed = { "pyright", "ruff", + "ts_ls", + "eslint", }, automatic_installation = true, }, @@ -77,15 +79,13 @@ return { client.server_capabilities.hoverProvider = false end - -- Format on save if client supports it - if client and client:supports_method("textDocument/formatting") then - local format_grp = vim.api.nvim_create_augroup("LspFormat." .. bufnr, { clear = true }) + -- Auto-fix ESLint issues on save if ESLint is active + if client and client.name == "eslint" then + local eslint_grp = vim.api.nvim_create_augroup("LspEslint." .. bufnr, { clear = true }) vim.api.nvim_create_autocmd("BufWritePre", { - group = format_grp, + group = eslint_grp, buffer = bufnr, - callback = function() - vim.lsp.buf.format({ bufnr = bufnr, id = client.id, async = false }) - end, + command = "EslintFixAll", }) end @@ -152,6 +152,26 @@ return { capabilities = capabilities, }) vim.lsp.enable("ruff") + + -- Configure ts_ls (TypeScript/JavaScript LSP) using native Neovim 0.11+ API + vim.lsp.config("ts_ls", { + capabilities = capabilities, + init_options = { + preferences = { + disableSuggestions = false, + }, + }, + }) + vim.lsp.enable("ts_ls") + + -- Configure ESLint (JS/TS linter) using native Neovim 0.11+ API + vim.lsp.config("eslint", { + capabilities = capabilities, + settings = { + workingDirectories = { mode = "location" }, + }, + }) + vim.lsp.enable("eslint") end, }, } diff --git a/lua/plugins/nvim-tree.lua b/lua/plugins/nvim-tree.lua index ec5ee27..b60f31f 100644 --- a/lua/plugins/nvim-tree.lua +++ b/lua/plugins/nvim-tree.lua @@ -6,13 +6,15 @@ return { "nvim-tree/nvim-web-devicons", }, config = function() + local ignored = require("config.ignored_patterns") -- vim.cmd([[hi NvimTreeNormal guibg=NONE ctermbd=NONE]]) require("nvim-tree").setup { git = { ignore = false, }, - filters= { + filters = { dotfiles = false, + custom = ignored.get_for_nvim_tree(), }, view = { adaptive_size = true, diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 2b4256a..ed3ecda 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -6,8 +6,10 @@ return { { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' }, }, config = function() + local ignored = require("config.ignored_patterns") require('telescope').setup({ defaults = { + file_ignore_patterns = ignored.get_for_telescope(), vimgrep_arguments = { "rg", "--color=never",