diff options
Diffstat (limited to 'configs/nvim/lua/crupest/nvim/plugins')
-rw-r--r-- | configs/nvim/lua/crupest/nvim/plugins/cmp.lua | 31 | ||||
-rw-r--r-- | configs/nvim/lua/crupest/nvim/plugins/format.lua | 76 | ||||
-rw-r--r-- | configs/nvim/lua/crupest/nvim/plugins/formatter.lua | 114 | ||||
-rw-r--r-- | configs/nvim/lua/crupest/nvim/plugins/gitsign.lua | 51 | ||||
-rw-r--r-- | configs/nvim/lua/crupest/nvim/plugins/init.lua | 11 | ||||
-rw-r--r-- | configs/nvim/lua/crupest/nvim/plugins/lint.lua | 39 | ||||
-rw-r--r-- | configs/nvim/lua/crupest/nvim/plugins/others.lua | 20 | ||||
-rw-r--r-- | configs/nvim/lua/crupest/nvim/plugins/snip.lua | 5 | ||||
-rw-r--r-- | configs/nvim/lua/crupest/nvim/plugins/telescope.lua | 11 |
9 files changed, 150 insertions, 208 deletions
diff --git a/configs/nvim/lua/crupest/nvim/plugins/cmp.lua b/configs/nvim/lua/crupest/nvim/plugins/cmp.lua new file mode 100644 index 0000000..9b1d876 --- /dev/null +++ b/configs/nvim/lua/crupest/nvim/plugins/cmp.lua @@ -0,0 +1,31 @@ +local function setup() + local cmp = require("cmp") + local luasnip = require("luasnip") + + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + window = { + }, + mapping = cmp.mapping.preset.insert({ + ['<C-b>'] = cmp.mapping.scroll_docs(-4), + ['<C-f>'] = cmp.mapping.scroll_docs(4), + ['<C-Space>'] = cmp.mapping.complete(), + ['<C-e>'] = cmp.mapping.abort(), + ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, { + { name = 'buffer' }, + }) + } +end + +return { + setup = setup +} diff --git a/configs/nvim/lua/crupest/nvim/plugins/format.lua b/configs/nvim/lua/crupest/nvim/plugins/format.lua deleted file mode 100644 index 0e3320a..0000000 --- a/configs/nvim/lua/crupest/nvim/plugins/format.lua +++ /dev/null @@ -1,76 +0,0 @@ -local find = require("crupest.system.find") -local constants = require("crupest.constants") - -local function wrap_formatter_with_exe(name, exe) - local formatter = require('formatter.defaults.' .. name) - formatter = formatter() - formatter.try_node_modules = false - formatter.exe = exe - return formatter -end - -local function set_formatters_for_filetype(filetype, formatters) - require('formatter.config').values.filetype[filetype] = formatters -end - -local my_formatters = { - { - name = "prettier", - exe_places = { "npm" }, - filetypes = constants.filetype_collections.frontend, - config_files = constants.config_patterns.nodejs, - }, -} - -local function find_custom_formatter(opts) - if opts == nil then opts = {} end - if opts.buf == nil then opts.buf = 0 end - - for _, f in ipairs(my_formatters) do - local r = find.find_exe_for_buf(opts.buf, f) - if r ~= nil then - local formatter = wrap_formatter_with_exe(r.name, r.exe_path) - set_formatters_for_filetype(r.filetype, { formatter }) - return r.name - end - end - - return nil -end - - -local function do_format(opt) - if not opt then - opt = {} - end - - if not opt.buf then - opt.buf = 0 - end - - local custom_formatter = find_custom_formatter(opt) - - if custom_formatter then - print("Use custom formatters: " .. custom_formatter .. ".") - vim.cmd("Format") - return - end - - local has_lsp = vim.lsp.get_active_clients({ bufnr = 0 }) - if has_lsp then - print("Use lsp formatter.") - vim.lsp.buf.format { async = true } - return - end - - vim.notify("No formatters found.", vim.log.levels.ERROR); -end - -local function setup_format() - require("formatter").setup {} -end - -return { - setup_format = setup_format, - do_format = do_format, -} diff --git a/configs/nvim/lua/crupest/nvim/plugins/formatter.lua b/configs/nvim/lua/crupest/nvim/plugins/formatter.lua deleted file mode 100644 index 9f6138f..0000000 --- a/configs/nvim/lua/crupest/nvim/plugins/formatter.lua +++ /dev/null @@ -1,114 +0,0 @@ -local fs = require("crupest.system.fs") -local find_npm_exe = require("crupest.system.find").find_npm_exe; - -local prettier_formatter = function() - local current_buffer = vim.api.nvim_buf_get_name(0) - local prettier_exe = find_npm_exe(current_buffer, "prettier") or "prettier" - - if vim.fn.has("win32") ~= 0 then - local escape = fs.escape_space - current_buffer = escape(current_buffer) - prettier_exe = escape(prettier_exe) - end - - return { - exe = prettier_exe, - args = { - "--stdin-filepath", - current_buffer - }, - stdin = true, - } -end - -local formatters_for_filetype = { - html = { - prettier_formatter - }, - css = { - prettier_formatter - }, - javascript = { - prettier_formatter - }, - javascriptreact = { - prettier_formatter - }, - typescript = { - prettier_formatter - }, - typescriptreact = { - prettier_formatter - } -} - -local function get_formatter_name(formatter) - if formatter == prettier_formatter then return "prettier" end - return nil -end - -local function get_formatter_name_list(formatters) - local result = {} - for _, formatter in ipairs(formatters) do - table.insert(result, get_formatter_name(formatter)) - end - return result -end - -local function setup_formatter() - require("formatter").setup { - filetype = formatters_for_filetype - } -end - - -local function get_custom_formatters(bufnr) - local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") - for ft, formatters in pairs(formatters_for_filetype) do - if filetype == ft then - return true, get_formatter_name_list(formatters) - end - end - return false, {} -end - -local function run_formatter(opt) - if not opt then - opt = {} - end - - if not opt.buf then - opt.buf = 0 - end - - local has_custom_formatter, formatter_names = get_custom_formatters(opt.buf) - - local formatter_name_str = "" - for i, name in ipairs(formatter_names) do - if i == 1 then - formatter_name_str = name - else - formatter_name_str = formatter_name_str .. " " .. name - end - end - - if has_custom_formatter then - print("Use custom formatters: " .. formatter_name_str .. ".") - vim.cmd("Format") - return - end - - local has_lsp = vim.lsp.get_active_clients({ bufnr = 0 }) - if has_lsp then - print("Use lsp formatter.") - vim.lsp.buf.format { async = true } - return - end - - vim.notify("No formatters found.", vim.log.levels.ERROR); -end - -return { - setup_formatter = setup_formatter, - run_formatter = run_formatter -} diff --git a/configs/nvim/lua/crupest/nvim/plugins/gitsign.lua b/configs/nvim/lua/crupest/nvim/plugins/gitsign.lua new file mode 100644 index 0000000..220c91a --- /dev/null +++ b/configs/nvim/lua/crupest/nvim/plugins/gitsign.lua @@ -0,0 +1,51 @@ +local function setup() + local gitsigns = require('gitsigns') + gitsigns.setup { + on_attach = function(bufnr) + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then + vim.cmd.normal({ ']c', bang = true }) + else + gitsigns.nav_hunk('next') + end + end) + + map('n', '[c', function() + if vim.wo.diff then + vim.cmd.normal({ '[c', bang = true }) + else + gitsigns.nav_hunk('prev') + end + end) + + -- Actions + map('n', '<leader>hs', gitsigns.stage_hunk) + map('n', '<leader>hr', gitsigns.reset_hunk) + map('v', '<leader>hs', function() gitsigns.stage_hunk { vim.fn.line('.'), vim.fn.line('v') } end) + map('v', '<leader>hr', function() gitsigns.reset_hunk { vim.fn.line('.'), vim.fn.line('v') } end) + map('n', '<leader>hS', gitsigns.stage_buffer) + map('n', '<leader>hu', gitsigns.undo_stage_hunk) + map('n', '<leader>hR', gitsigns.reset_buffer) + map('n', '<leader>hp', gitsigns.preview_hunk) + map('n', '<leader>hb', function() gitsigns.blame_line { full = true } end) + map('n', '<leader>tb', gitsigns.toggle_current_line_blame) + map('n', '<leader>hd', gitsigns.diffthis) + map('n', '<leader>hD', function() gitsigns.diffthis('~') end) + map('n', '<leader>td', gitsigns.toggle_deleted) + + -- Text object + map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>') + end + } +end + +return { + setup = setup +} diff --git a/configs/nvim/lua/crupest/nvim/plugins/init.lua b/configs/nvim/lua/crupest/nvim/plugins/init.lua new file mode 100644 index 0000000..637c8e5 --- /dev/null +++ b/configs/nvim/lua/crupest/nvim/plugins/init.lua @@ -0,0 +1,11 @@ +local function setup() + require("crupest.nvim.plugins.lint").setup() + require("crupest.nvim.plugins.snip").setup() + require("crupest.nvim.plugins.cmp").setup() + require("crupest.nvim.plugins.telescope").setup() + require("crupest.nvim.plugins.gitsign").setup() +end + +return { + setup = setup +} diff --git a/configs/nvim/lua/crupest/nvim/plugins/lint.lua b/configs/nvim/lua/crupest/nvim/plugins/lint.lua index 2ba3e36..6649e74 100644 --- a/configs/nvim/lua/crupest/nvim/plugins/lint.lua +++ b/configs/nvim/lua/crupest/nvim/plugins/lint.lua @@ -1,23 +1,30 @@ local lint = require("lint") -local find = require('crupest.system.find') -local constants = require("crupest.constants") +local find = require('crupest.utils.find') +local is_win = vim.fn.has("win32") ~= 0 +local cspell_config_patterns = { + ".cspell.json", + "cspell.json", + ".cSpell.json", + "cSpell.json", + "cspell.config.js", + "cspell.config.cjs", + "cspell.config.json", + "cspell.config.yaml", + "cspell.config.yml", + "cspell.yaml", + "cspell.yml", +} local my_linters = { { name = "cspell", exe_places = { "npm", "global" }, - config_files = constants.config_patterns.cspell, - }, - { - name = "eslint", - exe_places = { "npm" }, - filetypes = constants.filetype_collections.js_ts, - config_files = constants.config_patterns.nodejs, + config_files = cspell_config_patterns, }, } -local function run_lint(opt) +local function run(opt) if not opt then opt = {} end @@ -44,8 +51,8 @@ local function run_lint(opt) lint.try_lint(linter_names) end -local function setup_lint() - if require('crupest.system').is_win then +local function setup() + if is_win then for _, l in ipairs(my_linters) do local name = l.name local linter = require('lint.linters.' .. name) @@ -59,14 +66,16 @@ local function setup_lint() vim.api.nvim_create_autocmd({ "BufWritePost" }, { callback = function(opt) - run_lint({ + run({ buf = opt.buffer }) end, }) + + vim.keymap.set('n', '<leader>lr', run) end return { - setup_lint = setup_lint, - run_lint = run_lint + setup = setup, + run = run } diff --git a/configs/nvim/lua/crupest/nvim/plugins/others.lua b/configs/nvim/lua/crupest/nvim/plugins/others.lua new file mode 100644 index 0000000..2d728ae --- /dev/null +++ b/configs/nvim/lua/crupest/nvim/plugins/others.lua @@ -0,0 +1,20 @@ +local function setup() + require("neo-tree").setup { + filesystem = { + filtered_items = { + hide_dotfiles = false, + hide_gitignored = false, + hide_hidden = false, -- only works on Windows for hidden files/directories + }, + use_libuv_file_watcher = true + } + } + + require('lualine').setup {} + + require("nvim-autopairs").setup {} +end + +return { + setup = setup +} diff --git a/configs/nvim/lua/crupest/nvim/plugins/snip.lua b/configs/nvim/lua/crupest/nvim/plugins/snip.lua index 1cf1b7c..1cf9800 100644 --- a/configs/nvim/lua/crupest/nvim/plugins/snip.lua +++ b/configs/nvim/lua/crupest/nvim/plugins/snip.lua @@ -26,7 +26,7 @@ local function copy(args) return args[1] end -local function setup_snip() +local function setup() vim.keymap.set({ "i", "s" }, "<C-L>", function() luasnip.jump(1) end, { silent = true }) vim.keymap.set({ "i", "s" }, "<C-J>", function() luasnip.jump(-1) end, { silent = true }) @@ -69,6 +69,5 @@ local function setup_snip() end return { - setup_snip = setup_snip, - luasnip = luasnip + setup = setup, } diff --git a/configs/nvim/lua/crupest/nvim/plugins/telescope.lua b/configs/nvim/lua/crupest/nvim/plugins/telescope.lua new file mode 100644 index 0000000..d68b7f2 --- /dev/null +++ b/configs/nvim/lua/crupest/nvim/plugins/telescope.lua @@ -0,0 +1,11 @@ +local function setup() + local builtin = require('telescope.builtin') + vim.keymap.set('n', '<leader>ff', builtin.find_files, {}) + vim.keymap.set('n', '<leader>fg', builtin.live_grep, {}) + vim.keymap.set('n', '<leader>fb', builtin.buffers, {}) + vim.keymap.set('n', '<leader>fh', builtin.help_tags, {}) +end + +return { + setup = setup +} |