From 511492f6e1ab66957a37aaccffe748bb0f8e3d65 Mon Sep 17 00:00:00 2001 From: beeb5k Date: Fri, 5 Jun 2026 16:20:33 +0530 Subject: formamt files and perf improvements --- lua/bee/format.lua | 64 ++++---- lua/bee/init.lua | 11 +- lua/bee/lint.lua | 30 ++-- lua/bee/plugins/treesitter.lua | 353 +++++++++++++++++++++-------------------- lua/bee/utils/init.lua | 118 +++++++------- 5 files changed, 284 insertions(+), 292 deletions(-) (limited to 'lua') diff --git a/lua/bee/format.lua b/lua/bee/format.lua index c8d1214..5a123a4 100644 --- a/lua/bee/format.lua +++ b/lua/bee/format.lua @@ -1,35 +1,35 @@ return { - "conform.nvim", - auto_enable = true, - event = "FileType", - keys = { - { "lf", desc = "[F]ormat [F]ile" }, - }, - after = function(_) - local conform = require("conform") - conform.setup({ - format_on_save = { - timeout_ms = 1000, - lsp_format = "fallback", - quiet = true, - }, - formatters_by_ft = { - lua = { "stylua" }, - nix = { "nixfmt" }, - c = { "clang_format" }, - cpp = { "clang_format" }, - cmake = { "cmake_format" }, - -- Use a sub-list to run only the first available formatter - javascript = { { "prettierd", "prettier" } }, - }, - }) + "conform.nvim", + auto_enable = true, + event = "FileType", + keys = { + { "lf", desc = "[F]ormat [F]ile" }, + }, + after = function(_) + local conform = require("conform") + conform.setup({ + format_on_save = { + timeout_ms = 1000, + lsp_format = "fallback", + quiet = true, + }, + formatters_by_ft = { + lua = { "stylua" }, + nix = { "nixfmt" }, + c = { "clang_format" }, + cpp = { "clang_format" }, + cmake = { "cmake_format" }, + -- Use a sub-list to run only the first available formatter + javascript = { { "prettierd", "prettier" } }, + }, + }) - vim.keymap.set({ "n", "v" }, "lf", function() - conform.format({ - lsp_fallback = true, - async = false, - timeout_ms = 1000, - }) - end, { desc = "[L]anguage [F]ormat" }) - end, + vim.keymap.set({ "n", "v" }, "lf", function() + conform.format({ + lsp_fallback = true, + async = false, + timeout_ms = 1000, + }) + end, { desc = "[L]anguage [F]ormat" }) + end, } diff --git a/lua/bee/init.lua b/lua/bee/init.lua index 0b4db3d..265a0e3 100644 --- a/lua/bee/init.lua +++ b/lua/bee/init.lua @@ -29,15 +29,6 @@ nixInfo.lze.load({ { import = MP:relpath("format") }, { import = MP:relpath("lint") }, { import = MP:relpath("LSPs") }, - { - "base46", - lazy = false, - auto_enable = true, - event = "VimEnter", - after = function(_) - require("base46").setup() - end, - }, { "vim-startuptime", auto_enable = true, @@ -96,4 +87,4 @@ nixInfo.lze.load({ }, }) -vim.cmd.colorscheme("matugen") +vim.cmd.colorscheme("base46-tokyonight") diff --git a/lua/bee/lint.lua b/lua/bee/lint.lua index d29ea3a..7d03feb 100644 --- a/lua/bee/lint.lua +++ b/lua/bee/lint.lua @@ -1,18 +1,18 @@ return { - "nvim-lint", - auto_enable = true, - event = "FileType", - after = function(_) - require("lint").linters_by_ft = { - cpp = { "cpplint" }, - javascript = { "eslint" }, - typescript = { "eslint" }, - } + "nvim-lint", + auto_enable = true, + event = "FileType", + after = function(_) + require("lint").linters_by_ft = { + cpp = { "cpplint" }, + javascript = { "eslint" }, + typescript = { "eslint" }, + } - vim.api.nvim_create_autocmd({ "BufWritePost" }, { - callback = function() - require("lint").try_lint() - end, - }) - end, + vim.api.nvim_create_autocmd({ "BufWritePost" }, { + callback = function() + require("lint").try_lint() + end, + }) + end, } diff --git a/lua/bee/plugins/treesitter.lua b/lua/bee/plugins/treesitter.lua index bfce021..31917cf 100644 --- a/lua/bee/plugins/treesitter.lua +++ b/lua/bee/plugins/treesitter.lua @@ -1,192 +1,193 @@ -- Docs say not to lazy load it return { - { - "nvim-treesitter", - auto_enable = true, - lazy = false, - after = function(plugin) - ---@param buf integer - ---@param language string - local function treesitter_try_attach(buf, language) - -- check if parser exists and load it - if not vim.treesitter.language.add(language) then - return false - end - vim.treesitter.start(buf, language) + { + "nvim-treesitter", + auto_enable = true, + lazy = false, + after = function(plugin) + ---@param buf integer + ---@param language string + local function treesitter_try_attach(buf, language) + -- check if parser exists and load it + if not vim.treesitter.language.add(language) then + return false + end + vim.treesitter.start(buf, language) - -- enables treesitter based folds - vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()" - vim.wo.foldmethod = "expr" - -- ensure folds are open to begin with - vim.o.foldlevel = 99 + -- enables treesitter based folds + vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()" + vim.wo.foldmethod = "expr" + -- ensure folds are open to begin with + vim.o.foldlevel = 99 - -- enables treesitter based indentation - vim.b.did_indent = 1 -- this right here prevents built-in indent scripts from loading - vim.bo.indentexpr = "v:lua.require'nvim-treesitter.indent'.get_indent(v:lnum)" + -- enables treesitter based indentation + vim.b.did_indent = 1 -- this right here prevents built-in indent scripts from loading + vim.bo.indentexpr = "v:lua.require'nvim-treesitter.indent'.get_indent(v:lnum)" - return true - end + return true + end - local installable_parsers = nixInfo.isNix or require("nvim-treesitter").get_available() - vim.api.nvim_create_autocmd("FileType", { - callback = function(args) - local buf, filetype = args.buf, args.match - local language = vim.treesitter.language.get_lang(filetype) - if not language then - return - end + local installable_parsers = nixInfo.isNix or require("nvim-treesitter").get_available() + vim.api.nvim_create_autocmd("FileType", { + callback = function(args) + local buf, filetype = args.buf, args.match + local language = vim.treesitter.language.get_lang(filetype) + if not language then + return + end - if not treesitter_try_attach(buf, language) and not nixInfo.isNix then - -- we do something more interesting in nix and don't do this there - ---@cast installable_parsers string[] - if vim.tbl_contains(installable_parsers, language) then - -- not already installed, so try to install them via nvim-treesitter if possible - require("nvim-treesitter").install(language):await(function() - treesitter_try_attach(buf, language) - end) - end - end - end, - }) - end, - }, - { - "nvim-treesitter-textobjects", - auto_enable = true, - lazy = false, - before = function(plugin) - vim.g.no_plugin_maps = true - end, - after = function(plugin) - require("nvim-treesitter-textobjects").setup({ - select = { - -- Automatically jump forward to textobj, similar to targets.vim - lookahead = true, - -- You can choose the select mode (default is charwise 'v') - -- - -- Can also be a function which gets passed a table with the keys - -- * query_string: eg '@function.inner' - -- * method: eg 'v' or 'o' - -- and should return the mode ('v', 'V', or '') or a table - -- mapping query_strings to modes. - selection_modes = { - ["@parameter.outer"] = "v", -- charwise - ["@function.outer"] = "V", -- linewise - -- ['@class.outer'] = '', -- blockwise - }, - -- If you set this to `true` (default is `false`) then any textobject is - -- extended to include preceding or succeeding whitespace. Succeeding - -- whitespace has priority in order to act similarly to eg the built-in - -- `ap`. - -- - -- Can also be a function which gets passed a table with the keys - -- * query_string: eg '@function.inner' - -- * selection_mode: eg 'v' - -- and should return true of false - include_surrounding_whitespace = false, - }, - move = { - set_jumps = true, - }, - }) + if not treesitter_try_attach(buf, language) and not nixInfo.isNix then + -- we do something more interesting in nix and don't do this there + ---@cast installable_parsers string[] + if vim.tbl_contains(installable_parsers, language) then + -- not already installed, so try to install them via nvim-treesitter if possible + require("nvim-treesitter").install(language):await(function() + treesitter_try_attach(buf, language) + end) + end + end + end, + }) + end, + }, + { + "nvim-treesitter-textobjects", + auto_enable = true, + lazy = false, + before = function(plugin) + vim.g.no_plugin_maps = true + end, + after = function(plugin) + require("nvim-treesitter-textobjects").setup({ + select = { + -- Automatically jump forward to textobj, similar to targets.vim + lookahead = true, + -- You can choose the select mode (default is charwise 'v') + -- + -- Can also be a function which gets passed a table with the keys + -- * query_string: eg '@function.inner' + -- * method: eg 'v' or 'o' + -- and should return the mode ('v', 'V', or '') or a table + -- mapping query_strings to modes. + selection_modes = { + ["@parameter.outer"] = "v", -- charwise + ["@function.outer"] = "V", -- linewise + -- ['@class.outer'] = '', -- blockwise + }, + -- If you set this to `true` (default is `false`) then any textobject is + -- extended to include preceding or succeeding whitespace. Succeeding + -- whitespace has priority in order to act similarly to eg the built-in + -- `ap`. + -- + -- Can also be a function which gets passed a table with the keys + -- * query_string: eg '@function.inner' + -- * selection_mode: eg 'v' + -- and should return true of false + include_surrounding_whitespace = false, + }, + move = { + set_jumps = true, + }, + }) - -- keymaps - -- You can use the capture groups defined in `textobjects.scm` - vim.keymap.set({ "x", "o" }, "am", function() - require("nvim-treesitter-textobjects.select").select_textobject("@function.outer", "textobjects") - end) - vim.keymap.set({ "x", "o" }, "im", function() - require("nvim-treesitter-textobjects.select").select_textobject("@function.inner", "textobjects") - end) - vim.keymap.set({ "x", "o" }, "ac", function() - require("nvim-treesitter-textobjects.select").select_textobject("@class.outer", "textobjects") - end) - vim.keymap.set({ "x", "o" }, "ic", function() - require("nvim-treesitter-textobjects.select").select_textobject("@class.inner", "textobjects") - end) - -- You can also use captures from other query groups like `locals.scm` - vim.keymap.set({ "x", "o" }, "as", function() - require("nvim-treesitter-textobjects.select").select_textobject("@local.scope", "locals") - end) - vim.keymap.set("n", "a", function() - require("nvim-treesitter-textobjects.swap").swap_next("@parameter.inner") - end) - vim.keymap.set("n", "A", function() - require("nvim-treesitter-textobjects.swap").swap_previous("@parameter.outer") - end) + -- keymaps + -- You can use the capture groups defined in `textobjects.scm` + vim.keymap.set({ "x", "o" }, "am", function() + require("nvim-treesitter-textobjects.select").select_textobject("@function.outer", "textobjects") + end) + vim.keymap.set({ "x", "o" }, "im", function() + require("nvim-treesitter-textobjects.select").select_textobject("@function.inner", "textobjects") + end) + vim.keymap.set({ "x", "o" }, "ac", function() + require("nvim-treesitter-textobjects.select").select_textobject("@class.outer", "textobjects") + end) + vim.keymap.set({ "x", "o" }, "ic", function() + require("nvim-treesitter-textobjects.select").select_textobject("@class.inner", "textobjects") + end) + -- You can also use captures from other query groups like `locals.scm` + vim.keymap.set({ "x", "o" }, "as", function() + require("nvim-treesitter-textobjects.select").select_textobject("@local.scope", "locals") + end) + vim.keymap.set("n", "a", function() + require("nvim-treesitter-textobjects.swap").swap_next("@parameter.inner") + end) + vim.keymap.set("n", "A", function() + require("nvim-treesitter-textobjects.swap").swap_previous("@parameter.outer") + end) - -- You can use the capture groups defined in `textobjects.scm` - vim.keymap.set({ "n", "x", "o" }, "]m", function() - require("nvim-treesitter-textobjects.move").goto_next_start("@function.outer", "textobjects") - end) - vim.keymap.set({ "n", "x", "o" }, "]]", function() - require("nvim-treesitter-textobjects.move").goto_next_start("@class.outer", "textobjects") - end) - -- You can also pass a list to group multiple queries. - vim.keymap.set({ "n", "x", "o" }, "]o", function() - require("nvim-treesitter-textobjects.move").goto_next_start( - { "@loop.inner", "@loop.outer" }, - "textobjects" - ) - end) - -- You can also use captures from other query groups like `locals.scm` or `folds.scm` - vim.keymap.set({ "n", "x", "o" }, "]s", function() - require("nvim-treesitter-textobjects.move").goto_next_start("@local.scope", "locals") - end) - vim.keymap.set({ "n", "x", "o" }, "]z", function() - require("nvim-treesitter-textobjects.move").goto_next_start("@fold", "folds") - end) + -- You can use the capture groups defined in `textobjects.scm` + vim.keymap.set({ "n", "x", "o" }, "]m", function() + require("nvim-treesitter-textobjects.move").goto_next_start("@function.outer", "textobjects") + end) + vim.keymap.set({ "n", "x", "o" }, "]]", function() + require("nvim-treesitter-textobjects.move").goto_next_start("@class.outer", "textobjects") + end) + -- You can also pass a list to group multiple queries. + vim.keymap.set({ "n", "x", "o" }, "]o", function() + require("nvim-treesitter-textobjects.move").goto_next_start( + { "@loop.inner", "@loop.outer" }, + "textobjects" + ) + end) + -- You can also use captures from other query groups like `locals.scm` or `folds.scm` + vim.keymap.set({ "n", "x", "o" }, "]s", function() + require("nvim-treesitter-textobjects.move").goto_next_start("@local.scope", "locals") + end) + vim.keymap.set({ "n", "x", "o" }, "]z", function() + require("nvim-treesitter-textobjects.move").goto_next_start("@fold", "folds") + end) - vim.keymap.set({ "n", "x", "o" }, "]M", function() - require("nvim-treesitter-textobjects.move").goto_next_end("@function.outer", "textobjects") - end) - vim.keymap.set({ "n", "x", "o" }, "][", function() - require("nvim-treesitter-textobjects.move").goto_next_end("@class.outer", "textobjects") - end) + vim.keymap.set({ "n", "x", "o" }, "]M", function() + require("nvim-treesitter-textobjects.move").goto_next_end("@function.outer", "textobjects") + end) + vim.keymap.set({ "n", "x", "o" }, "][", function() + require("nvim-treesitter-textobjects.move").goto_next_end("@class.outer", "textobjects") + end) - vim.keymap.set({ "n", "x", "o" }, "[m", function() - require("nvim-treesitter-textobjects.move").goto_previous_start("@function.outer", "textobjects") - end) - vim.keymap.set({ "n", "x", "o" }, "[[", function() - require("nvim-treesitter-textobjects.move").goto_previous_start("@class.outer", "textobjects") - end) + vim.keymap.set({ "n", "x", "o" }, "[m", function() + require("nvim-treesitter-textobjects.move").goto_previous_start("@function.outer", "textobjects") + end) + vim.keymap.set({ "n", "x", "o" }, "[[", function() + require("nvim-treesitter-textobjects.move").goto_previous_start("@class.outer", "textobjects") + end) - vim.keymap.set({ "n", "x", "o" }, "[M", function() - require("nvim-treesitter-textobjects.move").goto_previous_end("@function.outer", "textobjects") - end) - vim.keymap.set({ "n", "x", "o" }, "[]", function() - require("nvim-treesitter-textobjects.move").goto_previous_end("@class.outer", "textobjects") - end) - local ts_repeat_move = require("nvim-treesitter-textobjects.repeatable_move") + vim.keymap.set({ "n", "x", "o" }, "[M", function() + require("nvim-treesitter-textobjects.move").goto_previous_end("@function.outer", "textobjects") + end) + vim.keymap.set({ "n", "x", "o" }, "[]", function() + require("nvim-treesitter-textobjects.move").goto_previous_end("@class.outer", "textobjects") + end) + local ts_repeat_move = require("nvim-treesitter-textobjects.repeatable_move") - -- Repeat movement with ; and , - -- ensure ; goes forward and , goes backward regardless of the last direction - -- vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next) - -- vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous) + -- Repeat movement with ; and , + -- ensure ; goes forward and , goes backward regardless of the last direction + -- vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next) + -- vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous) - -- vim way: ; goes to the direction you were moving. - vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move) - vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_opposite) + -- vim way: ; goes to the direction you were moving. + vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move) + vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_opposite) - -- Optionally, make builtin f, F, t, T also repeatable with ; and , - vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f_expr, { expr = true }) - vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F_expr, { expr = true }) - vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t_expr, { expr = true }) - vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T_expr, { expr = true }) - end, - }, - { - "nvim-ts-autotag", - auto_enable = true, - lazy = false, - after = function(plugin) - require("nvim-ts-autotag").setup({ - opts = { - enable_close = true, - enable_rename = true, - enable_close_on_slash = false, - }, - }) - end, - }, + -- Optionally, make builtin f, F, t, T also repeatable with ; and , + vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f_expr, { expr = true }) + vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F_expr, { expr = true }) + vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t_expr, { expr = true }) + vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T_expr, { expr = true }) + end, + }, + { + "nvim-ts-autotag", + auto_enable = true, + ft = { "html" }, + -- lazy = false, + after = function(plugin) + require("nvim-ts-autotag").setup({ + opts = { + enable_close = true, + enable_rename = true, + enable_close_on_slash = false, + }, + }) + end, + }, } diff --git a/lua/bee/utils/init.lua b/lua/bee/utils/init.lua index 4296561..49be80e 100644 --- a/lua/bee/utils/init.lua +++ b/lua/bee/utils/init.lua @@ -1,77 +1,77 @@ local M = {} local nixInfo = _G.nixInfo or function(default, ...) - return default + return default end function M.get_nix_plugin_path(name) - if vim.g.nix_info_plugin_name then - return nixInfo(nil, "plugins", "lazy", name) or nixInfo(nil, "plugins", "start", name) - else - return vim.api.nvim_get_runtime_file("pack/*/*/" .. name, false)[1] - end + if vim.g.nix_info_plugin_name then + return nixInfo(nil, "plugins", "lazy", name) or nixInfo(nil, "plugins", "start", name) + else + return vim.api.nvim_get_runtime_file("pack/*/*/" .. name, false)[1] + end end function M.lsp_ft_fallback(name) - local nvimlspcfg = M.get_nix_plugin_path("nvim-lspconfig") - if not nvimlspcfg then - local matches = vim.api.nvim_get_runtime_file("pack/*/*/nvim-lspconfig", false) - nvimlspcfg = assert(matches[1], "nvim-lspconfig not found!") - end - vim.api.nvim_create_user_command("LspGetFiletypesToClipboard", function(opts) - local lspname = - assert(opts.fargs[1] or vim.fn.getreg("+") or name, "no name to search for provided or in clipboard") - local ok, lspcfg = pcall(dofile, nvimlspcfg .. "/lsp/" .. lspname .. ".lua") - if not ok or not lspcfg then - error("failed to get config for lsp: " .. lspname) - end - vim.fn.setreg("+", "filetypes = " .. vim.inspect(lspcfg.filetypes or {}) .. ",") - end, { nargs = "?" }) - vim.schedule(function() - vim.notify((name or "lsp") .. " not provided filetype", vim.log.levels.WARN) - end) - return name and dofile(nvimlspcfg .. "/lsp/" .. name .. ".lua").filetypes or {} + local nvimlspcfg = M.get_nix_plugin_path("nvim-lspconfig") + if not nvimlspcfg then + local matches = vim.api.nvim_get_runtime_file("pack/*/*/nvim-lspconfig", false) + nvimlspcfg = assert(matches[1], "nvim-lspconfig not found!") + end + vim.api.nvim_create_user_command("LspGetFiletypesToClipboard", function(opts) + local lspname = + assert(opts.fargs[1] or vim.fn.getreg("+") or name, "no name to search for provided or in clipboard") + local ok, lspcfg = pcall(dofile, nvimlspcfg .. "/lsp/" .. lspname .. ".lua") + if not ok or not lspcfg then + error("failed to get config for lsp: " .. lspname) + end + vim.fn.setreg("+", "filetypes = " .. vim.inspect(lspcfg.filetypes or {}) .. ",") + end, { nargs = "?" }) + vim.schedule(function() + vim.notify((name or "lsp") .. " not provided filetype", vim.log.levels.WARN) + end) + return name and dofile(nvimlspcfg .. "/lsp/" .. name .. ".lua").filetypes or {} end M.auto_enable_handler = { - spec_field = "auto_enable", - set_lazy = false, - modify = function(plugin) - if vim.g.nix_info_plugin_name then - if type(plugin.auto_enable) == "table" then - for _, name in pairs(plugin.auto_enable) do - if not M.get_nix_plugin_path(name) then - plugin.enabled = false - break - end - end - elseif type(plugin.auto_enable) == "string" then - if not M.get_nix_plugin_path(plugin.auto_enable) then - plugin.enabled = false - end - elseif type(plugin.auto_enable) == "boolean" and plugin.auto_enable then - if not M.get_nix_plugin_path(plugin.name) then - plugin.enabled = false - end - end - end - return plugin - end, + spec_field = "auto_enable", + set_lazy = false, + modify = function(plugin) + if vim.g.nix_info_plugin_name then + if type(plugin.auto_enable) == "table" then + for _, name in pairs(plugin.auto_enable) do + if not M.get_nix_plugin_path(name) then + plugin.enabled = false + break + end + end + elseif type(plugin.auto_enable) == "string" then + if not M.get_nix_plugin_path(plugin.auto_enable) then + plugin.enabled = false + end + elseif type(plugin.auto_enable) == "boolean" and plugin.auto_enable then + if not M.get_nix_plugin_path(plugin.name) then + plugin.enabled = false + end + end + end + return plugin + end, } M.for_cat_handler = { - spec_field = "for_cat", - set_lazy = false, - modify = function(plugin) - if vim.g.nix_info_plugin_name then - if type(plugin.for_cat) == "table" then - plugin.enabled = nixInfo(plugin.for_cat.default, "settings", "cats", plugin.for_cat.cat) - elseif type(plugin.for_cat) == "string" then - plugin.enabled = nixInfo(false, "settings", "cats", plugin.for_cat) - end - end - return plugin - end, + spec_field = "for_cat", + set_lazy = false, + modify = function(plugin) + if vim.g.nix_info_plugin_name then + if type(plugin.for_cat) == "table" then + plugin.enabled = nixInfo(plugin.for_cat.default, "settings", "cats", plugin.for_cat.cat) + elseif type(plugin.for_cat) == "string" then + plugin.enabled = nixInfo(false, "settings", "cats", plugin.for_cat) + end + end + return plugin + end, } return M -- cgit v1.3.1