From d7c4fd7813c2a4ea54e0cf1dbd5c2e4e46e52146 Mon Sep 17 00:00:00 2001 From: fiplox Date: Sun, 1 Jan 2023 17:04:23 +0100 Subject: [PATCH] mv plugins to lua --- lua/config/plugins/lsp/handlers.lua | 106 --------------- lua/config/plugins/mini.lua | 127 ------------------ lua/plugins/Comment.lua | 64 +++++++++ lua/{config => }/plugins/autopairs.lua | 0 lua/{config => }/plugins/cmp.lua | 40 +----- lua/{config => }/plugins/colorizer.lua | 0 lua/{config => }/plugins/feline.lua | 0 lua/{config => }/plugins/init.lua | 7 +- lua/{config => }/plugins/lsp/init.lua | 6 +- .../plugins/lsp/settings/sumneko_lua.lua | 0 lua/{config => }/plugins/mason.lua | 3 +- lua/plugins/mini.bak | 127 ++++++++++++++++++ lua/{config => }/plugins/null-ls.lua | 0 lua/{config => }/plugins/telescope.lua | 0 lua/{config => }/plugins/theme.lua | 0 lua/{config => }/plugins/toggleterm.lua | 0 lua/{config => }/plugins/tresitter.lua | 12 +- lua/{config => }/plugins/trouble.lua | 0 lua/{config => }/plugins/which-key.lua | 0 19 files changed, 213 insertions(+), 279 deletions(-) delete mode 100644 lua/config/plugins/lsp/handlers.lua delete mode 100644 lua/config/plugins/mini.lua create mode 100644 lua/plugins/Comment.lua rename lua/{config => }/plugins/autopairs.lua (100%) rename lua/{config => }/plugins/cmp.lua (81%) rename lua/{config => }/plugins/colorizer.lua (100%) rename lua/{config => }/plugins/feline.lua (100%) rename lua/{config => }/plugins/init.lua (79%) rename lua/{config => }/plugins/lsp/init.lua (97%) rename lua/{config => }/plugins/lsp/settings/sumneko_lua.lua (100%) rename lua/{config => }/plugins/mason.lua (96%) create mode 100644 lua/plugins/mini.bak rename lua/{config => }/plugins/null-ls.lua (100%) rename lua/{config => }/plugins/telescope.lua (100%) rename lua/{config => }/plugins/theme.lua (100%) rename lua/{config => }/plugins/toggleterm.lua (100%) rename lua/{config => }/plugins/tresitter.lua (79%) rename lua/{config => }/plugins/trouble.lua (100%) rename lua/{config => }/plugins/which-key.lua (100%) diff --git a/lua/config/plugins/lsp/handlers.lua b/lua/config/plugins/lsp/handlers.lua deleted file mode 100644 index f75612a..0000000 --- a/lua/config/plugins/lsp/handlers.lua +++ /dev/null @@ -1,106 +0,0 @@ -local M = {} - -local cmp_nvim_lsp = require 'cmp_nvim_lsp' - -M.capabilities = vim.lsp.protocol.make_client_capabilities() -M.capabilities.textDocument.completion.completionItem.snippetSupport = true --- M.capabilities.offsetEncoding = { "utf-16" } -M.capabilities = cmp_nvim_lsp.default_capabilities(M.capabilities) - --- vim.cmd [[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false, scope="cursor"})]] - -M.setup = function() - local config = { - virtual_text = true, - signs = false, - underline = true, - update_in_insert = true, - severity_sort = true, - float = { - focusable = true, - style = 'minimal', - border = 'rounded', - source = 'always', - header = '', - prefix = '', - }, - } - vim.diagnostic.config(config) - - vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { - border = 'rounded', - }) - - vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { - border = 'rounded', - }) - - --[[ local on_references = vim.lsp.handlers['textDocument/references'] ]] - --[[ vim.lsp.handlers['textDocument/references'] = vim.lsp.with(on_references, { ]] - --[[ -- Use location list instead of quickfix list ]] - --[[ loclist = true, ]] - --[[ }) ]] -end - -local function lsp_keymaps(bufnr) - local opts = { noremap = true, silent = true } - local keymap = vim.api.nvim_buf_set_keymap - keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) - keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) - keymap(bufnr, 'n', 'gI', 'lua vim.lsp.buf.implementation()', opts) - keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) - keymap(bufnr, 'n', 'gl', 'lua vim.diagnostic.open_float()', opts) - keymap(bufnr, 'n', 'lf', 'lua vim.lsp.buf.format { async = true }', opts) - keymap(bufnr, 'n', 'li', 'LspInfo', opts) - keymap(bufnr, 'n', 'lI', 'LspInstallInfo', opts) - keymap(bufnr, 'n', 'la', 'lua vim.lsp.buf.code_action()', opts) - keymap(bufnr, 'n', 'lj', 'lua vim.diagnostic.goto_next({buffer=0})', opts) - keymap(bufnr, 'n', 'lk', 'lua vim.diagnostic.goto_prev({buffer=0})', opts) - keymap(bufnr, 'n', 'lr', 'lua vim.lsp.buf.rename()', opts) - keymap(bufnr, 'n', 'ls', 'lua vim.lsp.buf.signature_help()', opts) - keymap(bufnr, 'n', 'lq', 'lua vim.diagnostic.setloclist()', opts) - keymap(bufnr, 'n', 'e', 'lua vim.diagnostic.open_float()', opts) -end - -M.on_attach = function(client, bufnr) - --[[ vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') ]] - lsp_keymaps(bufnr) - if client.name == 'sumneko_lua' then - client.server_capabilities.documentFormattingProvider = false - end - if client.name == 'clangd' then - client.server_capabilities.documentFormattingProvider = false - end - if client.name == 'gopls' then - client.server_capabilities.documentFormattingProvider = false - end - if client.name == 'jdtls' then - client.server_capabilities.documentFormattingProvider = false - end - if client.name == 'jdt.ls' then - client.server_capabilities.documentFormattingProvider = false - vim.lsp.codelens.refresh() - if JAVA_DAP_ACTIVE then - require('jdtls').setup_dap { hotcodereplace = 'auto' } - require('jdtls.dap').setup_dap_main_class_configs() - end - end - local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype') - local nls = require 'config.plugins.null-ls' - - local enable = false - if nls.has_formatter(ft) then - enable = client.name == 'null-ls' - else - enable = not (client.name == 'null-ls') - end - - if client.name == 'tsserver' then - enable = false - end - -- util.info(client.name .. " " .. (enable and "yes" or "no"), "format") - client.server_capabilities.documentFormattingProvider = enable -end - -return M diff --git a/lua/config/plugins/mini.lua b/lua/config/plugins/mini.lua deleted file mode 100644 index 897b439..0000000 --- a/lua/config/plugins/mini.lua +++ /dev/null @@ -1,127 +0,0 @@ -local mini = { - 'echasnovski/mini.nvim', - event = 'VeryLazy', -} - -local specs = { mini, 'JoosepAlviste/nvim-ts-context-commentstring' } - -function mini.surround() - require('mini.surround').setup { - mappings = { - add = 'gza', -- Add surrounding in Normal and Visual modes - delete = 'gzd', -- Delete surrounding - find = 'gzf', -- Find surrounding (to the right) - find_left = 'gzF', -- Find surrounding (to the left) - highlight = 'gzh', -- Highlight surrounding - replace = 'gzr', -- Replace surrounding - update_n_lines = 'gzn', -- Update `n_lines` - }, - } -end - -function mini.jump() - require('mini.jump').setup {} -end - -function mini.pairs() - require('mini.pairs').setup {} -end - -function mini.comment() - require('mini.comment').setup { - hooks = { - pre = function() - require('ts_context_commentstring.internal').update_commentstring {} - end, - }, - } -end - -function mini.ai() - local ai = require 'mini.ai' - require('mini.ai').setup { - n_lines = 500, - -- search_method = "cover_or_next", - custom_textobjects = { - o = ai.gen_spec.treesitter({ - a = { '@block.outer', '@conditional.outer', '@loop.outer' }, - i = { '@block.inner', '@conditional.inner', '@loop.inner' }, - }, {}), - f = ai.gen_spec.treesitter({ a = '@function.outer', i = '@function.inner' }, {}), - c = ai.gen_spec.treesitter({ a = '@class.outer', i = '@class.inner' }, {}), - }, - } - - local map = function(text_obj, desc) - for _, side in ipairs { 'left', 'right' } do - for dir, d in pairs { prev = '[', next = ']' } do - local lhs = d .. (side == 'right' and text_obj:upper() or text_obj:lower()) - for _, mode in ipairs { 'n', 'x', 'o' } do - vim.keymap.set(mode, lhs, function() - ai.move_cursor(side, 'a', text_obj, { search_method = dir }) - end, { - desc = dir .. ' ' .. desc, - }) - end - end - end - end - - map('f', 'function') - map('c', 'class') - map('o', 'block') -end - -function mini.config() - -- M.jump() - mini.surround() - -- mini.ai() - -- mini.pairs() - mini.comment() - mini.jump() - -- mini.animate() -end - -function mini.animate() - local mouse_scrolled = false - for _, scroll in ipairs { 'Up', 'Down' } do - local key = '' - vim.keymap.set('', key, function() - mouse_scrolled = true - return key - end, { remap = true, expr = true }) - end - - local animate = require 'mini.animate' - vim.go.winwidth = 20 - vim.go.winminwidth = 5 - - animate.setup { - resize = { - timing = animate.gen_timing.linear { duration = 50, unit = 'total' }, - }, - scroll = { - timing = animate.gen_timing.linear { duration = 100, unit = 'total' }, - subscroll = animate.gen_subscroll.equal { - predicate = function(total_scroll) - if mouse_scrolled then - mouse_scrolled = false - return false - end - return total_scroll > 1 - end, - }, - }, - } -end - -function mini.init() - vim.keymap.set('n', 'bd', function() - require('mini.bufremove').delete(0, false) - end) - vim.keymap.set('n', 'bD', function() - require('mini.bufremove').delete(0, true) - end) -end - -return specs diff --git a/lua/plugins/Comment.lua b/lua/plugins/Comment.lua new file mode 100644 index 0000000..791c7ba --- /dev/null +++ b/lua/plugins/Comment.lua @@ -0,0 +1,64 @@ +local M = { + 'numToStr/Comment.nvim', + event = 'VeryLazy', +} + +function M.config() + local comment = require 'Comment' + + comment.setup { + -- -LHS of operator-pending mappings in NORMAL and VISUAL mode + opleader = { + ---Line-comment keymap + line = 'gc', + ---Block-comment keymap + block = 'gb', + }, + ---LHS of extra mappings + extra = { + ---Add comment on the line above + above = 'gcO', + ---Add comment on the line below + below = 'gco', + ---Add comment at the end of line + eol = 'gca', + }, + ---Enable keybindings + ---NOTE: If given `false` then the plugin won't create any mappings + mappings = { + ---Operator-pending mapping; `gcc` `gbc` `gc[count]{motion}` `gb[count]{motion}` + basic = true, + ---Extra mapping; `gco`, `gcO`, `gcA` + extra = true, + ---Extended mapping; `g>` `g<` `g>[count]{motion}` `g<[count]{motion}` + extended = false, + }, + pre_hook = function(ctx) + -- Only calculate commentstring for tsx filetypes + if vim.bo.filetype == 'typescriptreact' then + local U = require 'Comment.utils' + + -- Determine whether to use linewise or blockwise commentstring + local type = ctx.ctype == U.ctype.linewise and '__default' or '__multiline' + + -- Determine the location where to calculate commentstring from + local location = nil + if ctx.ctype == U.ctype.blockwise then + location = require('ts_context_commentstring.utils').get_cursor_location() + elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then + location = require('ts_context_commentstring.utils').get_visual_start_location() + end + + return require('ts_context_commentstring.internal').calculate_commentstring { + key = type, + location = location, + } + end + end, + } + + local ft = require 'Comment.ft' + ft({ 's', 'asm' }, '# %s') +end + +return M diff --git a/lua/config/plugins/autopairs.lua b/lua/plugins/autopairs.lua similarity index 100% rename from lua/config/plugins/autopairs.lua rename to lua/plugins/autopairs.lua diff --git a/lua/config/plugins/cmp.lua b/lua/plugins/cmp.lua similarity index 81% rename from lua/config/plugins/cmp.lua rename to lua/plugins/cmp.lua index 862c626..01976e4 100644 --- a/lua/config/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -6,6 +6,7 @@ local M = { 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-path', + 'hrsh7th/cmp-calc', }, } @@ -105,14 +106,14 @@ function M.config() end end, { 'i', 's', 'c' }), }, - sources = cmp.config.sources { + sources = { { name = 'nvim_lsp' }, { name = 'snippy' }, { name = 'buffer' }, { name = 'path' }, + { name = 'calc' }, }, } - cmp.setup.cmdline(':', { completion = { autocomplete = true }, mapping = { @@ -136,6 +137,7 @@ function M.config() sources = { { name = 'cmdline' }, { name = 'path' }, + { name = 'calc' }, }, view = { entries = { name = 'wildmenu', separator = ' · ' }, @@ -145,45 +147,13 @@ function M.config() cmp.setup.cmdline('/', { completion = { autocomplete = true }, sources = { - { - name = 'buffer', - }, + { name = 'buffer' }, }, view = { entries = { name = 'wildmenu', separator = ' · ' }, }, }) - local config = { - virtual_text = true, - signs = false, - underline = true, - update_in_insert = true, - severity_sort = true, - float = { - focusable = true, - style = 'minimal', - border = 'rounded', - source = 'always', - header = '', - prefix = '', - }, - } - vim.diagnostic.config(config) - - vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { - border = 'rounded', - }) - - vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { - border = 'rounded', - }) - - --[[ local on_references = vim.lsp.handlers['textDocument/references'] ]] - --[[ vim.lsp.handlers['textDocument/references'] = vim.lsp.with(on_references, { ]] - --[[ -- Use location list instead of quickfix list ]] - --[[ loclist = true, ]] - --[[ }) ]] end return M diff --git a/lua/config/plugins/colorizer.lua b/lua/plugins/colorizer.lua similarity index 100% rename from lua/config/plugins/colorizer.lua rename to lua/plugins/colorizer.lua diff --git a/lua/config/plugins/feline.lua b/lua/plugins/feline.lua similarity index 100% rename from lua/config/plugins/feline.lua rename to lua/plugins/feline.lua diff --git a/lua/config/plugins/init.lua b/lua/plugins/init.lua similarity index 79% rename from lua/config/plugins/init.lua rename to lua/plugins/init.lua index f1664d2..b65c377 100644 --- a/lua/config/plugins/init.lua +++ b/lua/plugins/init.lua @@ -3,7 +3,12 @@ return { { 'honza/vim-snippets', lazy = false }, { 'dcampos/nvim-snippy', lazy = false }, { 'dcampos/cmp-snippy', lazy = false }, - { 'kdheepak/lazygit.nvim', cmd = 'LazyGit' }, + -- { 'kdheepak/lazygit.nvim', cmd = 'LazyGit' }, + { 'is0n/fm-nvim', cmd = { + 'Neomutt', + 'Lazygit', + 'Lf', + } }, 'williamboman/mason-lspconfig.nvim', { 'phaazon/hop.nvim', diff --git a/lua/config/plugins/lsp/init.lua b/lua/plugins/lsp/init.lua similarity index 97% rename from lua/config/plugins/lsp/init.lua rename to lua/plugins/lsp/init.lua index 41293c4..e3aa4c9 100644 --- a/lua/config/plugins/lsp/init.lua +++ b/lua/plugins/lsp/init.lua @@ -12,7 +12,7 @@ M.tools = { } function M.config() - require 'mason' + -- require 'mason' local lspconfig = require 'lspconfig' local opts = {} local cmp_nvim_lsp = require 'cmp_nvim_lsp' @@ -65,7 +65,7 @@ function M.config() end end local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype') - local nls = require 'config.plugins.null-ls' + local nls = require 'plugins.null-ls' local enable = false if nls.has_formatter(ft) then @@ -88,7 +88,7 @@ function M.config() local server = vim.split(tool, '@')[1] if server == 'sumneko_lua' then - local sumneko_opts = require 'config.plugins.lsp.settings.sumneko_lua' + local sumneko_opts = require 'plugins.lsp.settings.sumneko_lua' opts = vim.tbl_deep_extend('force', sumneko_opts, opts) end if server == 'clangd' then diff --git a/lua/config/plugins/lsp/settings/sumneko_lua.lua b/lua/plugins/lsp/settings/sumneko_lua.lua similarity index 100% rename from lua/config/plugins/lsp/settings/sumneko_lua.lua rename to lua/plugins/lsp/settings/sumneko_lua.lua diff --git a/lua/config/plugins/mason.lua b/lua/plugins/mason.lua similarity index 96% rename from lua/config/plugins/mason.lua rename to lua/plugins/mason.lua index 89201ee..c77d1b3 100644 --- a/lua/config/plugins/mason.lua +++ b/lua/plugins/mason.lua @@ -1,5 +1,6 @@ local M = { 'williamboman/mason.nvim', + cmd = 'Mason', } M.tools = { @@ -40,7 +41,7 @@ function M.config() max_concurrent_installers = 4, }, } - M.check() + -- M.check() require('mason-lspconfig').setup { automatic_installation = false, } diff --git a/lua/plugins/mini.bak b/lua/plugins/mini.bak new file mode 100644 index 0000000..8970762 --- /dev/null +++ b/lua/plugins/mini.bak @@ -0,0 +1,127 @@ +local mini = { + 'echasnovski/mini.nvim', + event = 'VeryLazy', +} + +local specs = { mini, 'JoosepAlviste/nvim-ts-context-commentstring' } + +-- function mini.surround() +-- require('mini.surround').setup { +-- mappings = { +-- add = 'gza', -- Add surrounding in Normal and Visual modes +-- delete = 'gzd', -- Delete surrounding +-- find = 'gzf', -- Find surrounding (to the right) +-- find_left = 'gzF', -- Find surrounding (to the left) +-- highlight = 'gzh', -- Highlight surrounding +-- replace = 'gzr', -- Replace surrounding +-- update_n_lines = 'gzn', -- Update `n_lines` +-- }, +-- } +-- end +-- +-- function mini.jump() +-- require('mini.jump').setup {} +-- end +-- +-- function mini.pairs() +-- require('mini.pairs').setup {} +-- end + +function mini.comment() + require('mini.comment').setup { + hooks = { + pre = function() + require('ts_context_commentstring.internal').update_commentstring {} + end, + }, + } +end + +-- function mini.ai() +-- local ai = require 'mini.ai' +-- require('mini.ai').setup { +-- n_lines = 500, +-- -- search_method = "cover_or_next", +-- custom_textobjects = { +-- o = ai.gen_spec.treesitter({ +-- a = { '@block.outer', '@conditional.outer', '@loop.outer' }, +-- i = { '@block.inner', '@conditional.inner', '@loop.inner' }, +-- }, {}), +-- f = ai.gen_spec.treesitter({ a = '@function.outer', i = '@function.inner' }, {}), +-- c = ai.gen_spec.treesitter({ a = '@class.outer', i = '@class.inner' }, {}), +-- }, +-- } +-- +-- local map = function(text_obj, desc) +-- for _, side in ipairs { 'left', 'right' } do +-- for dir, d in pairs { prev = '[', next = ']' } do +-- local lhs = d .. (side == 'right' and text_obj:upper() or text_obj:lower()) +-- for _, mode in ipairs { 'n', 'x', 'o' } do +-- vim.keymap.set(mode, lhs, function() +-- ai.move_cursor(side, 'a', text_obj, { search_method = dir }) +-- end, { +-- desc = dir .. ' ' .. desc, +-- }) +-- end +-- end +-- end +-- end +-- +-- map('f', 'function') +-- map('c', 'class') +-- map('o', 'block') +-- end + +function mini.config() + -- M.jump() + -- mini.surround() + -- mini.ai() + -- mini.pairs() + mini.comment() + -- mini.jump() + -- mini.animate() +end + +-- function mini.animate() +-- local mouse_scrolled = false +-- for _, scroll in ipairs { 'Up', 'Down' } do +-- local key = '' +-- vim.keymap.set('', key, function() +-- mouse_scrolled = true +-- return key +-- end, { remap = true, expr = true }) +-- end +-- +-- local animate = require 'mini.animate' +-- vim.go.winwidth = 20 +-- vim.go.winminwidth = 5 +-- +-- animate.setup { +-- resize = { +-- timing = animate.gen_timing.linear { duration = 50, unit = 'total' }, +-- }, +-- scroll = { +-- timing = animate.gen_timing.linear { duration = 100, unit = 'total' }, +-- subscroll = animate.gen_subscroll.equal { +-- predicate = function(total_scroll) +-- if mouse_scrolled then +-- mouse_scrolled = false +-- return false +-- end +-- return total_scroll > 1 +-- end, +-- }, +-- }, +-- } +-- end + +function mini.init() + vim.keymap.set('n', 'bd', function() + require('mini.bufremove').delete(0, false) + end) + vim.keymap.set('n', 'bD', function() + require('mini.bufremove').delete(0, true) + end) +end + +return specs diff --git a/lua/config/plugins/null-ls.lua b/lua/plugins/null-ls.lua similarity index 100% rename from lua/config/plugins/null-ls.lua rename to lua/plugins/null-ls.lua diff --git a/lua/config/plugins/telescope.lua b/lua/plugins/telescope.lua similarity index 100% rename from lua/config/plugins/telescope.lua rename to lua/plugins/telescope.lua diff --git a/lua/config/plugins/theme.lua b/lua/plugins/theme.lua similarity index 100% rename from lua/config/plugins/theme.lua rename to lua/plugins/theme.lua diff --git a/lua/config/plugins/toggleterm.lua b/lua/plugins/toggleterm.lua similarity index 100% rename from lua/config/plugins/toggleterm.lua rename to lua/plugins/toggleterm.lua diff --git a/lua/config/plugins/tresitter.lua b/lua/plugins/tresitter.lua similarity index 79% rename from lua/config/plugins/tresitter.lua rename to lua/plugins/tresitter.lua index c235897..d19cca4 100644 --- a/lua/config/plugins/tresitter.lua +++ b/lua/plugins/tresitter.lua @@ -36,14 +36,14 @@ function M.config() enable = true, -- false will disable the whole extension disable = { 'html' }, }, - context_commentstring = { enable = true, config = { css = '// %s' } }, + -- context_commentstring = { enable = true, config = { css = '// %s' } }, -- indent = {enable = true, disable = {"python", "html", "javascript"}}, -- TODO seems to be broken - indent = { enable = true, disable = { 'python', 'css' } }, - autotag = { enable = true }, - autopairs = { - enable = true, - }, + indent = { enable = false, disable = { 'python', 'css' } }, + -- autotag = { enable = true }, + -- autopairs = { + -- enable = true, + -- }, } end diff --git a/lua/config/plugins/trouble.lua b/lua/plugins/trouble.lua similarity index 100% rename from lua/config/plugins/trouble.lua rename to lua/plugins/trouble.lua diff --git a/lua/config/plugins/which-key.lua b/lua/plugins/which-key.lua similarity index 100% rename from lua/config/plugins/which-key.lua rename to lua/plugins/which-key.lua