From 69459410098ba58da4650fb4cd5852205a6e08c0 Mon Sep 17 00:00:00 2001 From: FollieHiyuki Date: Thu, 25 Nov 2021 01:42:33 +0700 Subject: [PATCH] nvim: big refactor --- roles/nvim/files/nvim/init.lua | 2 +- roles/nvim/files/nvim/lua/autocmd.lua | 16 +- roles/nvim/files/nvim/lua/mappings.lua | 288 ++++++-- .../{completion.lua => completion/config.lua} | 85 ++- .../nvim/lua/modules/completion/plugins.lua | 35 + .../files/nvim/lua/modules/core/config.lua | 29 + .../nvim/lua/modules/{ => core}/pack.lua | 10 +- .../files/nvim/lua/modules/core/plugins.lua | 10 + .../modules/{editor.lua => editor/config.lua} | 270 +++----- .../files/nvim/lua/modules/editor/plugins.lua | 139 ++++ roles/nvim/files/nvim/lua/modules/lsp.lua | 631 ------------------ .../files/nvim/lua/modules/lsp/config.lua | 258 +++++++ .../files/nvim/lua/modules/lsp/lsp_conf.lua | 240 +++++++ .../nvim/lua/modules/lsp/null_ls_conf.lua | 81 +++ .../files/nvim/lua/modules/lsp/plugins.lua | 57 ++ .../nvim/files/nvim/lua/modules/lsp/util.lua | 218 ++++++ .../modules/{tools.lua => tools/config.lua} | 143 ++-- .../files/nvim/lua/modules/tools/plugins.lua | 107 +++ .../files/nvim/lua/modules/ui/components.lua | 229 +++++++ .../lua/modules/{ui.lua => ui/config.lua} | 336 +++------- .../files/nvim/lua/modules/ui/plugins.lua | 38 ++ roles/nvim/files/nvim/lua/plugins.lua | 496 +------------- .../nvim/files/nvim/lua/themes/nord/init.lua | 14 +- roles/nvim/files/nvim/lua/util.lua | 86 +-- roles/nvim/files/nvim/scripts/lint/autopep8 | 8 - roles/nvim/files/nvim/scripts/lint/black | 8 - roles/nvim/files/nvim/scripts/lint/flake8 | 8 - roles/nvim/files/nvim/scripts/lint/isort | 8 - roles/nvim/files/nvim/scripts/lint/pylint | 8 - roles/nvim/files/nvim/scripts/lint/yapf | 9 - roles/nvim/files/nvim/scripts/lsp/pylsp | 14 + roles/nvim/files/nvim/scripts/lsp/pyright | 12 - roles/nvim/files/nvim/scripts/pylsp | 4 + 33 files changed, 1988 insertions(+), 1909 deletions(-) rename roles/nvim/files/nvim/lua/modules/{completion.lua => completion/config.lua} (85%) create mode 100644 roles/nvim/files/nvim/lua/modules/completion/plugins.lua create mode 100644 roles/nvim/files/nvim/lua/modules/core/config.lua rename roles/nvim/files/nvim/lua/modules/{ => core}/pack.lua (87%) create mode 100644 roles/nvim/files/nvim/lua/modules/core/plugins.lua rename roles/nvim/files/nvim/lua/modules/{editor.lua => editor/config.lua} (72%) create mode 100644 roles/nvim/files/nvim/lua/modules/editor/plugins.lua delete mode 100644 roles/nvim/files/nvim/lua/modules/lsp.lua create mode 100644 roles/nvim/files/nvim/lua/modules/lsp/config.lua create mode 100644 roles/nvim/files/nvim/lua/modules/lsp/lsp_conf.lua create mode 100644 roles/nvim/files/nvim/lua/modules/lsp/null_ls_conf.lua create mode 100644 roles/nvim/files/nvim/lua/modules/lsp/plugins.lua create mode 100644 roles/nvim/files/nvim/lua/modules/lsp/util.lua rename roles/nvim/files/nvim/lua/modules/{tools.lua => tools/config.lua} (65%) create mode 100644 roles/nvim/files/nvim/lua/modules/tools/plugins.lua create mode 100644 roles/nvim/files/nvim/lua/modules/ui/components.lua rename roles/nvim/files/nvim/lua/modules/{ui.lua => ui/config.lua} (60%) create mode 100644 roles/nvim/files/nvim/lua/modules/ui/plugins.lua delete mode 100755 roles/nvim/files/nvim/scripts/lint/autopep8 delete mode 100755 roles/nvim/files/nvim/scripts/lint/black delete mode 100755 roles/nvim/files/nvim/scripts/lint/flake8 delete mode 100755 roles/nvim/files/nvim/scripts/lint/isort delete mode 100755 roles/nvim/files/nvim/scripts/lint/pylint delete mode 100755 roles/nvim/files/nvim/scripts/lint/yapf create mode 100755 roles/nvim/files/nvim/scripts/lsp/pylsp delete mode 100755 roles/nvim/files/nvim/scripts/lsp/pyright create mode 100755 roles/nvim/files/nvim/scripts/pylsp diff --git a/roles/nvim/files/nvim/init.lua b/roles/nvim/files/nvim/init.lua index 678f374..a0a2274 100644 --- a/roles/nvim/files/nvim/init.lua +++ b/roles/nvim/files/nvim/init.lua @@ -7,5 +7,5 @@ require('autocmd').setup() -- packer_compiled.lua exists, so don't need to load this early vim.defer_fn(function() - require('plugins') + require('plugins').load_plugins() end, 0) diff --git a/roles/nvim/files/nvim/lua/autocmd.lua b/roles/nvim/files/nvim/lua/autocmd.lua index 76f1bcc..bc422be 100644 --- a/roles/nvim/files/nvim/lua/autocmd.lua +++ b/roles/nvim/files/nvim/lua/autocmd.lua @@ -13,7 +13,6 @@ local augroups = { {'BufWritePre', '*.tmp', 'setlocal noundofile'}, {'BufWritePre', '*.bak', 'setlocal noundofile'} }, - wins = { -- Equalize window dimensions when resizing vim window {'VimResized', '*', 'tabdo wincmd ='}, @@ -22,26 +21,13 @@ local augroups = { -- Check if file changed when its window is focus, more eager than 'autoread' {'FocusGained', '* checktime'} }, - yank = { {'TextYankPost', [[* silent! lua vim.highlight.on_yank({higroup='IncSearch', timeout=300})]]} } } -local load_autocmd = function(definitions) - for group_name, definition in pairs(definitions) do - vim.api.nvim_command('augroup ' .. group_name) - vim.api.nvim_command('autocmd!') - for _, def in ipairs(definition) do - local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ') - vim.api.nvim_command(command) - end - vim.api.nvim_command('augroup END') - end -end - function M.setup() - load_autocmd(augroups) + require('util').load_autocmd(augroups) end return M diff --git a/roles/nvim/files/nvim/lua/mappings.lua b/roles/nvim/files/nvim/lua/mappings.lua index bff8d10..e5f7091 100644 --- a/roles/nvim/files/nvim/lua/mappings.lua +++ b/roles/nvim/files/nvim/lua/mappings.lua @@ -1,33 +1,30 @@ -local api = vim.api -local wk = require('which-key') local M = {} +local wk = require('which-key') +local api, notify = vim.api, vim.notify +local opts = {noremap = true, silent = true} +------------------------------- +-- Globally defined mappings -- +------------------------------- local normal_mappings = { -- Better Y Y = {'y$', 'Yank to eol'}, - -- Easier start and end of line H = {'^', 'Start of the line'}, L = {'$', 'End of the line'}, - -- Close a window [''] = {'q', 'Quit current window'}, - -- Close current buffer [''] = {':bdelete', 'Close current buffer'}, - -- Copy the whole buffer [''] = {':%y+', 'Copy whole buffer'}, - -- Remove trailing whitespace [''] = {':%s/\\s\\+$//e', 'Remove trailing'}, - -- Resize buffer [''] = {':resize -2', 'Resize vertical -2'}, [''] = {':resize +2', 'Resize vertical +2'}, [''] = {':vertical resize -2', 'Resize horizontal -2'}, [''] = {':vertical resize +2', 'Resize horizontal +2'}, - -- Switch between tabs and spaces [''] = { function() @@ -35,17 +32,16 @@ local normal_mappings = { vim.opt.expandtab = false vim.opt.smarttab = false vim.opt.softtabstop = 0 -- reset to default - vim.notify('Indent with Tabs.', vim.log.levels.INFO) + notify('Indent with Tabs.', vim.log.levels.INFO) else vim.opt.expandtab = true vim.opt.smarttab = true vim.opt.softtabstop = -1 -- fallback to shiftwidth - vim.notify('Indent with Spaces.', vim.log.levels.INFO) + notify('Indent with Spaces.', vim.log.levels.INFO) end end, 'Switch indent style' }, - -- Naming common keys ['['] = { name = 'Block motions (previous)', @@ -60,15 +56,12 @@ local normal_mappings = { t = {':TodoTrouble', 'Todo list'} }, z = {name = 'Misc utils'}, - -- Move between tabs [''] = {':BufferLineCycleNext', 'Next buffer'}, [''] = {':BufferLineCyclePrev', 'Previous buffer'}, - -- ToggleTerm [''] = {':ToggleTerm', 'Toggle terminal'}, [''] = {':ToggleTerm direction=float', 'Toggle float terminal'}, - -- hop.nvim S = {':HopWord', 'Hop to word'}, [''] = {':HopChar1', 'Hop to character'}, @@ -93,7 +86,6 @@ local normal_leader_mappings = { v = 'Run again 1 step', z = 'Re-run the last adapter' }, - e = { name = 'Editor', a = {':EasyAlign', 'Align elements'}, @@ -106,24 +98,24 @@ local normal_leader_mappings = { local venn_enabled = vim.inspect(vim.b.venn_enabled) if venn_enabled == 'nil' then vim.b.venn_enabled = true - vim.api.nvim_command('setlocal virtualedit=all') + api.nvim_command('setlocal virtualedit=all') -- Draw lines with WASD keystroke - vim.api.nvim_buf_set_keymap(0, 'n', 'A', 'h:VBox', {noremap = true, silent = true}) - vim.api.nvim_buf_set_keymap(0, 'n', 'S', 'j:VBox', {noremap = true, silent = true}) - vim.api.nvim_buf_set_keymap(0, 'n', 'W', 'k:VBox', {noremap = true, silent = true}) - vim.api.nvim_buf_set_keymap(0, 'n', 'D', 'l:VBox', {noremap = true, silent = true}) + api.nvim_buf_set_keymap(0, 'n', 'A', 'h:VBox', opts) + api.nvim_buf_set_keymap(0, 'n', 'S', 'j:VBox', opts) + api.nvim_buf_set_keymap(0, 'n', 'W', 'k:VBox', opts) + api.nvim_buf_set_keymap(0, 'n', 'D', 'l:VBox', opts) -- Draw boxes by pressing 'f' with visual selection - vim.api.nvim_buf_set_keymap(0, 'v', 'f', ':VBox', {noremap = true, silent = true}) - vim.notify('Virtual box edit enabled.', vim.log.levels.INFO) + api.nvim_buf_set_keymap(0, 'v', 'f', ':VBox', opts) + notify('Virtual box edit enabled.', vim.log.levels.INFO) else vim.b.venn_enabled = nil - vim.api.nvim_command('setlocal virtualedit=block') - vim.api.nvim_buf_del_keymap(0, 'v', 'f') - vim.api.nvim_buf_del_keymap(0, 'n', 'A') - vim.api.nvim_buf_del_keymap(0, 'n', 'S') - vim.api.nvim_buf_del_keymap(0, 'n', 'W') - vim.api.nvim_buf_del_keymap(0, 'n', 'D') - vim.notify('Virtual box edit disabled.', vim.log.levels.INFO) + api.nvim_command('setlocal virtualedit=block') + api.nvim_buf_del_keymap(0, 'v', 'f') + api.nvim_buf_del_keymap(0, 'n', 'A') + api.nvim_buf_del_keymap(0, 'n', 'S') + api.nvim_buf_del_keymap(0, 'n', 'W') + api.nvim_buf_del_keymap(0, 'n', 'D') + notify('Virtual box edit disabled.', vim.log.levels.INFO) end end, 'Toggle virtual box edit' @@ -131,8 +123,6 @@ local normal_leader_mappings = { z = {':ZenMode', 'Zen mode'}, Z = {':Twilight', 'Twilight mode'} }, - - -- Telescope f = { name = 'Telescope', a = {':Telescope autocommands', 'Autocommands'}, @@ -176,8 +166,6 @@ local normal_leader_mappings = { y = {':Telescope filetypes', 'Filetypes'}, z = {':Telescope registers', 'Vim registers'} }, - - -- Git g = { name = 'Git', a = {':Telescope git_stash', 'Stash'}, @@ -197,8 +185,6 @@ local normal_leader_mappings = { y = 'Get remote url for cursorline', Y = 'Get remote url' }, - - -- translate-shell.vim j = { name = 'Translate', t = {':Trans', 'Translate'}, @@ -206,24 +192,19 @@ local normal_leader_mappings = { r = {'cw=system(\'trans -brief -no-ansi\', getreg(""))[:-2]', 'Translate and replace'}, c = {'cw=system(\'trans -brief -no-ansi :\', getreg(""))[:-2]', 'Translate and replace with direction'} }, - - -- NvimTree n = {':NvimTreeToggle', 'NvimTree'}, - p = { name = 'Find/Replace', o = 'Open spectre', p = 'Search in current file', w = 'Find/Replace cursorword' }, - r = { name = 'REST', c = {'RestNvim', 'Run request under cursor'}, p = {'RestNvimPreview', 'Preview request cURL command'}, l = {'RestNvimLast', 'Re-run last request'} }, - s = { name = 'Session', s = 'Save session for current directory', @@ -231,9 +212,7 @@ local normal_leader_mappings = { l = 'Load last session', r = 'Load session for current directory' }, - w = {':WindowPick', 'Pick window'} - } local visual_leader_mappings = { @@ -241,19 +220,16 @@ local visual_leader_mappings = { name = 'Editor', a = {':EasyAlign', 'Range align'} }, - d = { name = 'DAP', e = 'Hover on range (UI)' }, - g = { name = 'Git', r = 'Reset hunk', s = 'Stage hunk', y = 'Get remote url for range' }, - j = { name = 'Translate', t = {':Trans', 'Translate'}, @@ -261,14 +237,13 @@ local visual_leader_mappings = { r = {'c=system(\'trans -brief -no-ansi\', getreg(""))[:-2]', 'Translate and replace'}, c = {'c=system(\'trans -brief -no-ansi :\', getreg(""))[:-2]', 'Translate and replace with direction'} }, - p = 'Find/Replace' } -local localleader_mappings = function() - vim.api.nvim_command('autocmd BufEnter * lua WhichkeyLocal()') +local function localleader_mappings() + api.nvim_command('autocmd BufEnter * lua WhichkeyLocal()') function WhichkeyLocal() - local bufnr = vim.api.nvim_get_current_buf() + local bufnr = api.nvim_get_current_buf() wk.register({ c = {':ColorizerToggle', 'Colorizer'}, d = { @@ -286,40 +261,37 @@ local localleader_mappings = function() }, {buffer = bufnr, prefix = ''}) end - vim.api.nvim_command('autocmd FileType markdown lua WhichkeyMarkdown()') + api.nvim_command('autocmd FileType markdown lua WhichkeyMarkdown()') function WhichkeyMarkdown() wk.register({ p = {':MarkdownPreviewToggle', 'Preview markdown'} - }, {buffer = vim.api.nvim_get_current_buf(), prefix = ''}) + }, {buffer = api.nvim_get_current_buf(), prefix = ''}) end - vim.api.nvim_command('autocmd FileType html lua WhichkeyHtml()') + api.nvim_command('autocmd FileType html lua WhichkeyHtml()') function WhichkeyHtml() wk.register({ p = {':Bracey', 'Preview html'} - }, {buffer = vim.api.nvim_get_current_buf(), prefix = ''}) + }, {buffer = api.nvim_get_current_buf(), prefix = ''}) end end -local undefined_mappings = function() +local function undefined_mappings() -- Escape to normal mode in terminal buffer - api.nvim_set_keymap('t', '', '', {noremap = true, silent = true}) - + api.nvim_set_keymap('t', '', '', opts) -- Continuous indent - api.nvim_set_keymap('v', '<', '', '>gv', {noremap = true, silent = true}) - + api.nvim_set_keymap('v', '<', '', '>gv', opts) -- Also move up/down virtual lines (:set wrap) - api.nvim_set_keymap('n', 'j', 'gj', {noremap = true, silent = true}) - api.nvim_set_keymap('n', 'k', 'gk', {noremap = true, silent = true}) - + api.nvim_set_keymap('n', 'j', 'gj', opts) + api.nvim_set_keymap('n', 'k', 'gk', opts) -- winshift.nvim - api.nvim_set_keymap('n', '', ':WinShift', {noremap = true, silent = true}) - api.nvim_set_keymap('n', 'm', ':WinShift', {noremap = true, silent = true}) - api.nvim_set_keymap('n', '', ':WinShift left', {noremap = true, silent = true}) - api.nvim_set_keymap('n', '', ':WinShift down', {noremap = true, silent = true}) - api.nvim_set_keymap('n', '', ':WinShift up', {noremap = true, silent = true}) - api.nvim_set_keymap('n', '', ':WinShift right', {noremap = true, silent = true}) + api.nvim_set_keymap('n', '', ':WinShift', opts) + api.nvim_set_keymap('n', 'm', ':WinShift', opts) + api.nvim_set_keymap('n', '', ':WinShift left', opts) + api.nvim_set_keymap('n', '', ':WinShift down', opts) + api.nvim_set_keymap('n', '', ':WinShift up', opts) + api.nvim_set_keymap('n', '', ':WinShift right', opts) end function M.setup() @@ -330,4 +302,182 @@ function M.setup() wk.register(visual_leader_mappings, {mode = 'v', prefix = ''}) end +----------------------- +-- Plugins' mappings -- +----------------------- +function M.orgmode() + api.nvim_command('autocmd FileType org lua WhichkeyOrg()') + function WhichkeyOrg() + wk.register({ + ['o'] = { + name = 'Org', + a = 'Agenda', + A = 'Toggle ARCHIVE', + c = 'Capture', + e = 'Export', + i = { + name = 'Insert', + h = 'Add headline', + t = 'Add TODO heading and content', + T = 'Add TODO heading' + }, + J = 'Move subtree down', + K = 'Move subtree up', + o = 'Open at point', + r = 'Refile', + t = 'Set tags', + ['$'] = 'Archive current headline' + }, + [''] = 'Org meta return', + [''] = 'Org increase date', + [''] = 'Org decrease date', + ['cid'] = 'Org change date', + ['cit'] = 'Org TODO', + ['ciT'] = 'Org TODO prev', + [''] = 'Org toggle checkbox', + [''] = 'Org cycle folding', + [''] = 'Org cycle global folding', + ['<<'] = 'Org promote headline', + ['>>'] = 'Org demote headline', + ['s'] = 'Org demote subtree', + ['}'] = 'Org next visible heading', + ['{'] = 'Org previous visible heading', + [']]'] = 'Org forward heading', + ['[['] = 'Org backward heading', + ['g{'] = 'Org parent heading', + ['?'] = 'Org help' + }, {buffer = api.nvim_get_current_buf()}) + end +end + +function M.treesitter() + local mappings = { + ['['] = { + m = 'Previous start of outer class', + M = 'Previous end of outer class', + ['['] = 'Previous start of outer function', + [']'] = 'Previous end of outer function' + }, + [']'] = { + m = 'Next start of outer class', + M = 'Next end of outer class', + ['['] = 'Next start of outer function', + [']'] = 'Next end of outer function' + }, + g = { + n = { + name = 'Treesitter', + d = 'Goto definition', + D = 'List definitions', + i = 'Initialize selection', + j = 'Goto previous usage', + k = 'Goto next usage', + o = 'List definitions TOC', + r = 'Rename within scope' + } + } + } + local visual_mappings = { + a = { + c = 'Outer class', + f = 'Outer function' + }, + i = { + c = 'Inner class', + f = 'Inner function' + }, + g = { + n = { + name = 'Treesitter', + n = 'Increment node', + s = 'Increment scope', + m = 'Decrement node' + } + } + } + + wk.register(mappings) + wk.register(visual_mappings, {mode = 'v'}) +end + +function M.eft() + api.nvim_set_keymap('n', 'f', '(eft-f)', {silent = true}) + api.nvim_set_keymap('x', 'f', '(eft-f)', {silent = true}) + api.nvim_set_keymap('n', 'F', '(eft-F)', {silent = true}) + api.nvim_set_keymap('x', 'F', '(eft-F)', {silent = true}) + api.nvim_set_keymap('n', 't', '(eft-t)', {silent = true}) + api.nvim_set_keymap('x', 't', '(eft-t)', {silent = true}) + api.nvim_set_keymap('n', 'T', '(eft-T)', {silent = true}) + api.nvim_set_keymap('x', 'T', '(eft-T)', {silent = true}) + api.nvim_set_keymap('n', ';', '(eft-repeat)', {silent = true}) + api.nvim_set_keymap('x', ';', '(eft-repeat)', {silent = true}) +end + +function M.dial() + api.nvim_set_keymap('n', '', '(dial-increment)', {silent = true}) + api.nvim_set_keymap('v', '', '(dial-increment)', {silent = true}) + api.nvim_set_keymap('n', '', '(dial-decrement)', {silent = true}) + api.nvim_set_keymap('v', '', '(dial-decrement)', {silent = true}) + api.nvim_set_keymap('v', 'g', '(dial-increment-additional)', {silent = true}) + api.nvim_set_keymap('v', 'g', '(dial-decrement-additional)', {silent = true}) +end + +function M.neogen() + api.nvim_set_keymap('n', 'eg', ':lua require("neogen").generate()', opts) + api.nvim_set_keymap('n', '', ':lua require("neogen").jump_next()', opts) +end + +function M.gitlinker() + api.nvim_set_keymap('n', 'gY', ':lua require("gitlinker").get_repo_url()', opts) +end + +function M.dap() + api.nvim_set_keymap('n', 'dn', ':lua require("dap").continue()', opts) + api.nvim_set_keymap('n', 'dd', ':lua require("dap").disconnect()', opts) + api.nvim_set_keymap('n', 'db', ':lua require("dap").toggle_breakpoint()', opts) + api.nvim_set_keymap('n', 'dB', ':lua require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: "))', opts) + api.nvim_set_keymap('n', 'dl', ':lua require("dap").list_breakpoints()', opts) + api.nvim_set_keymap('n', 'dc', ':lua require("dap").run_to_cursor()', opts) + api.nvim_set_keymap('n', 'dz', ':lua require("dap").run_last()', opts) + api.nvim_set_keymap('n', '', ':lua require("dap").step_over()', opts) + api.nvim_set_keymap('n', 'dv', ':lua require("dap").step_over()', opts) + api.nvim_set_keymap('n', '', ':lua require("dap").step_into()', opts) + api.nvim_set_keymap('n', 'di', ':lua require("dap").step_into()', opts) + api.nvim_set_keymap('n', '', ':lua require("dap").step_out()', opts) + api.nvim_set_keymap('n', 'do', ':lua require("dap").step_out()', opts) + api.nvim_set_keymap('n', 'dr', ':lua require("dap").repl.open()', opts) +end + +function M.dapui() + api.nvim_set_keymap('n', 'de', ':lua require("dapui").eval()', opts) + api.nvim_set_keymap('v', 'de', ':lua require("dapui").eval()', opts) + api.nvim_set_keymap('n', 'df', ':lua require("dapui").float_element()', opts) + api.nvim_set_keymap('n', 'dt', ':lua require("dapui").toggle()', opts) +end + +function M.telescope_symbols() + api.nvim_set_keymap('n', 'fjg', ':lua require("telescope.builtin").symbols{sources = {"gitmoji"}, prompt_title = "Gitmoji"}', opts) + api.nvim_set_keymap('n', 'fjj', ':lua require("telescope.builtin").symbols{sources = {"emoji"}, prompt_title = "Emoji"}', opts) + api.nvim_set_keymap('n', 'fjk', ':lua require("telescope.builtin").symbols{sources = {"kaomoji"}, prompt_title = "Kaomoji"}', opts) + api.nvim_set_keymap('n', 'fjl', ':lua require("telescope.builtin").symbols{sources = {"julia"}, prompt_title = "Julia symbols"}', opts) + api.nvim_set_keymap('n', 'fjm', ':lua require("telescope.builtin").symbols{sources = {"math"}, prompt_title = "Math symbols"}', opts) + api.nvim_set_keymap('n', 'fjn', ':lua require("telescope.builtin").symbols{sources = {"nerd"}, prompt_title = "Nerd-fonts symbols"}', opts) + api.nvim_set_keymap('n', 'fjt', ':lua require("telescope.builtin").symbols{sources = {"latex"}, prompt_title = "Latex symbols"}', opts) +end + +function M.spectre() + api.nvim_set_keymap('n', 'po', ':lua require("spectre").open()', opts) + api.nvim_set_keymap('n', 'pp', 'viw:lua require("spectre").open_file_search()', opts) + api.nvim_set_keymap('n', 'pw', ':lua require("spectre").open_visual({select_word = true})', opts) + api.nvim_set_keymap('v', 'p', ':lua require("spectre").open_visual()', opts) +end + +function M.persistence() + api.nvim_set_keymap('n', 'ss', ':lua require("persistence").save()', opts) + api.nvim_set_keymap('n', 'sd', ':lua require("persistence").stop()', opts) + api.nvim_set_keymap('n', 'sl', ':lua require("persistence").load({last = true})', opts) + api.nvim_set_keymap('n', 'sr', ':lua require("persistence").load()', opts) +end + return M diff --git a/roles/nvim/files/nvim/lua/modules/completion.lua b/roles/nvim/files/nvim/lua/modules/completion/config.lua similarity index 85% rename from roles/nvim/files/nvim/lua/modules/completion.lua rename to roles/nvim/files/nvim/lua/modules/completion/config.lua index cdbcc02..8d3f2f4 100644 --- a/roles/nvim/files/nvim/lua/modules/completion.lua +++ b/roles/nvim/files/nvim/lua/modules/completion/config.lua @@ -1,6 +1,26 @@ local M = {} -function M.cmp_conf() +function M.luasnip() + local types = require('luasnip.util.types') + + require('luasnip').config.set_config({ + updateevents = 'TextChanged, TextChangedI', + history = true, + ext_opts = { + [types.choiceNode] = { + active = {virt_text = {{'●', 'LuaSnipChoice'}}} + }, + [types.insertNode] = { + active = {virt_text = {{'●', 'LuaSnipInsert'}}} + } + } + }) + + -- Loading snippets from 'friendly-snippets' + require('luasnip/loaders/from_vscode').load() +end + +function M.cmp() local cmp = require('cmp') local luasnip = require('luasnip') @@ -61,7 +81,7 @@ function M.cmp_conf() orgmode = '[ORG]', -- cmp_tabnine = '[TN]', latex_symbols = '[TEX]', - dictionary = '[DICT]', + -- dictionary = '[DICT]', path = '[PATH]', buffer = '[BUF]', calc = '[CALC]' @@ -74,27 +94,30 @@ function M.cmp_conf() border = { '┌','─', '┐', '│', '┘', '─', '└', '│'} }, mapping = { - [''] = cmp.mapping.confirm({select = true}), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true + }), [''] = cmp.mapping.complete(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Insert}), + [''] = cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Insert}), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.close(), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.close() + else fallback() end + end), -- Change choice nodes for luasnip [''] = cmp.mapping(function(fallback) if luasnip.choice_active() then luasnip.change_choice(-1) - else - fallback() - end + else fallback() end end, {'i', 's'}), [''] = cmp.mapping(function(fallback) if luasnip.choice_active() then luasnip.change_choice(1) - else - fallback() - end + else fallback() end end, {'i', 's'}), -- supertab-like mapping [''] = cmp.mapping(function(fallback) @@ -104,18 +127,14 @@ function M.cmp_conf() luasnip.expand_or_jump() elseif has_words_before() then cmp.complete() - else - fallback() - end + else fallback() end end, {'i', 's'}), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif luasnip.jumpable(-1) then luasnip.jump(-1) - else - fallback() - end + else fallback() end end, {'i', 's'}) }, snippet = { @@ -130,7 +149,7 @@ function M.cmp_conf() {name = 'orgmode'}, -- {name = 'cmp_tabnine'}, {name = 'latex_symbols'}, - {name = 'dictionary', keyword_length = 2}, + -- {name = 'dictionary', keyword_length = 2}, {name = 'path'}, {name = 'buffer'}, {name = 'calc'} @@ -141,7 +160,7 @@ function M.cmp_conf() vim.g.cmp_dictionary_exact = -1 end --- function M.tabnine_conf() +-- function M.tabnine() -- local tabnine = require('cmp_tabnine.config') -- tabnine:setup { -- max_lines = 1000, @@ -151,7 +170,7 @@ end -- } -- end -function M.autopairs_conf() +function M.autopairs() require('nvim-autopairs').setup { disable_filetype = {'TelescopePrompt', 'spectre_panel'}, disable_in_macro = false, -- disable when recording or executing a macro @@ -186,28 +205,4 @@ function M.autopairs_conf() cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) end -function M.snippets_conf() - local types = require('luasnip.util.types') - - require('luasnip').config.set_config({ - updateevents = 'TextChanged, TextChangedI', - history = true, - ext_opts = { - [types.choiceNode] = { - active = { - virt_text = {{'●', 'LuaSnipChoice'}} - } - }, - [types.insertNode] = { - active = { - virt_text = {{'●', 'LuaSnipInsert'}} - } - } - } - }) - - -- Loading vscode-like snippets from 'friendly-snippets' - require('luasnip/loaders/from_vscode').load() -end - return M diff --git a/roles/nvim/files/nvim/lua/modules/completion/plugins.lua b/roles/nvim/files/nvim/lua/modules/completion/plugins.lua new file mode 100644 index 0000000..b1bd7a5 --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/completion/plugins.lua @@ -0,0 +1,35 @@ +local M = {} +local conf = require('modules.completion.config') + +M['hrsh7th/nvim-cmp'] = { + event = 'InsertEnter', + wants = {'LuaSnip', 'cmp-under-comparator'}, + requires = { + { + 'L3MON4D3/LuaSnip', + wants = 'friendly-snippets', + requires = {{'rafamadriz/friendly-snippets', opt = true}}, + config = conf.luasnip, + opt = true + }, + {'lukas-reineke/cmp-under-comparator', opt = true} + }, + config = conf.cmp +} +M['saadparwaiz1/cmp_luasnip'] = {after = 'nvim-cmp'} +M['saadparwaiz1/cmp_luasnip'] = {after = 'nvim-cmp'} +M['hrsh7th/cmp-path'] = {after = 'nvim-cmp'} +M['hrsh7th/cmp-buffer'] = {after = 'nvim-cmp'} +M['hrsh7th/cmp-calc'] = {after = 'nvim-cmp'} +M['uga-rosa/cmp-dictionary'] = {after = 'nvim-cmp'} +M['hrsh7th/cmp-nvim-lsp'] = {after = {'nvim-cmp', 'nvim-lspconfig'}} +-- M['tzachar/cmp-tabnine'] = { +-- after = 'nvim-cmp', +-- run = './install.sh', +-- config = conf.tabnine +-- } +M['kdheepak/cmp-latex-symbols'] = {after = 'nvim-cmp'} +M['PaterJason/cmp-conjure'] = {after = {'conjure', 'nvim-cmp'}} +M['windwp/nvim-autopairs'] = {after = 'nvim-cmp', config = conf.autopairs} + +return M diff --git a/roles/nvim/files/nvim/lua/modules/core/config.lua b/roles/nvim/files/nvim/lua/modules/core/config.lua new file mode 100644 index 0000000..ff62cf7 --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/core/config.lua @@ -0,0 +1,29 @@ +local M = {} + +function M.notify() + require('notify').setup { + -- Animation style (see below for details) + stages = 'fade_in_slide_out', + -- Function called when a new window is opened, use for changing win settings/config + on_open = nil, + -- Render function for notifications. See notify-render() + render = 'default', + -- Default timeout for notifications + timeout = 2000, + -- For stages that change opacity this is treated as the highlight behind the window + -- Set this to either a highlight group or an RGB hex value e.g. '#000000' + background_colour = 'NormalFloat', + -- Minimum width for notification windows + minimum_width = 40, + -- Icons for the different levels + icons = { + ERROR = '', + WARN = '', + INFO = '', + DEBUG = '', + TRACE = '✎' + } + } +end + +return M diff --git a/roles/nvim/files/nvim/lua/modules/pack.lua b/roles/nvim/files/nvim/lua/modules/core/pack.lua similarity index 87% rename from roles/nvim/files/nvim/lua/modules/pack.lua rename to roles/nvim/files/nvim/lua/modules/core/pack.lua index 384a005..99c80d8 100644 --- a/roles/nvim/files/nvim/lua/modules/pack.lua +++ b/roles/nvim/files/nvim/lua/modules/core/pack.lua @@ -1,7 +1,7 @@ -local fn, api = vim.fn, vim.api +local fn, cmd = vim.fn, vim.api.nvim_command -- Require since we use 'packer' as opt -api.nvim_command('packadd packer.nvim') +cmd('packadd packer.nvim') local present, packer = pcall(require, 'packer') if not present then @@ -11,7 +11,7 @@ if not present then -- remove packer_dir before cloning fn.delete(packer_dir, 'rf') fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', packer_dir}) - api.nvim_command('packadd packer.nvim') + cmd('packadd packer.nvim') present, packer = pcall(require, 'packer') if present then @@ -57,9 +57,9 @@ _G.packer_compile_on_save = function() local config_dir = fn.stdpath('config') .. '/lua/modules' if file:match(config_dir) and filename ~= 'pack.lua' then - vim.api.nvim_command('source | PackerCompile') + cmd('source | PackerCompile') end end -api.nvim_command('autocmd BufWritePost *.lua lua packer_compile_on_save()') +cmd('autocmd BufWritePost *.lua lua packer_compile_on_save()') return packer diff --git a/roles/nvim/files/nvim/lua/modules/core/plugins.lua b/roles/nvim/files/nvim/lua/modules/core/plugins.lua new file mode 100644 index 0000000..40e223b --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/core/plugins.lua @@ -0,0 +1,10 @@ +local conf = require('modules.core.config') +local M = { + ['wbthomason/packer.nvim'] = {opt = true}, + ['kyazdani42/nvim-web-devicons'] = {module = 'nvim-web-devicons'}, + ['nvim-lua/plenary.nvim'] = {module = 'plenary'}, + ['nvim-lua/popup.nvim'] = {module = 'popup'}, + ['rcarriga/nvim-notify'] = {module = 'nvim-notify', config = conf.notify} +} + +return M diff --git a/roles/nvim/files/nvim/lua/modules/editor.lua b/roles/nvim/files/nvim/lua/modules/editor/config.lua similarity index 72% rename from roles/nvim/files/nvim/lua/modules/editor.lua rename to roles/nvim/files/nvim/lua/modules/editor/config.lua index b635357..e5c90c1 100644 --- a/roles/nvim/files/nvim/lua/modules/editor.lua +++ b/roles/nvim/files/nvim/lua/modules/editor/config.lua @@ -1,6 +1,6 @@ local M = {} -function M.colorizer_conf() +function M.colorizer() require('colorizer').setup( {'*'}, { @@ -16,40 +16,19 @@ function M.colorizer_conf() }) end --- function M.illuminate_conf() +-- function M.illuminate() -- vim.g.Illuminate_delay = 500 -- vim.g.Illuminate_ftblacklist = {'alpha', 'NvimTree', 'undotree', 'packer'} -- end -function M.blankline_conf() - require('indent_blankline').setup { - char = '│', - -- space_char_blankline = '·', - show_first_indent_level = true, - filetype_exclude = { - 'startify', 'dashboard', 'alpha', 'log', 'gitcommit', 'packer', 'vimwiki', - 'markdown', 'org', 'json', 'txt', 'help', 'NvimTree', 'git', 'TelescopePrompt', - 'undotree', 'dotooagenda', 'fugitive', - '' -- for all buffers without a filetype - }, - buftype_exclude = {'terminal', 'nofile'}, - show_trailing_blankline_indent = false, - -- show_end_of_line = true, - show_current_context = true, - context_patterns = { - 'class', 'function', 'method', 'block', 'list_literal', 'selector', '^if', - '^table', 'if_statement', 'while', 'for' - }, - use_treesitter = true +function M.org_bullets() + require('org-bullets').setup { + symbols = {'', '', '', ''} } - - -- Refresh often, since it is lazy-loaded - -- vim.api.nvim_command('autocmd CursorMoved * IndentBlanklineRefresh') end -function M.orgmode_conf() +function M.orgmode() local c = require('themes.' .. vim.g.colors_name .. '.colors') - require('orgmode').setup { -- General settings org_agenda_files = {'~/Documents/Org/agenda/*'}, @@ -84,60 +63,10 @@ function M.orgmode_conf() org_use_tag_inheritance = false } - -- Define mappings's names - vim.api.nvim_command('autocmd FileType org lua WhichkeyOrg()') - local wk = require('which-key') - function WhichkeyOrg() - wk.register({ - ['o'] = { - name = 'Org', - a = 'Agenda', - A = 'Toggle ARCHIVE', - c = 'Capture', - e = 'Export', - i = { - name = 'Insert', - h = 'Add headline', - t = 'Add TODO heading and content', - T = 'Add TODO heading' - }, - J = 'Move subtree down', - K = 'Move subtree up', - o = 'Open at point', - r = 'Refile', - t = 'Set tags', - ['$'] = 'Archive current headline' - }, - [''] = 'Org meta return', - [''] = 'Org increase date', - [''] = 'Org decrease date', - ['cid'] = 'Org change date', - ['cit'] = 'Org TODO', - ['ciT'] = 'Org TODO prev', - [''] = 'Org toggle checkbox', - [''] = 'Org cycle folding', - [''] = 'Org cycle global folding', - ['<<'] = 'Org promote headline', - ['>>'] = 'Org demote headline', - ['s'] = 'Org demote subtree', - ['}'] = 'Org next visible heading', - ['{'] = 'Org previous visible heading', - [']]'] = 'Org forward heading', - ['[['] = 'Org backward heading', - ['g{'] = 'Org parent heading', - ['?'] = 'Org help' - }, {buffer = vim.api.nvim_get_current_buf()}) - end + require('mappings').orgmode() end -function M.bullets_conf() - require('org-bullets').setup { - symbols = {'', '', '', ''} - } -end - -function M.headlines_conf() +function M.headlines() require('headlines').setup { markdown = { headline_signs = false, @@ -152,7 +81,7 @@ function M.headlines_conf() } end -function M.treesitter_conf() +function M.treesitter() -- Additional parser for rest.nvim (*.http files) local parser_configs = require('nvim-treesitter.parsers').get_parser_configs() parser_configs.http = { @@ -166,7 +95,8 @@ function M.treesitter_conf() install_info = { url = 'https://github.com/milisims/tree-sitter-org', revision = 'main', - files = {'src/parser.c', 'src/scanner.cc'} + files = {'src/parser.c', 'src/scanner.cc'}, + branch = 'master' } } @@ -185,7 +115,7 @@ function M.treesitter_conf() node_decremental = 'gnm' } }, - indent = {enable = true}, + indent = {enable = false}, refactor = { highlight_definitions = {enable = true}, highlight_current_scope = {enable = false}, @@ -286,65 +216,55 @@ function M.treesitter_conf() vim.opt.foldmethod = 'expr' vim.opt.foldexpr = 'nvim_treesitter#foldexpr()' - -- Define mappings' names - local wk = require('which-key') - local mappings = { - ['['] = { - m = 'Previous start of outer class', - M = 'Previous end of outer class', - ['['] = 'Previous start of outer function', - [']'] = 'Previous end of outer function' - }, - [']'] = { - m = 'Next start of outer class', - M = 'Next end of outer class', - ['['] = 'Next start of outer function', - [']'] = 'Next end of outer function' - }, - g = { - n = { - name = 'Treesitter', - d = 'Goto definition', - D = 'List definitions', - i = 'Initialize selection', - j = 'Goto previous usage', - k = 'Goto next usage', - o = 'List definitions TOC', - r = 'Rename within scope' - } - } - } - local visual_mappings = { - a = { - c = 'Outer class', - f = 'Outer function' - }, - - i = { - c = 'Inner class', - f = 'Inner function' - }, - - g = { - n = { - name = 'Treesitter', - n = 'Increment node', - s = 'Increment scope', - m = 'Decrement node' - } - } - } - - wk.register(mappings) - wk.register(visual_mappings, {mode = 'v'}) + require('mappings').treesitter() end --- function M.detect_conf() +-- function M.detect_language() -- require('detect-language').setup() -- vim.api.nvim_command('autocmd BufNewFile * DetectLanguageBufEnable') -- end -function M.iswap_conf() +-- function M.spellsitter() +-- require('spellsitter').setup { +-- -- Whether enabled, can be a list of filetypes, e.g. {'python', 'lua'} +-- enable = true, +-- -- Highlight to use for bad spellings +-- hl = 'SpellBad', +-- -- Spellchecker to use. values: +-- -- * vimfn: built-in spell checker using vim.fn.spellbadword() +-- -- * ffi: built-in spell checker using the FFI to access the +-- -- internal spell_check() function +-- spellchecker = 'vimfn', +-- } +-- end + +function M.indent_blankline() + require('indent_blankline').setup { + char = '│', + -- space_char_blankline = '·', + show_first_indent_level = true, + filetype_exclude = { + 'startify', 'dashboard', 'alpha', 'log', 'gitcommit', 'packer', 'vimwiki', + 'markdown', 'org', 'json', 'txt', 'help', 'NvimTree', 'git', 'TelescopePrompt', + 'undotree', 'dotooagenda', 'fugitive', + '' -- for all buffers without a filetype + }, + buftype_exclude = {'terminal', 'nofile'}, + show_trailing_blankline_indent = false, + -- show_end_of_line = true, + show_current_context = true, + context_patterns = { + 'class', 'function', 'method', 'block', 'list_literal', 'selector', '^if', + '^table', 'if_statement', 'while', 'for' + }, + use_treesitter = true + } + + -- Refresh often, since it is lazy-loaded + -- vim.api.nvim_command('autocmd CursorMoved * IndentBlanklineRefresh') +end + +function M.iswap() require('iswap').setup { -- The keys that will be used as a selection, in order -- ('asdfghjklqwertyuiopzxcvbnm' by default) @@ -372,11 +292,11 @@ function M.iswap_conf() } end -function M.matchup_conf() +function M.matchup() vim.g.matchup_matchparen_offscreen = {method = 'popup'} end -function M.twilight_conf() +function M.twilight() require('twilight').setup { dimming = { alpha = 0.25, -- amount of dimming @@ -396,7 +316,7 @@ function M.twilight_conf() } end -function M.zenmode_conf() +function M.zenmode() require('zen-mode').setup { window = { options = { @@ -419,7 +339,7 @@ function M.zenmode_conf() } end -function M.betterescape_conf() +function M.better_escape() require('better_escape').setup { mapping = {'jk', 'kj'}, timeout = vim.opt.timeoutlen:get(), @@ -428,27 +348,16 @@ function M.betterescape_conf() } end -function M.hop_conf() +function M.hop() require('hop').setup {keys = 'etovxqpdygfblzhckisuran'} end -function M.eft_conf() +function M.eft() vim.g.eft_index_function = {all = function() return true end} - - -- Mappings - vim.api.nvim_set_keymap('n', 'f', '(eft-f)', {silent = true}) - vim.api.nvim_set_keymap('x', 'f', '(eft-f)', {silent = true}) - vim.api.nvim_set_keymap('n', 'F', '(eft-F)', {silent = true}) - vim.api.nvim_set_keymap('x', 'F', '(eft-F)', {silent = true}) - vim.api.nvim_set_keymap('n', 't', '(eft-t)', {silent = true}) - vim.api.nvim_set_keymap('x', 't', '(eft-t)', {silent = true}) - vim.api.nvim_set_keymap('n', 'T', '(eft-T)', {silent = true}) - vim.api.nvim_set_keymap('x', 'T', '(eft-T)', {silent = true}) - vim.api.nvim_set_keymap('n', ';', '(eft-repeat)', {silent = true}) - vim.api.nvim_set_keymap('x', ';', '(eft-repeat)', {silent = true}) + require('mappings').eft() end -function M.dial_conf() +function M.dial() local dial = require('dial') -- Custom augends @@ -493,23 +402,17 @@ function M.dial_conf() 'color#hex' } - -- Mappings - vim.api.nvim_set_keymap('n', '', '(dial-increment)', {silent = true}) - vim.api.nvim_set_keymap('v', '', '(dial-increment)', {silent = true}) - vim.api.nvim_set_keymap('n', '', '(dial-decrement)', {silent = true}) - vim.api.nvim_set_keymap('v', '', '(dial-decrement)', {silent = true}) - vim.api.nvim_set_keymap('v', 'g', '(dial-increment-additional)', {silent = true}) - vim.api.nvim_set_keymap('v', 'g', '(dial-decrement-additional)', {silent = true}) + require('mappings').dial() end -function M.table_conf() +function M.table_mode() vim.g.table_mode_disable_mappings = 1 vim.g.table_mode_disable_tableize_mappings = 1 vim.g.table_mode_map_prefix = 'et' vim.g.table_mode_toggle_map = '' end -function M.comment_conf() +function M.comment() require('Comment').setup { padding = true, -- add a ' ' between comment and the line sticky = true, -- whether the cursor should stay at its position @@ -534,22 +437,19 @@ function M.comment_conf() } end -function M.range_conf() +function M.range_highlight() require('range-highlight').setup() end -function M.neogen_conf() +function M.neogen() require('neogen').setup { enabled = true, input_after_comment = true } - - -- Mappings - vim.api.nvim_set_keymap('n', 'eg', ':lua require("neogen").generate()', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', '', ':lua require("neogen").jump_next()', {noremap = true, silent = true}) + require('mappings').neogen() end -function M.project_conf() +function M.project() require('project_nvim').setup { manual_mode = false, detection_methods = {'lsp', 'pattern'}, @@ -570,7 +470,7 @@ function M.project_conf() -- vim.api.nvim_command('autocmd BufEnter * lua set_window_project_dir()') end -function M.gitlinker_conf() +function M.gitlinker() require('gitlinker').setup { opts = { remote = nil, -- force the use of a specific remote @@ -590,8 +490,32 @@ function M.gitlinker_conf() mappings = 'gy' } - -- Mapping to get remote url - vim.api.nvim_set_keymap('n', 'gY', ':lua require("gitlinker").get_repo_url()', {noremap = true, silent = true}) + require('mappings').gitlinker() +end + +function M.filetype() + require('filetype').setup { + overrides = { + extensions = { + md = 'markdown', + mkd = 'markdown', + toml = 'toml', + rasi = 'css', + vifm = 'vim', + log = 'log', + LO = 'log' + }, + literal = { + vifmrc = 'vim' + }, + complex = { + ['*_log'] = 'log', + ['G*_LOG'] = 'log', + ['.*waybar/config'] = 'jsonc', + ['.*lf/lfrc'] = 'sh' + } + } + } end return M diff --git a/roles/nvim/files/nvim/lua/modules/editor/plugins.lua b/roles/nvim/files/nvim/lua/modules/editor/plugins.lua new file mode 100644 index 0000000..059456e --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/editor/plugins.lua @@ -0,0 +1,139 @@ +local M = {} +local conf = require('modules.editor.config') + +M['norcalli/nvim-colorizer.lua'] = { + cmd = 'ColorizerToggle', + config = conf.colorizer +} +-- M['RRethy/vim-illuminate'] = { -- TODO: check out treesitter support, otherwise use nvim-treesitter-refactor +-- event = 'CursorHold', +-- setup = conf.illuminate +-- } +M['Olical/conjure'] = { -- TODO: config, check out fennel-repl.nvim + ft = {'clojure', 'fennel', 'scheme', 'hy', 'janet', 'racket'} +} +M['kristijanhusak/orgmode.nvim'] = { -- TODO: highlights, check out neorg + ft = 'org', + requires = {{ + 'akinsho/org-bullets.nvim', + after = 'orgmode.nvim', + config = conf.org_bullets + }}, + config = conf.orgmode +} +M['lukas-reineke/headlines.nvim'] = { + ft = {'org', 'markdown'}, + config = conf.headlines +} +M['nvim-treesitter/nvim-treesitter'] = { + run = ':TSUpdate', + event = 'BufRead', + config = conf.treesitter +} +M['nvim-treesitter/playground'] = {after = 'nvim-treesitter'} +M['nvim-treesitter/nvim-treesitter-refactor'] = {after = 'nvim-treesitter'} +M['nvim-treesitter/nvim-treesitter-textobjects'] = {after = 'nvim-treesitter'} +M['p00f/nvim-ts-rainbow'] = {after = 'nvim-treesitter'} +M['windwp/nvim-ts-autotag'] = {after = 'nvim-treesitter'} +M['romgrk/nvim-treesitter-context'] = {after = 'nvim-treesitter'} +M['JoosepAlviste/nvim-ts-context-commentstring'] = {after = 'nvim-treesitter'} +-- M['spywhere/detect-language.nvim'] = { +-- event = 'BufNewFile', +-- config = conf.detect_language +-- } +-- M['lewis6991/spellsitter.nvim'] = { +-- event = {'BufRead', 'BufNewFile'}, +-- config = conf.spellsitter +-- } +M['lukas-reineke/indent-blankline.nvim'] = { + after = 'nvim-treesitter', + config = conf.indent_blankline +} +M['mizlan/iswap.nvim'] = { + cmd = {'ISwapWith', 'ISwap'}, + wants = 'nvim-treesitter', + config = conf.iswap +} +M['andymass/vim-matchup'] = { + after = 'nvim-treesitter', + config = conf.matchup +} +M['machakann/vim-sandwich'] = {keys = 's'} -- TODO: check out surround.nvim +M['folke/zen-mode.nvim'] = { + cmd = 'ZenMode', + wants = 'twilight.nvim', + requires = {{ + 'folke/twilight.nvim', + cmd = {'Twilight', 'TwilightEnable'}, + config = conf.twilight, + opt = true + }}, + config = conf.zenmode +} +M['max397574/better-escape.nvim'] = { + event = 'InsertCharPre', + config = conf.better_escape +} +M['phaazon/hop.nvim'] = { -- TODO: check out lightspeed.nvim + cmd = {'HopChar1', 'HopChar2', 'HopWord', 'HopPattern', 'HopLine'}, + config = conf.hop +} +M['hrsh7th/vim-eft'] = { + keys = { + {'n', 'f'}, {'x', 'f'}, {'n', 'F'}, {'x', 'F'}, + {'n', 't'}, {'x', 't'}, {'n', 'T'}, {'x', 'T'}, + {'n', ';'}, {'x', ';'} + }, + config = conf.eft +} +M['monaqa/dial.nvim'] = { + keys = { + {'n', ''}, {'v', ''}, {'v', 'g'}, + {'n', ''}, {'v', ''}, {'v', 'g'} + }, + config = conf.dial +} +M['junegunn/vim-easy-align'] = {cmd = {'EasyAlign', 'LiveEasyAlign'}} +M['dhruvasagar/vim-table-mode'] = { + cmd = {'Tableize', 'TableModeToggle', 'TableModeRealign'}, + setup = conf.table_mode +} +M['numToStr/Comment.nvim'] = { + keys = {'gc', 'gb'}, + wants = 'nvim-ts-context-commentstring', + config = conf.comment +} +M['winston0410/range-highlight.nvim'] = { + event = 'CmdlineEnter', + wants = 'cmd-parser.nvim', + requires = {{'winston0410/cmd-parser.nvim', opt = true}}, + config = conf.range_highlight +} +M['danymat/neogen'] = { + keys = 'eg', + wants = 'nvim-treesitter', + config = conf.neogen +} +M['gpanders/editorconfig.nvim'] = { + event = {'BufRead', 'BufNewFile'} +} +M['eraserhd/parinfer-rust'] = { -- TODO: move to nvim-parinfer (lua) + run = 'cargo build --release', + ft = {'clojure', 'lisp', 'scheme', 'fennel', 'racket', 'hy', 'janet', 'carp', 'wast'} +} +M['ahmedkhalf/project.nvim'] = { + event = 'BufEnter', + config = conf.project +} +M['ruifm/gitlinker.nvim'] = { + wants = 'plenary.nvim', + keys = {'gy', 'gY'}, + config = conf.gitlinker +} +M['jbyuki/venn.nvim'] = {cmd = 'VBox'} +M['nathom/filetype.nvim'] = { + event = {'BufRead', 'BufNewFile'}, + config = conf.filetype +} + +return M diff --git a/roles/nvim/files/nvim/lua/modules/lsp.lua b/roles/nvim/files/nvim/lua/modules/lsp.lua deleted file mode 100644 index 4f3675d..0000000 --- a/roles/nvim/files/nvim/lua/modules/lsp.lua +++ /dev/null @@ -1,631 +0,0 @@ -local M = {} - -function M.signature_conf() - require('lsp_signature').setup { - bind = true, -- This is mandatory, otherwise border config doesn't work - floating_window = true, - fix_pos = true, - hint_enable = false, - hint_prefix = ' ', - hint_scheme = 'String', - hi_parameter = 'Visual', - transpancy = 5, - handler_opts = {border = 'single'}, - zindex = 50, -- set to 200 to make the float window on top of others - toggle_key = '' - } -end - -function M.saga_conf() - require('lspsaga').init_lsp_saga { - debug = false, - use_saga_diagnostic_sign = true, - -- diagnostic sign - error_sign = '', - warn_sign = '', - hint_sign = '', - infor_sign = '', - dianostic_header_icon = '  ', - -- code action title icon - code_action_icon = ' ', - code_action_prompt = { - enable = false, - sign = true, - sign_priority = 40, - virtual_text = true - }, - finder_definition_icon = ' ', - finder_reference_icon = ' ', - max_preview_lines = 10, - finder_action_keys = { - open = 'o', - vsplit = 's', - split = 'i', - quit = 'q', - scroll_down = '', - scroll_up = '' - }, - code_action_keys = { - quit = 'q', - exec = '' - }, - rename_action_keys = { - quit = '', - exec = '' - }, - definition_preview_icon = ' ', - border_style = 'single', - rename_prompt_prefix = '', - server_filetype_map = {} - } -end - -function M.lsp_conf() - local lspconf = require('lspconfig') - local on_attach = require('util').lsp_on_attach - - local capabilities = vim.lsp.protocol.make_client_capabilities() - -- Add additional capabilities supported by nvim-cmp - local completionItem = capabilities.textDocument.completion.completionItem - completionItem.documentationFormat = {'markdown', 'plaintext'} - completionItem.snippetSupport = true - completionItem.preselectSupport = true - completionItem.insertReplaceSupport = true - completionItem.labelDetailsSupport = true - completionItem.deprecatedSupport = true - completionItem.commitCharactersSupport = true - completionItem.tagSupport = {valueSet = {1}} - completionItem.resolveSupport = { - properties = { - 'documentation', - 'detail', - 'additionalTextEdits', - } - } - - -- Replace the default lsp diagnostic letters with prettier symbols - vim.fn.sign_define('LspDiagnosticsSignError', {text = ''}) - vim.fn.sign_define('LspDiagnosticsSignWarning', {text = ''}) - vim.fn.sign_define('LspDiagnosticsSignInformation', {text = ''}) - vim.fn.sign_define('LspDiagnosticsSignHint', {text = ''}) - - --------------------------- - -- Server configurations -- - --------------------------- - -- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md - local servers_path = vim.fn.stdpath('data') .. '/lsp' - - -- C/C++ - lspconf.clangd.setup { - on_attach = on_attach, - capabilities = capabilities, - filetypes = {'c', 'cpp'}, - init_options = { - usePlaceholders = true, - completeUnimported = true, - clangdFileStatus = true - }, - cmd = { - 'clangd', - '-j=2', - '--background-index', - '--clang-tidy', - '--completion-style=detailed', - '--pch-storage=memory', - '--header-insertion=iwyu', - '--header-insertion-decorators' - } - } - - -- Lua - local lua_lib_path = {} - local lua_runtime_path = {} - - -- lua_lib_path[vim.fn.expand('~/.luarocks/share/lua/5.3')] = true - -- lua_lib_path[vim.fn.expand('/usr/share/lua/5.3')] = true - lua_lib_path[os.getenv('VIMRUNTIME') .. '/lua'] = true - -- local function add(lib) - -- for _, p in pairs(vim.fn.expand(lib .. '/lua', false, true)) do - -- p = vim.loop.fs_realpath(p) - -- if p then lua_lib_path[p] = true end - -- end - -- end - -- for _, site in pairs(vim.split(vim.opt.packpath:get(), ',')) do - -- add(site .. '/pack/*/opt/*') - -- add(site .. '/pack/*/start/*') - -- end - - table.insert(lua_runtime_path, 'lua/?.lua') - table.insert(lua_runtime_path, 'lua/?/init.lua') - -- table.insert(lua_runtime_path, '?.lua') - -- table.insert(lua_runtime_path, '?/?.lua') - -- table.insert(lua_runtime_path, '?/init.lua') - - for lib, _ in pairs(lua_lib_path) do - table.insert(lua_runtime_path, lib .. '/?.lua') - table.insert(lua_runtime_path, lib .. '/?/init.lua') - end - - lspconf.sumneko_lua.setup { - on_attach = on_attach, - capabilities = capabilities, - cmd = { - servers_path .. '/sumneko_lua/bin/Linux/lua-language-server', - '-E', '-e', 'LANG=en', - servers_path .. '/sumneko_lua/main.lua' - }, - settings = { - Lua = { - diagnostics = {globals = {'vim'}}, - runtime = {version = 'LuaJIT', path = lua_runtime_path}, - workspace = { - library = lua_lib_path, - maxPreload = 1000, - preloadFileSize = 150 - }, - completion = {callSnippet = 'Replace'}, - hint = {enable = true}, - telemetry = {enable = false} - } - } - } - - -- Go - lspconf.gopls.setup { - on_attach = on_attach, - capabilities = capabilities, - cmd = {servers_path .. '/gopls/gopls', '--remote=auto'}, - init_options = { - usePlaceholders = true, - completeUnimported = true - } - } - - -- Yaml - -- lspconf.yamlls.setup { - -- on_attach = on_attach, - -- capabilities = capabilities, - -- cmd = {servers_path .. '/yamlls/node_modules/.bin/yaml-language-server', '--stdio'}, - -- settings = { - -- redhat = {telemetry = {enabled = false}}, - -- yaml = { - -- format = { - -- bracketSpacing = true, - -- printWidth = 80, - -- -- proseWrap = 'always', -- default is 'preserve' - -- -- singleQuote = true, - -- -- editor.formatOnType = true - -- }, - -- schemas = require('schemastore').json.schemas() - -- } - -- } - -- } - - -- Ansible - lspconf.ansiblels.setup { - on_attach = on_attach, - capabilities = capabilities, - cmd = {'node', servers_path .. '/ansiblels/out/server/src/server.js', '--stdio'}, - settings = { - ansible = { - python = {interpreterPath = 'python3'}, - executionEnvironment = {enabled = false} - } - } - } - - -- Tailwind - -- lspconf.tailwindcss.setup { - -- on_attach = on_attach, - -- capabilities = capabilities, - -- cmd = {servers_path .. '/tailwindcss/node_modules/.bin/tailwindcss-language-server', '--stdio'}, - -- settings = { - -- tailwindCSS = { - -- emmetCompletions = true - -- } - -- } - -- } - - -- Emmet - lspconf.emmet_ls.setup { - cmd = {servers_path .. '/emmet_ls/node_modules/.bin/emmet-ls', '--stdio'}, - filetypes = { - 'html', 'xml', 'css', 'scss', 'sass', - 'javascript', 'javascriptreact' - }, - capabilities = capabilities - } - - -- HTML - lspconf.html.setup { - on_attach = on_attach, - capabilities = capabilities, - cmd = {servers_path .. '/vscode/node_modules/.bin/vscode-html-language-server', '--stdio'}, - } - - -- Eslint - lspconf.eslint.setup { - on_attach = on_attach, - capabilities = capabilities, - cmd = {servers_path .. '/vscode/node_modules/.bin/vscode-eslint-language-server', '--stdio'}, - filetypes = {'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'vue', 'svelte'}, - handlers = { - ['eslint/noConfig'] = function() - vim.notify('Unable to parse ESLint config.', vim.log.levels.WARN) - end - }, - settings = { - codeAction = { - disableRuleComment = { - enable = true, - location = 'separateLine' - }, - showDocumentation = {enable = true} - }, - codeActionOnSave = { - enable = false, -- run ':EslintFixAll' manually - mode = 'all' - }, - format = true, - nodePath = '', - onIgnoredFiles = 'off', - packageManager = 'npm', - quiet = false, - rulesCustomizations = {}, - run = 'onType', - useESLintClass = false, - validate = 'on', - workingDirectory = {mode = 'auto'} - } - } - - -- JSON - lspconf.jsonls.setup { - on_attach = on_attach, - capabilities = capabilities, - cmd = {servers_path .. '/vscode/node_modules/.bin/vscode-json-language-server', '--stdio'}, - settings = { - json = { - -- Schema catalog: https://www.schemastore.org/api/json/catalog.json - schemas = require('schemastore').json.schemas() - } - } - } - - -- Others - local servers = { - rust_analyzer = {'rust-analyzer'}, - sqls = {servers_path .. '/sqls/sqls'}, - cmake = {servers_path .. '/cmake/venv/bin/cmake-language-server'}, - -- bashls = {servers_path .. '/bashls/node_modules/.bin/bash-language-server', 'start'}, - -- dockerls = {servers_path .. '/dockerls/node_modules/.bin/docker-langserver', '--stdio'}, - cssls = {servers_path .. '/vscode/node_modules/.bin/vscode-css-language-server', '--stdio'}, - pyright = {servers_path .. '/pyright/node_modules/.bin/pyright-langserver', '--stdio'}, - -- vimls = {servers_path .. '/vimls/node_modules/.bin/vim-language-server', '--stdio'}, - tsserver = {servers_path .. '/tsserver/node_modules/.bin/typescript-language-server', '--stdio'} - } - for server, _ in pairs(servers) do - lspconf[server].setup { - on_attach = on_attach, - capabilities = capabilities, - cmd = servers[server] - } - end -end - --- TODO: installers for the rest --- TODO: ansible-lint -function M.null_ls_conf() - local null_ls = require('null-ls') - local linters_path = vim.fn.stdpath('data') .. '/lint' - - -- Register sources - null_ls.config { - sources = { - -- Formatters -- - -- null_ls.builtins.formatting.black.with { - -- command = linters_path .. '/black/venv/bin/black' - -- }, - -- null_ls.builtins.formatting.codespell.with { - -- command = linters_path .. '/codespell/venv/bin/codespell' - -- }, - null_ls.builtins.formatting.clang_format.with { - filetypes = {'c', 'cpp'} - }, - null_ls.builtins.formatting.cmake_format.with { - command = linters_path .. '/cmake_format/venv/bin/cmake-format' - }, - -- null_ls.builtins.formatting.fish_indent, - -- null_ls.builtins.formatting.fixjson.with {command = 'fixjson'}, - -- null_ls.builtins.formatting.fnlfmt.with {command = 'fnlfmt'}, - -- null_ls.builtins.formatting.goimports.with {command = 'goimports'}, - -- null_ls.builtins.formatting.gofmt.with {command = 'gofmt'}, - -- null_ls.builtins.formatting.isort.with { - -- command = linters_path .. '/isort/venv/bin/isort' - -- }, - -- null_ls.builtins.formatting.nixfmt.with {command = 'nixfmt'}, - -- null_ls.builtins.formatting.prettier.with { - -- command = linters_path .. '/prettier/node_modules/.bin/prettier' - -- }, - -- null_ls.builtins.formatting.rustfmt.with {command = 'rustfmt'}, - -- null_ls.builtins.formatting.rustywind.with {command = 'rustywind'}, - -- null_ls.builtins.formatting.shfmt.with { - -- command = linters_path .. '/shfmt/shfmt' - -- }, - null_ls.builtins.formatting.stylua.with { - condition = function(utils) - return utils.root_has_file('stylua.toml') - end, - command = 'stylua' - }, - -- null_ls.builtins.formatting.uncrustify.with {command = 'uncrustify'}, - -- null_ls.builtins.formatting.yapf.with { - -- command = linters_path .. '/yapf/venv/bin/yapf' - -- }, - -- null_ls.builtins.formatting.autopep8.with { - -- command = linters_path .. '/autopep8/venv/bin/autopep8' - -- }, - -- null_ls.builtins.formatting.stylelint.with { - -- command = linters_path .. '/stylelint/node_modules/.bin/stylelint' - -- }, - - -- Linters -- - null_ls.builtins.diagnostics.shellcheck, - null_ls.builtins.diagnostics.codespell.with { - command = linters_path .. '/codespell/venv/bin/codespell' - }, - null_ls.builtins.diagnostics.cspell.with { - command = linters_path .. '/cspell/node_modules/.bin/cspell' - }, - -- null_ls.builtins.diagnostics.flake8.with { - -- command = linters_path .. '/flake8/venv/bin/flake8' - -- }, - null_ls.builtins.diagnostics.hadolint.with { - command = vim.fn.stdpath('config') .. '/scripts/hadolint', - args = {'$FILENAME'} - }, - -- null_ls.builtins.diagnostics.luacheck, - null_ls.builtins.diagnostics.cppcheck, - null_ls.builtins.diagnostics.write_good.with { - command = linters_path .. '/write_good/node_modules/.bin/write-good' - }, - null_ls.builtins.diagnostics.markdownlint.with { - command = linters_path .. '/markdownlint/node_modules/.bin/markdownlint' - }, - -- null_ls.builtins.diagnostics.pylint.with { - -- command = linters_path .. '/pylint/venv/bin/pylint' - -- }, - null_ls.builtins.diagnostics.qmllint, - null_ls.builtins.diagnostics.selene.with { - condition = function(utils) - return utils.root_has_file('selene.toml') - end, - }, - -- null_ls.builtins.diagnostics.vale.with { - -- command = linters_path .. '/vale/vale' - -- }, - -- null_ls.builtins.diagnostics.vint.with { - -- command = linters_path .. '/vint/venv/bin/vint' - -- }, - -- null_ls.builtins.diagnostics.stylelint.with { - -- command = linters_path .. '/stylelint/node_modules/.bin/stylelint' - -- }, - - -- Special -- - null_ls.builtins.hover.dictionary -- get word definition from dictionaryapi.dev - } - } - - local lspconf = require('lspconfig') - local on_attach = require('util').lsp_on_attach - lspconf['null-ls'].setup { - on_attach = on_attach - } -end - -function M.sqls_conf() - require('sqls').setup { - picker = 'telescope' - } -end - -function M.trouble_conf() - require('trouble').setup { - mode = 'lsp_workspace_diagnostics', - fold_open = ' ', - fold_closed = '', - action_keys = { - open_split = {''}, - open_vsplit = {''}, - open_tab = {''} - }, - signs = { - error = '', - warning = '', - information = '', - hint = '', - other = '' - } - } -end - -function M.comments_conf() - require('todo-comments').setup { - signs = false, - -- sign_priority = 8, - keywords = { - FIX = { - icon = ' ', -- icon used for the sign, and in search results - color = 'error', -- can be a hex color, or a named color (see below) - alt = {'FIXME', 'BUG', 'FIXIT', 'ISSUE'}, -- a set of other keywords that all map to this FIX keywords - -- signs = false, -- configure signs for some keywords individually - }, - TODO = {icon = ' ', color = 'info'}, - HACK = {icon = ' ', color = 'warning'}, - WARN = {icon = ' ', color = 'warning', alt = {'WARNING', 'XXX'}}, - PERF = {icon = ' ', alt = {'OPTIM', 'PERFORMANCE', 'OPTIMIZE'}}, - NOTE = {icon = ' ', color = 'hint', alt = {'INFO'}}, - }, - merge_keywords = true, - highlight = { - before = '', -- 'fg' or 'bg' or empty - keyword = 'fg', -- 'fg', 'bg', 'wide' or empty. (wide is the same as bg, but will also highlight surrounding characters) - after = '', -- 'fg' or 'bg' or empty - pattern = [[.*<(KEYWORDS)\s*:]], -- pattern or table of patterns, used for highlightng (vim regex) - comments_only = true, -- uses treesitter to match keywords in comments only - max_line_len = 400, -- ignore lines longer than this - exclude = {'org'} -- list of file types to exclude highlighting - }, - colors = { - error = {'LspDiagnosticsDefaultError', 'TSDanger', '#bf616a', '#e06c75'}, - warning = {'LspDiagnosticsDefaultWarning', 'TSWarning', '#ebcb8b', '#e5c07b'}, - info = {'LspDiagnosticsDefaultInformation', 'TSNote', '#81a1c1', '#61afef'}, - hint = {'LspDiagnosticsDefaultHint', '#88c0d0', '#56b6c2'}, - default = {'Normal', '#d8dee9', '#abb2bf'} - }, - search = { - command = 'rg', - args = { - '--hidden', - '--color=never', - '--no-heading', - '--with-filename', - '--line-number', - '--column', - }, - -- regex that will be used to match keywords. - -- don't replace the (KEYWORDS) placeholder - pattern = [[\b(KEYWORDS):]] -- ripgrep regex - -- pattern = [[\b(KEYWORDS)\b]] -- match without the extra colon. You'll likely get false positives - } - } -end - -function M.outline_conf() - vim.g.symbols_outline = { - highlight_hovered_item = false, - show_guides = true, - auto_preview = true, - position = 'right', - width = 30, - show_numbers = false, - show_relative_numbers = false, - show_symbol_details = true, - preview_bg_highlight = 'NormalFloat', - keymaps = { -- Can be string or a table - close = {'', 'q'}, - goto_location = '', - focus_location = 'o', - hover_symbol = '', - toggle_preview = 'K', - rename_symbol = 'r', - code_actions = 'a', - }, - lsp_blacklist = {}, - symbol_blacklist = {}, - symbols = { - File = {icon = '', hl = 'TSURI'}, - Module = {icon = '', hl = 'TSNamespace'}, - Namespace = {icon = '', hl = 'TSNamespace'}, - Package = {icon = '', hl = 'TSNamespace'}, - Class = {icon = '𝓒', hl = 'TSType'}, - Method = {icon = 'ƒ', hl = 'TSMethod'}, - Property = {icon = '', hl = 'TSMethod'}, - Field = {icon = '', hl = 'TSField'}, - Constructor = {icon = '', hl = 'TSConstructor'}, - Enum = {icon = 'ℰ', hl = 'TSType'}, - Interface = {icon = 'ﰮ', hl = 'TSType'}, - Function = {icon = '', hl = 'TSFunction'}, - Variable = {icon = '', hl = 'TSConstant'}, - Constant = {icon = '', hl = 'TSConstant'}, - String = {icon = '𝓐', hl = 'TSString'}, - Number = {icon = '#', hl = 'TSNumber'}, - Boolean = {icon = '⊨', hl = 'TSBoolean'}, - Array = {icon = '', hl = 'TSConstant'}, - Object = {icon = '⦿', hl = 'TSType'}, - Key = {icon = '🔐', hl = 'TSType'}, - Null = {icon = 'NULL', hl = 'TSType'}, - EnumMember = {icon = '', hl = 'TSField'}, - Struct = {icon = '𝓢', hl = 'TSType'}, - Event = {icon = '🗲', hl = 'TSType'}, - Operator = {icon = '+', hl = 'TSOperator'}, - TypeParameter = {icon = '𝙏', hl = 'TSParameter'} - } - } -end - -function M.dap_conf() - local dap = require('dap') - vim.fn.sign_define('DapBreakpoint', {text='', texthl='DapSignDefault'}) - vim.fn.sign_define('DapLogPoint', {text='', texthl='DapSignDefault'}) - vim.fn.sign_define('DapStopped', {text='ﱢ', texthl='DapSignDefault'}) - vim.fn.sign_define('DapBreakpointRejected', {text='', texthl='DapSignRejected'}) - - -- Mappings - vim.api.nvim_command('n', 'dn', ':lua require("dap").continue()', {noremap = true, silent = true}) - vim.api.nvim_command('n', 'dd', ':lua require("dap").disconnect()', {noremap = true, silent = true}) - vim.api.nvim_command('n', 'db', ':lua require("dap").toggle_breakpoint()', {noremap = true, silent = true}) - vim.api.nvim_command('n', 'dB', ':lua require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: "))', {noremap = true, silent = true}) - vim.api.nvim_command('n', 'dl', ':lua require("dap").list_breakpoints()', {noremap = true, silent = true}) - vim.api.nvim_command('n', 'dc', ':lua require("dap").run_to_cursor()', {noremap = true, silent = true}) - vim.api.nvim_command('n', 'dz', ':lua require("dap").run_last()', {noremap = true, silent = true}) - vim.api.nvim_command('n', '', ':lua require("dap").step_over()', {noremap = true, silent = true}) - vim.api.nvim_command('n', 'dv', ':lua require("dap").step_over()', {noremap = true, silent = true}) - vim.api.nvim_command('n', '', ':lua require("dap").step_into()', {noremap = true, silent = true}) - vim.api.nvim_command('n', 'di', ':lua require("dap").step_into()', {noremap = true, silent = true}) - vim.api.nvim_command('n', '', ':lua require("dap").step_out()', {noremap = true, silent = true}) - vim.api.nvim_command('n', 'do', ':lua require("dap").step_out()', {noremap = true, silent = true}) - vim.api.nvim_command('n', 'dr', ':lua require("dap").repl.open()', {noremap = true, silent = true}) -end - -function M.dapui_conf() - local dap, dapui = require('dap'), require('dapui') - dap.listeners.after.event_initialized['dapui_config'] = function() dapui.open() end - dap.listeners.before.event_terminated['dapui_config'] = function() dapui.close() end - dap.listeners.before.event_exited['dapui_config'] = function() dapui.close() end - - require('dapui').setup { - icons = {expanded = '', collapsed = ''}, - mappings = { - expand = {'', '<2-LeftMouse>'}, - open = 'o', - remove = 'd', - edit = 'e', - repl = 'r' - }, - sidebar = { - elements = { - -- Provide as ID strings or tables with 'id' and 'size' keys - -- 'size' can be float or integer > 1 - {id = 'scopes', size = 0.25}, - {id = 'breakpoints', size = 0.25}, - {id = 'stacks', size = 0.25}, - {id = 'watches', size = 0.25}, - }, - size = 40, - position = 'left' - }, - tray = { - elements = {'repl'}, - size = 10, - position = 'bottom' - }, - floating = { - max_height = nil, -- These can be integers or a float between 0 and 1. - max_width = nil, -- Floats will be treated as percentage of your screen. - border = 'single', - mappings = { - close = {'q', ''} - } - }, - windows = {indent = 1} - } - - -- Mappings - vim.api.nvim_set_keymap('n', 'de', ':lua require("dapui").eval()', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('v', 'de', ':lua require("dapui").eval()', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'df', ':lua require("dapui").float_element()', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'dt', ':lua require("dapui").toggle()', {noremap = true, silent = true}) -end - -return M diff --git a/roles/nvim/files/nvim/lua/modules/lsp/config.lua b/roles/nvim/files/nvim/lua/modules/lsp/config.lua new file mode 100644 index 0000000..0cd5104 --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/lsp/config.lua @@ -0,0 +1,258 @@ +local M = {} + +function M.signature() + require('lsp_signature').setup { + bind = true, -- This is mandatory, otherwise border config doesn't work + floating_window = true, + fix_pos = true, + hint_enable = false, + hint_prefix = ' ', + hint_scheme = 'String', + hi_parameter = 'Visual', + transparency = 5, + handler_opts = {border = 'single'}, + zindex = 50, -- set to 200 to make the float window on top of others + toggle_key = '' + } +end + +function M.saga() + require('lspsaga').init_lsp_saga { + debug = false, + use_saga_diagnostic_sign = true, + -- diagnostic sign + error_sign = '', + warn_sign = '', + hint_sign = '', + infor_sign = '', + dianostic_header_icon = '  ', + -- code action title icon + code_action_icon = ' ', + code_action_prompt = { + enable = false, + sign = true, + sign_priority = 40, + virtual_text = true + }, + finder_definition_icon = ' ', + finder_reference_icon = ' ', + max_preview_lines = 10, + finder_action_keys = { + open = 'o', + vsplit = 's', + split = 'i', + quit = 'q', + scroll_down = '', + scroll_up = '' + }, + code_action_keys = { + quit = 'q', + exec = '' + }, + rename_action_keys = { + quit = '', + exec = '' + }, + definition_preview_icon = ' ', + border_style = 'single', + rename_prompt_prefix = '', + server_filetype_map = {} + } +end + +function M.lsp() + require('modules.lsp.lsp_conf') +end + +function M.null_ls() + require('modules.lsp.null_ls_conf') +end + +function M.sqls() + require('sqls').setup { + picker = 'telescope' + } +end + +function M.trouble() + require('trouble').setup { + mode = 'lsp_workspace_diagnostics', + fold_open = ' ', + fold_closed = '', + action_keys = { + open_split = {''}, + open_vsplit = {''}, + open_tab = {''} + }, + signs = { + error = '', + warning = '', + information = '', + hint = '', + other = '' + } + } +end + +function M.todo_comments() + require('todo-comments').setup { + signs = false, + -- sign_priority = 8, + keywords = { + FIX = { + icon = ' ', -- icon used for the sign, and in search results + color = 'error', -- can be a hex color, or a named color (see below) + alt = {'FIXME', 'BUG', 'FIXIT', 'ISSUE'}, -- a set of other keywords that all map to this FIX keywords + -- signs = false, -- configure signs for some keywords individually + }, + TODO = {icon = ' ', color = 'info'}, + HACK = {icon = ' ', color = 'warning'}, + WARN = {icon = ' ', color = 'warning', alt = {'WARNING', 'XXX'}}, + PERF = {icon = ' ', alt = {'OPTIM', 'PERFORMANCE', 'OPTIMIZE'}}, + NOTE = {icon = ' ', color = 'hint', alt = {'INFO'}}, + }, + merge_keywords = true, + highlight = { + before = '', -- 'fg' or 'bg' or empty + keyword = 'fg', -- 'fg', 'bg', 'wide' or empty. (wide is the same as bg, but will also highlight surrounding characters) + after = '', -- 'fg' or 'bg' or empty + pattern = [[.*<(KEYWORDS)\s*:]], -- pattern or table of patterns, used for highlightng (vim regex) + comments_only = true, -- uses treesitter to match keywords in comments only + max_line_len = 400, -- ignore lines longer than this + exclude = {'org'} -- list of file types to exclude highlighting + }, + colors = { + error = {'LspDiagnosticsDefaultError', 'TSDanger', '#bf616a', '#e06c75'}, + warning = {'LspDiagnosticsDefaultWarning', 'TSWarning', '#ebcb8b', '#e5c07b'}, + info = {'LspDiagnosticsDefaultInformation', 'TSNote', '#81a1c1', '#61afef'}, + hint = {'LspDiagnosticsDefaultHint', '#88c0d0', '#56b6c2'}, + default = {'Normal', '#d8dee9', '#abb2bf'} + }, + search = { + command = 'rg', + args = { + '--hidden', + '--color=never', + '--no-heading', + '--with-filename', + '--line-number', + '--column', + }, + -- regex that will be used to match keywords. + -- don't replace the (KEYWORDS) placeholder + pattern = [[\b(KEYWORDS):]] -- ripgrep regex + -- pattern = [[\b(KEYWORDS)\b]] -- match without the extra colon. You'll likely get false positives + } + } +end + +function M.symbols_outline() + vim.g.symbols_outline = { + highlight_hovered_item = false, + show_guides = true, + auto_preview = true, + position = 'right', + width = 30, + show_numbers = false, + show_relative_numbers = false, + show_symbol_details = true, + preview_bg_highlight = 'NormalFloat', + keymaps = { -- Can be string or a table + close = {'', 'q'}, + goto_location = '', + focus_location = 'o', + hover_symbol = '', + toggle_preview = 'K', + rename_symbol = 'r', + code_actions = 'a', + }, + lsp_blacklist = {}, + symbol_blacklist = {}, + symbols = { + File = {icon = '', hl = 'TSURI'}, + Module = {icon = '', hl = 'TSNamespace'}, + Namespace = {icon = '', hl = 'TSNamespace'}, + Package = {icon = '', hl = 'TSNamespace'}, + Class = {icon = '𝓒', hl = 'TSType'}, + Method = {icon = 'ƒ', hl = 'TSMethod'}, + Property = {icon = '', hl = 'TSMethod'}, + Field = {icon = '', hl = 'TSField'}, + Constructor = {icon = '', hl = 'TSConstructor'}, + Enum = {icon = 'ℰ', hl = 'TSType'}, + Interface = {icon = 'ﰮ', hl = 'TSType'}, + Function = {icon = '', hl = 'TSFunction'}, + Variable = {icon = '', hl = 'TSConstant'}, + Constant = {icon = '', hl = 'TSConstant'}, + String = {icon = '𝓐', hl = 'TSString'}, + Number = {icon = '#', hl = 'TSNumber'}, + Boolean = {icon = '⊨', hl = 'TSBoolean'}, + Array = {icon = '', hl = 'TSConstant'}, + Object = {icon = '⦿', hl = 'TSType'}, + Key = {icon = '🔐', hl = 'TSType'}, + Null = {icon = 'NULL', hl = 'TSType'}, + EnumMember = {icon = '', hl = 'TSField'}, + Struct = {icon = '𝓢', hl = 'TSType'}, + Event = {icon = '🗲', hl = 'TSType'}, + Operator = {icon = '+', hl = 'TSOperator'}, + TypeParameter = {icon = '𝙏', hl = 'TSParameter'} + } + } +end + +function M.dap() + local dap = require('dap') + vim.fn.sign_define('DapBreakpoint', {text='', texthl='DapSignDefault'}) + vim.fn.sign_define('DapLogPoint', {text='', texthl='DapSignDefault'}) + vim.fn.sign_define('DapStopped', {text='ﱢ', texthl='DapSignDefault'}) + vim.fn.sign_define('DapBreakpointRejected', {text='', texthl='DapSignRejected'}) + + require('mappings').dap() +end + +function M.dapui() + local dap, dapui = require('dap'), require('dapui') + dap.listeners.after.event_initialized['dapui_config'] = function() dapui.open() end + dap.listeners.before.event_terminated['dapui_config'] = function() dapui.close() end + dap.listeners.before.event_exited['dapui_config'] = function() dapui.close() end + + require('dapui').setup { + icons = {expanded = '', collapsed = ''}, + mappings = { + expand = {'', '<2-LeftMouse>'}, + open = 'o', + remove = 'd', + edit = 'e', + repl = 'r' + }, + sidebar = { + elements = { + -- Provide as ID strings or tables with 'id' and 'size' keys + -- 'size' can be float or integer > 1 + {id = 'scopes', size = 0.25}, + {id = 'breakpoints', size = 0.25}, + {id = 'stacks', size = 0.25}, + {id = 'watches', size = 0.25}, + }, + size = 40, + position = 'left' + }, + tray = { + elements = {'repl'}, + size = 10, + position = 'bottom' + }, + floating = { + max_height = nil, -- These can be integers or a float between 0 and 1. + max_width = nil, -- Floats will be treated as percentage of your screen. + border = 'single', + mappings = { + close = {'q', ''} + } + }, + windows = {indent = 1} + } + + require('mappings').dapui() +end + +return M diff --git a/roles/nvim/files/nvim/lua/modules/lsp/lsp_conf.lua b/roles/nvim/files/nvim/lua/modules/lsp/lsp_conf.lua new file mode 100644 index 0000000..93dd935 --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/lsp/lsp_conf.lua @@ -0,0 +1,240 @@ +local servers_path = vim.fn.stdpath('data') .. '/lsp' +local lspconf = require('lspconfig') +local util = require('modules.lsp.util') +local on_attach = util.common_on_attach +local capabilities = util.common_capabilities() + +util.setup_handlers() + +lspconf.clangd.setup { + filetypes = {'c', 'cpp'}, + init_options = { + usePlaceholders = true, + completeUnimported = true, + clangdFileStatus = true + }, + cmd = { + 'clangd', + '-j=2', + '--background-index', + '--clang-tidy', + '--completion-style=detailed', + '--pch-storage=memory', + '--header-insertion=iwyu', + '--header-insertion-decorators' + }, + on_attach = on_attach, + capabilities = capabilities +} + +lspconf.sumneko_lua.setup { + cmd = { + servers_path .. '/sumneko_lua/bin/Linux/lua-language-server', + '-E', '-e', 'LANG=en', + servers_path .. '/sumneko_lua/main.lua' + }, + on_attach = on_attach, + capabilities = capabilities, + settings = { + Lua = { + diagnostics = {globals = {'vim'}}, + runtime = {version = 'LuaJIT', path = util.lua_runtime_path()}, + workspace = { + library = util.lua_lib_path(), + maxPreload = 1000, + preloadFileSize = 150 + }, + completion = {callSnippet = 'Replace'}, + hint = {enable = true}, + telemetry = {enable = false} + } + } +} + +lspconf.pylsp.setup { + cmd = {vim.fn.stdpath('config') .. '/scripts/pylsp'}, + on_attach = on_attach, + capabilities = capabilities, + settings = { + pylsp = { + -- configurationSources = {'pycodestyle', 'flake8'}, + plugins = { + -- flake8 = { + -- enabled = true, + -- executable = servers_path .. 'pylsp/venv/bin/flake8' + -- }, + mccabe = { + enabled = true, + threshold = 15 + }, + pycodestyle = {enabled = true}, + -- pydocstyle = {enabled = true}, + pyflakes = {enabled = true}, + -- pylint = { + -- enabled = true, + -- executable = servers_path .. 'pylsp/venv/bin/pylint' + -- }, + rope_completion = { + enabled = true, + eager = false + }, + yapf = {enabled = true} + } + } + } +} + +lspconf.gopls.setup { + cmd = {servers_path .. '/gopls/gopls', '--remote=auto'}, + on_attach = on_attach, + capabilities = capabilities, + init_options = { + usePlaceholders = true, + completeUnimported = true + } +} + +-- lspconf.yamlls.setup { +-- cmd = {servers_path .. '/yamlls/node_modules/.bin/yaml-language-server', '--stdio'}, +-- on_attach = on_attach, +-- capabilities = capabilities, +-- settings = { +-- redhat = {telemetry = {enabled = false}}, +-- yaml = { +-- format = { +-- bracketSpacing = true, +-- printWidth = 80, +-- -- proseWrap = 'always', -- default is 'preserve' +-- -- singleQuote = true, +-- -- editor.formatOnType = true +-- }, +-- schemas = require('schemastore').json.schemas() +-- } +-- } +-- } + +lspconf.ansiblels.setup { + cmd = {'node', servers_path .. '/ansiblels/out/server/src/server.js', '--stdio'}, + on_attach = on_attach, + capabilities = capabilities, + settings = { + ansible = { + python = {interpreterPath = 'python3'}, + executionEnvironment = {enabled = false} + } + } +} + +-- lspconf.tailwindcss.setup { +-- cmd = {servers_path .. '/tailwindcss/node_modules/.bin/tailwindcss-language-server', '--stdio'}, +-- on_attach = on_attach, +-- capabilities = capabilities, +-- settings = { +-- tailwindCSS = { +-- emmetCompletions = true +-- } +-- } +-- } + +lspconf.emmet_ls.setup { + cmd = {servers_path .. '/emmet_ls/node_modules/.bin/emmet-ls', '--stdio'}, + capabilities = capabilities, + filetypes = { + 'html', 'xml', 'css', 'scss', 'sass', + 'javascript', 'javascriptreact' + }, +} + +lspconf.eslint.setup { + cmd = {servers_path .. '/vscode/node_modules/.bin/vscode-eslint-language-server', '--stdio'}, + on_attach = on_attach, + capabilities = capabilities, + filetypes = {'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'vue', 'svelte'}, + handlers = { + ['eslint/noConfig'] = function() + vim.notify('Unable to parse ESLint config.', vim.log.levels.WARN) + end + }, + settings = { + codeAction = { + disableRuleComment = { + enable = true, + location = 'separateLine' + }, + showDocumentation = {enable = true} + }, + codeActionOnSave = { + enable = false, -- run ':EslintFixAll' manually + mode = 'all' + }, + format = true, + nodePath = '', + onIgnoredFiles = 'off', + packageManager = 'npm', + quiet = false, + rulesCustomizations = {}, + run = 'onType', + useESLintClass = false, + validate = 'on', + workingDirectory = {mode = 'auto'} + } +} + +lspconf.jsonls.setup { + cmd = {servers_path .. '/vscode/node_modules/.bin/vscode-json-language-server', '--stdio'}, + on_attach = on_attach, + capabilities = capabilities, + settings = { + json = { + -- Schema catalog: https://www.schemastore.org/api/json/catalog.json + schemas = require('schemastore').json.schemas() + } + } +} + +lspconf.rust_analyzer.setup { + on_attach = on_attach, + capabilities = capabilities, + settings = { + ['rust-analyzer'] = { + checkOnSave = { + enable = true, + command = 'clippy' + }, + callInfo = {full = true}, + lens = { + enable = true, + references = true, + implementations = true, + enumVariantReferences = true, + methodReferences = true + }, + inlayHints = { + enable = true, + typeHints = true, + parameterHints = true + }, + hoverActions = {enable = true}, + cargo = {autoreload = true} + } + } +} + +local servers = { + sqls = {servers_path .. '/sqls/sqls'}, + cmake = {servers_path .. '/cmake/venv/bin/cmake-language-server'}, + -- bashls = {servers_path .. '/bashls/node_modules/.bin/bash-language-server', 'start'}, + -- dockerls = {servers_path .. '/dockerls/node_modules/.bin/docker-langserver', '--stdio'}, + html = {servers_path .. '/vscode/node_modules/.bin/vscode-html-language-server', '--stdio'}, + cssls = {servers_path .. '/vscode/node_modules/.bin/vscode-css-language-server', '--stdio'}, + -- vimls = {servers_path .. '/vimls/node_modules/.bin/vim-language-server', '--stdio'}, + tsserver = {servers_path .. '/tsserver/node_modules/.bin/typescript-language-server', '--stdio'} +} + +for server, _ in pairs(servers) do + lspconf[server].setup { + cmd = servers[server], + on_attach = on_attach, + capabilities = capabilities + } +end diff --git a/roles/nvim/files/nvim/lua/modules/lsp/null_ls_conf.lua b/roles/nvim/files/nvim/lua/modules/lsp/null_ls_conf.lua new file mode 100644 index 0000000..b60f3ab --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/lsp/null_ls_conf.lua @@ -0,0 +1,81 @@ +-- TODO: installers for the rest +local linters_path = vim.fn.stdpath('data') .. '/lint' +local null_ls = require('null-ls') +local lspconf = require('lspconfig') +local on_attach = require('modules.lsp.util').common_on_attach + +local sources = { + -- null_ls.builtins.formatting.codespell.with { + -- command = linters_path .. '/codespell/venv/bin/codespell' + -- }, + null_ls.builtins.formatting.clang_format.with { + filetypes = {'c', 'cpp'} + }, + null_ls.builtins.formatting.cmake_format.with { + command = linters_path .. '/cmake_format/venv/bin/cmake-format' + }, + null_ls.builtins.formatting.fish_indent, + -- null_ls.builtins.formatting.fixjson.with {command = 'fixjson'}, + -- null_ls.builtins.formatting.fnlfmt.with {command = 'fnlfmt'}, + -- null_ls.builtins.formatting.goimports.with {command = 'goimports'}, + -- null_ls.builtins.formatting.gofmt.with {command = 'gofmt'}, + -- null_ls.builtins.formatting.nixfmt.with {command = 'nixfmt'}, + -- null_ls.builtins.formatting.prettier.with { + -- command = linters_path .. '/prettier/node_modules/.bin/prettier' + -- }, + -- null_ls.builtins.formatting.rustfmt.with {command = 'rustfmt'}, + -- null_ls.builtins.formatting.rustywind.with {command = 'rustywind'}, + -- null_ls.builtins.formatting.shfmt.with { + -- command = linters_path .. '/shfmt/shfmt' + -- }, + null_ls.builtins.formatting.stylua.with { + condition = function(utils) + return utils.root_has_file('stylua.toml') + end + }, + -- null_ls.builtins.formatting.uncrustify.with {command = 'uncrustify'}, + -- null_ls.builtins.formatting.stylelint.with { + -- command = linters_path .. '/stylelint/node_modules/.bin/stylelint' + -- }, + null_ls.builtins.diagnostics.shellcheck, + null_ls.builtins.diagnostics.codespell.with { + command = linters_path .. '/codespell/venv/bin/codespell' + }, + -- null_ls.builtins.diagnostics.cspell.with { + -- command = linters_path .. '/cspell/node_modules/.bin/cspell', + -- filetypes = {'tex', 'markdown', 'org'} + -- }, + null_ls.builtins.diagnostics.hadolint.with { + command = vim.fn.stdpath('config') .. '/scripts/hadolint', + args = {'$FILENAME'} + }, + -- null_ls.builtins.diagnostics.luacheck, + null_ls.builtins.diagnostics.cppcheck, + null_ls.builtins.diagnostics.write_good.with { + command = linters_path .. '/write_good/node_modules/.bin/write-good' + }, + null_ls.builtins.diagnostics.markdownlint.with { + command = linters_path .. '/markdownlint/node_modules/.bin/markdownlint' + }, + null_ls.builtins.diagnostics.qmllint, + null_ls.builtins.diagnostics.selene.with { + condition = function(utils) + return utils.root_has_file('selene.toml') + end + }, + -- null_ls.builtins.diagnostics.vale.with { + -- command = linters_path .. '/vale/vale' + -- }, + null_ls.builtins.diagnostics.vint.with { + command = linters_path .. '/vint/venv/bin/vint' + }, + -- null_ls.builtins.diagnostics.stylelint.with { + -- command = linters_path .. '/stylelint/node_modules/.bin/stylelint' + -- }, + null_ls.builtins.hover.dictionary -- get word definition from dictionaryapi.dev +} + +null_ls.config {sources = sources} +lspconf['null-ls'].setup { + on_attach = on_attach +} diff --git a/roles/nvim/files/nvim/lua/modules/lsp/plugins.lua b/roles/nvim/files/nvim/lua/modules/lsp/plugins.lua new file mode 100644 index 0000000..40df553 --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/lsp/plugins.lua @@ -0,0 +1,57 @@ +local M = {} +local conf = require('modules.lsp.config') + +M['neovim/nvim-lspconfig'] = { + event = 'BufReadPre', + wants = {'lsp_signature.nvim', 'lspsaga.nvim', 'SchemaStore.nvim'}, + requires = { + { + 'ray-x/lsp_signature.nvim', + config = conf.signature, + opt = true + }, + { + 'tami5/lspsaga.nvim', + branch = 'nvim51', + config = conf.saga, + opt = true + }, + {'b0o/SchemaStore.nvim', opt = true} + }, + config = conf.lsp +} +M['jose-elias-alvarez/null-ls.nvim'] = { + wants = 'plenary.nvim', + after = 'nvim-lspconfig', + config = conf.null_ls +} +M['nanotee/sqls.nvim'] = { + ft = {'sql', 'mysql'}, + wants = 'nvim-lspconfig', + config = conf.sqls +} +M['folke/trouble.nvim'] = { + cmd = {'Trouble', 'TroubleToggle', 'TroubleRefresh'}, + config = conf.trouble +} +M['folke/todo-comments.nvim'] = { + wants = 'plenary.nvim', + event = 'BufRead', + config = conf.todo_comments +} +M['simrat39/symbols-outline.nvim'] = { + cmd = {'SymbolsOutline', 'SymbolsOutlineOpen'}, + setup = conf.symbols_outline +} +M['rcarriga/nvim-dap-ui'] = { -- TODO: config, scripts to install/update dap servers + keys = 'd', + wants = 'nvim-dap', + requires = {{ + 'mfussenegger/nvim-dap', + config = conf.dap, + opt = true + }}, + config = conf.dapui +} + +return M diff --git a/roles/nvim/files/nvim/lua/modules/lsp/util.lua b/roles/nvim/files/nvim/lua/modules/lsp/util.lua new file mode 100644 index 0000000..7789926 --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/lsp/util.lua @@ -0,0 +1,218 @@ +local M = {} +local wk = require('which-key') + +local function setup_mappings(bufnr) + local lsp_mappings = { + g = { + d = {':lua vim.lsp.buf.definition()', 'Goto definition'}, + D = {':lua vim.lsp.buf.declaration()', 'Goto declaration'}, + i = {':Lspsaga implement', 'Implementations'}, + I = {':Telescope lsp_implementations', 'Implementations (Telescope)'}, + r = {':TroubleToggle lsp_references', 'References'}, + R = {':Telescope lsp_references', 'References (Telescope)'} + }, + K = {':Lspsaga hover_doc', 'Hover doc'}, + ['[d'] = {':Lspsaga diagnostic_jump_prev', 'Previous diagnostics'}, + [']d'] = {':Lspsaga diagnostic_jump_next', 'Next diagnostics'} + } + local lsp_leader_mappings = { + l = { + name = 'LSP', + a = {':lua vim.lsp.buf.add_workspace_folder()', 'Add workspace folder'}, + b = {':TroubleToggle lsp_document_diagnostics', 'Buffer diagnostics'}, + B = {':Telescope lsp_document_diagnostics', 'Buffer diagnostics (Telescope)'}, + c = {':Lspsaga code_action', 'Code action'}, + C = {':Telescope lsp_code_actions', 'Code action (Telescope)'}, + d = {':TroubleToggle lsp_definitions', 'Definitions'}, + D = {':Telescope lsp_definitions', 'Definitions (Telescope)'}, + e = {':Lspsaga show_line_diagnostics', 'Line diagnostics'}, + f = {':Lspsaga lsp_finder', 'Finder'}, + g = {':SymbolsOutline', 'Symbol outline'}, + i = {':LspInfo', 'Lsp info'}, + l = {':TroubleToggle loclist', 'Diagnostics loclist'}, + n = {':Lspsaga rename', 'Rename'}, + p = {':Lspsaga preview_definition', 'Preview definition'}, + r = {':lua vim.lsp.buf.remove_workspace_folder()', 'Remove workspace folder'}, + s = {':Telescope lsp_document_symbols', 'Buffer symbols'}, + S = {':Telescope lsp_workspace_symbols', 'Workspace symbols'}, + t = {':TroubleToggle', 'Toggle Trouble'}, + w = {':TroubleToggle lsp_workspace_diagnostics', 'Workspace diagnostics'}, + W = {':Telescope lsp_workspace_diagnostics', 'Workspace diagnostics (Telescope)'}, + x = {':lua vim.lsp.buf.signature_help()', 'Signature help'}, + y = {':lua vim.notify(vim.inspect(vim.lsp.buf.list_workspace_folders()), vim.log.levels.INFO)', 'List workspace folders'} + } + } + local lsp_visual_mappings = { + l = { + name = 'LSP', + c = {':Lspsaga range_code_action', 'Range code action'}, + C = {':Telescope lsp_range_code_actions', 'Range code action (Telescope)'} + } + } + + wk.register(lsp_mappings, {buffer = bufnr}) + wk.register(lsp_leader_mappings, {buffer = bufnr, prefix = ''}) + wk.register(lsp_visual_mappings, {buffer = bufnr, prefix = '', mode = 'v'}) + + local opts = {noremap = true, silent = true} + vim.api.nvim_buf_set_keymap(bufnr, 'n', '', ':lua require("lspsaga.action").smart_scroll_with_saga(1)', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', '', ':lua require("lspsaga.action").smart_scroll_with_saga(-1)', opts) +end + +local function setup_formatting_mapping(client, bufnr) + if client.resolved_capabilities.document_formatting then + wk.register({ + ['lo'] = {':lua vim.lsp.buf.formatting()', 'Format buffer'} + }, {buffer = bufnr, prefix = ''}) + -- vim.api.nvim_command('autocmd BufWritePre lua vim.lsp.buf.formatting_sync()') + elseif client.resolved_capabilities.document_range_formatting then + wk.register({ + ['lo'] = {':lua vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0})', 'Format buffer'} + }, {buffer = bufnr, prefix = ''}) + wk.register({ + ['lo'] = {':lua vim.lsp.buf.range_formatting()', 'Format range'} + }, {buffer = bufnr, prefix = '', mode = 'v'}) + -- vim.api.nvim_command('autocmd BufWritePre lua vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0})') + end +end + +local function setup_document_highlight(client) + if client.resolved_capabilities.document_highlight then + vim.api.nvim_exec( + [[ + augroup lsp_document_highlight + autocmd! * + autocmd CursorHold lua vim.lsp.buf.document_highlight() + autocmd CursorMoved lua vim.lsp.buf.clear_references() + augroup END + ]], + false + ) + end +end + +local function setup_codelens(client) + if client.resolved_capabilities.code_lens then + vim.api.nvim_exec( + [[ + augroup lsp_code_lens_refresh + autocmd! * + autocmd InsertLeave lua vim.lsp.codelens.refresh() + autocmd InsertLeave lua vim.lsp.codelens.display() + augroup END + ]], + false + ) + end +end + +function M.common_on_attach(client, bufnr) + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + setup_mappings(bufnr) + setup_codelens(client) + setup_document_highlight(client) + setup_formatting_mapping(client, bufnr) +end + +function M.common_capabilities() + local capabilities = vim.lsp.protocol.make_client_capabilities() + -- Add additional capabilities supported by nvim-cmp + local completionItem = capabilities.textDocument.completion.completionItem + completionItem.documentationFormat = {'markdown', 'plaintext'} + completionItem.snippetSupport = true + completionItem.preselectSupport = true + completionItem.insertReplaceSupport = true + completionItem.labelDetailsSupport = true + completionItem.deprecatedSupport = true + completionItem.commitCharactersSupport = true + completionItem.tagSupport = {valueSet = {1}} + completionItem.resolveSupport = { + properties = { + 'documentation', + 'detail', + 'additionalTextEdits', + } + } + + return capabilities +end + +function M.setup_handlers() + local border = { + {'┌', 'FloatBorder'}, + {'─', 'FloatBorder'}, + {'┐', 'FloatBorder'}, + {'│', 'FloatBorder'}, + {'┘', 'FloatBorder'}, + {'─', 'FloatBorder'}, + {'└', 'FloatBorder'}, + {'│', 'FloatBorder'} + } + + vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + underline = false, + virtual_text = { + prefix = '■', + source = 'always' + }, + signs = { + active = true, + values = { + {name = 'LspDiagnosticsSignError', text = ''}, + {name = 'LspDiagnosticsSignWarning', text = ''}, + {name = 'LspDiagnosticsSignInformation', text = ''}, + {name = 'LspDiagnosticsSignHint', text = ''} + } + }, + update_in_insert = false, + severity_sort = true + }) + + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { + border = border, + }) + + vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = border, + }) +end + +function M.lua_lib_path() + local lib_path = {} + + -- lib_path[vim.fn.expand('~/.luarocks/share/lua/5.3')] = true + -- lib_path[vim.fn.expand('/usr/share/lua/5.3')] = true + lib_path[os.getenv('VIMRUNTIME') .. '/lua'] = true + -- local function add(lib) + -- for _, p in pairs(vim.fn.expand(lib .. '/lua', false, true)) do + -- p = vim.loop.fs_realpath(p) + -- if p then lib_path[p] = true end + -- end + -- end + -- for _, site in pairs(vim.split(vim.opt.packpath:get(), ',')) do + -- add(site .. '/pack/*/opt/*') + -- add(site .. '/pack/*/start/*') + -- end + + return lib_path +end + +function M.lua_runtime_path() + local lib_path = M.lua_lib_path() + local runtime_path = {} + + table.insert(runtime_path, 'lua/?.lua') + table.insert(runtime_path, 'lua/?/init.lua') + -- table.insert(runtime_path, '?.lua') + -- table.insert(runtime_path, '?/?.lua') + -- table.insert(runtime_path, '?/init.lua') + + for lib, _ in pairs(lib_path) do + table.insert(runtime_path, lib .. '/?.lua') + table.insert(runtime_path, lib .. '/?/init.lua') + end + + return runtime_path +end + +return M diff --git a/roles/nvim/files/nvim/lua/modules/tools.lua b/roles/nvim/files/nvim/lua/modules/tools/config.lua similarity index 65% rename from roles/nvim/files/nvim/lua/modules/tools.lua rename to roles/nvim/files/nvim/lua/modules/tools/config.lua index 1185714..8d0c645 100644 --- a/roles/nvim/files/nvim/lua/modules/tools.lua +++ b/roles/nvim/files/nvim/lua/modules/tools/config.lua @@ -1,6 +1,6 @@ local M = {} -function M.telescope_conf() +function M.telescope() local telescope = require('telescope') telescope.setup { @@ -53,21 +53,18 @@ function M.telescope_conf() -- wrap lines inside preview pane vim.api.nvim_command('autocmd User TelescopePreviewerLoaded setlocal wrap') - -- Mappings for telescope-symbols.nvim - vim.api.nvim_set_keymap('n', 'fjg', ':lua require("telescope.builtin").symbols{sources = {"gitmoji"}, prompt_title = "Gitmoji"}', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'fjj', ':lua require("telescope.builtin").symbols{sources = {"emoji"}, prompt_title = "Emoji"}', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'fjk', ':lua require("telescope.builtin").symbols{sources = {"kaomoji"}, prompt_title = "Kaomoji"}', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'fjl', ':lua require("telescope.builtin").symbols{sources = {"julia"}, prompt_title = "Julia symbols"}', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'fjm', ':lua require("telescope.builtin").symbols{sources = {"math"}, prompt_title = "Math symbols"}', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'fjn', ':lua require("telescope.builtin").symbols{sources = {"nerd"}, prompt_title = "Nerd-fonts symbols"}', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'fjt', ':lua require("telescope.builtin").symbols{sources = {"latex"}, prompt_title = "Latex symbols"}', {noremap = true, silent = true}) + require('mappings').telescope_symbols() end -function M.octo_conf() +function M.octo() require('octo').setup() end -function M.neogit_conf() +function M.diffview() + require('diffview').setup {diff_binaries = true} +end + +function M.neogit() require('neogit').setup { integrations = { diffview = true @@ -75,11 +72,7 @@ function M.neogit_conf() } end -function M.diffview_conf() - require('diffview').setup {diff_binaries = true} -end - -function M.yabs_conf() +function M.yabs() require('yabs'):setup { languages = { vim = {tasks = {run = {command = 'source %', type = 'vim'}}}, @@ -126,7 +119,7 @@ function M.yabs_conf() } end -function M.markdown_preview_conf() +function M.markdown_preview() vim.g.mkdp_refresh_slow = 1 vim.g.mkdp_filetypes = { 'markdown', @@ -138,33 +131,12 @@ function M.markdown_preview_conf() -- vim.g.mkdp_echo_preview_url = 1 end -function M.rest_conf() - require('rest-nvim').setup { - -- Open request results in a horizontal split - result_split_horizontal = false, - -- Skip SSL verification, useful for unknown certificates - skip_ssl_verification = false, - -- Highlight request on run - highlight = { - enabled = true, - timeout = 150, - }, - -- Jump to request line on run - jump_to_request = false, - } -end - -function M.spectre_conf() +function M.spectre() require('spectre').setup() - - -- Mappings - vim.api.nvim_set_keymap('n', 'po', ':lua require("spectre").open()', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'pp', 'viw:lua require("spectre").open_file_search()', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'pw', ':lua require("spectre").open_visual({select_word = true})', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('v', 'p', ':lua require("spectre").open_visual()', {noremap = true, silent = true}) + require('mappings').spectre() end -function M.translate_conf() +function M.translate_shell() vim.g.trans_join_lines = 1 vim.g.trans_win_height = 15 vim.g.trans_default_direction = ':ja' @@ -181,7 +153,7 @@ function M.translate_conf() } end -function M.undotree_conf() +function M.undotree() vim.g.undotree_WindowLayout = 2 vim.g.undotree_SplitWidth = 30 vim.g.undotree_DiffpaneHeight = 10 @@ -189,7 +161,7 @@ function M.undotree_conf() vim.g.undotree_RelativeTimestamp = 1 end -function M.toggleterm_conf() +function M.toggleterm() require('toggleterm').setup { shade_terminals = false, float_opts = { @@ -205,7 +177,7 @@ function M.toggleterm_conf() } end -function M.sniprun_conf() +function M.sniprun() local c = require('themes.' .. vim.g.colors_name .. '.colors') require('sniprun').setup { @@ -237,45 +209,32 @@ function M.sniprun_conf() } end -function M.session_conf() +function M.rest() + require('rest-nvim').setup { + -- Open request results in a horizontal split + result_split_horizontal = false, + -- Skip SSL verification, useful for unknown certificates + skip_ssl_verification = false, + -- Highlight request on run + highlight = { + enabled = true, + timeout = 150, + }, + -- Jump to request line on run + jump_to_request = false, + } +end + +function M.persistence() require('persistence').setup { dir = vim.fn.expand(vim.fn.stdpath('data') .. '/sessions/'), options = {'buffers', 'curdir', 'tabpages', 'winsize'} } - -- Mappings - vim.api.nvim_set_keymap('n', 'ss', ':lua require("persistence").save()', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'sd', ':lua require("persistence").stop()', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'sl', ':lua require("persistence").load({last = true})', {noremap = true, silent = true}) - vim.api.nvim_set_keymap('n', 'sr', ':lua require("persistence").load()', {noremap = true, silent = true}) + require('mappings').persistence() end -function M.filetype_conf() - require('filetype').setup { - overrides = { - extensions = { - md = 'markdown', - mkd = 'markdown', - toml = 'toml', - rasi = 'css', - vifm = 'vim', - log = 'log', - LO = 'log' - }, - literal = { - vifmrc = 'vim' - }, - complex = { - ['*_log'] = 'log', - ['G*_LOG'] = 'log', - ['.*waybar/config'] = 'jsonc', - ['.*lf/lfrc'] = 'sh' - } - } - } -end - -function M.closebuf_conf() +function M.close_buffers() require('close_buffers').setup { preserve_window_layout = {'this'}, next_buffer_cmd = function(windows) @@ -289,7 +248,7 @@ function M.closebuf_conf() } end -function M.winshift_conf() +function M.winshift() require('winshift').setup { highlight_moving_win = true, -- Highlight the window being moved focused_hl_group = 'Visual', -- The highlight group used for the moving window @@ -304,7 +263,7 @@ function M.winshift_conf() } end -function M.winpicker_conf() +function M.window_picker() require('window-picker').setup { keys = 'alskdjfhgwoeiruty', -- Swap windows by holding shift + letter @@ -315,36 +274,10 @@ function M.winpicker_conf() } end -function M.distant_conf() +function M.distant() require('distant').setup { ['*'] = require('distant.settings').chip_default() } end -function M.notify_conf() - require('notify').setup { - -- Animation style (see below for details) - stages = 'fade_in_slide_out', - -- Function called when a new window is opened, use for changing win settings/config - on_open = nil, - -- Render function for notifications. See notify-render() - render = 'default', - -- Default timeout for notifications - timeout = 2000, - -- For stages that change opacity this is treated as the highlight behind the window - -- Set this to either a highlight group or an RGB hex value e.g. '#000000' - background_colour = 'NormalFloat', - -- Minimum width for notification windows - minimum_width = 40, - -- Icons for the different levels - icons = { - ERROR = '', - WARN = '', - INFO = '', - DEBUG = '', - TRACE = '✎' - } - } -end - return M diff --git a/roles/nvim/files/nvim/lua/modules/tools/plugins.lua b/roles/nvim/files/nvim/lua/modules/tools/plugins.lua new file mode 100644 index 0000000..aba079c --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/tools/plugins.lua @@ -0,0 +1,107 @@ +local M = {} +local conf = require('modules.tools.config') + +M['nvim-telescope/telescope.nvim'] = { -- TODO: check out fzf-lua + keys = 'fj', + cmd = 'Telescope', + wants = { + 'popup.nvim', + 'plenary.nvim', + 'nvim-notify', + 'yabs.nvim', + 'telescope-symbols.nvim', + 'telescope-project.nvim', + 'telescope-fzf-native.nvim' + }, + requires = { + {'FollieHiyuki/telescope-symbols.nvim', opt = true}, + {'nvim-telescope/telescope-project.nvim', opt = true}, + {'nvim-telescope/telescope-fzf-native.nvim', run = 'make', opt = true} + }, + config = conf.telescope +} +M['pwntester/octo.nvim'] = { -- TODO: colors + config + cmd = 'Octo', + wants = 'telescope.nvim', + config = conf.octo +} +M['TimUntersberger/neogit'] = { + cmd = 'Neogit', + wants = {'diffview.nvim', 'plenary.nvim'}, + requires = {{ + 'sindrets/diffview.nvim', + cmd = { + 'DiffviewOpen','DiffviewClose', + 'DiffviewToggleFiles', 'DiffviewFocusFiles' + }, + config = conf.diffview, + opt = true + }}, + config = conf.neogit +} +M['pianocomposer321/yabs.nvim'] = { + cmd = {'YabsTask', 'YabsDefaultTask'}, + config = conf.yabs +} +M['iamcco/markdown-preview.nvim'] = { -- TODO: check out kat0h/bufpreview.vim + run = 'cd app && yarn install', + ft = {'markdown', 'rmd'}, + config = conf.markdown_preview +} +M['turbio/bracey.vim'] = { + run = 'npm install --prefix server', + cmd = 'Bracey' +} +M['windwp/nvim-spectre'] = { + keys = 'p', + wants = 'plenary.nvim', + config = conf.spectre +} +M['echuraev/translate-shell.vim'] = { + cmd = {'Trans', 'TransSelectDirection'}, + config = conf.translate_shell +} +M['mbbill/undotree'] = { + cmd = 'UndotreeToggle', + setup = conf.undotree +} +M['akinsho/toggleterm.nvim'] = { + cmd = 'ToggleTerm', + config = conf.toggleterm +} +M['michaelb/sniprun'] = { + run = 'cargo build --release', + cmd = 'SnipRun', + wants = 'nvim-notify', + config = conf.sniprun +} +M['NTBBloodbath/rest.nvim'] = { + keys = {'RestNvim', 'RestNvimPreview', 'RestNvimLast'}, + wants = {'plenary.nvim', 'nvim-treesitter'}, + config = conf.rest +} +M['folke/persistence.nvim'] = { -- TODO: check out auto-session + session-lens + event = 'BufReadPre', + keys = 's', + config = conf.persistence +} +M['kazhala/close-buffers.nvim'] = { + cmd = {'BDelete', 'BWipeout'}, + wants = 'bufferline.nvim', + config = conf.close_buffers +} +M['sindrets/winshift.nvim'] = { + cmd = 'WinShift', + config = conf.winshift +} +M['ten3roberts/window-picker.nvim'] = { + cmd = {'WindowPick', 'WindowSwap', 'WindowSwapStay'}, + config = conf.window_picker +} +M['chipsenkbeil/distant.nvim'] = { + cmd = {'DistantInstall', 'DistantLaunch'}, + config = conf.distant +} +M['dstein64/vim-startuptime'] = {cmd = 'StartupTime'} -- Just for benchmarking + +return M diff --git a/roles/nvim/files/nvim/lua/modules/ui/components.lua b/roles/nvim/files/nvim/lua/modules/ui/components.lua new file mode 100644 index 0000000..fae3ae4 --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/ui/components.lua @@ -0,0 +1,229 @@ +local M = {} +local colors = require('themes.' .. vim.g.colors_name .. '.colors') +local vi_mode_utils = require('feline.providers.vi_mode') +local lightbulb_present, lightbulb = pcall(require, 'nvim-lightbulb') +-- local gps_present, gps = pcall(require, 'nvim-gps') + +local function file_osinfo() + local os = vim.bo.fileformat:upper() + local icon = {} + if os == 'UNIX' then + icon = ' ' + elseif os == 'MAC' then + icon = ' ' + else + icon = ' ' + end + return icon .. os +end + +local function buffer_not_empty() + if vim.fn.empty(vim.fn.expand('%:t')) ~= 1 then + return true + end + return false +end + +-- Default colors for statusline -- +M['normal_colors'] = {bg = colors.grey1, fg = colors.fg} +M['vi_mode_colors'] = { + NORMAL = colors.green, + OP = colors.green, + INSERT = colors.blue, + VISUAL = colors.yellow, + LINES = colors.yellow, + BLOCK = colors.yellow, + REPLACE = colors.red, + ['V-REPLACE'] = colors.red, + ENTER = colors.cyan, + MORE = colors.cyan, + SELECT = colors.orange, + COMMAND = colors.purple, + SHELL = colors.green, + TERM = colors.green, + NONE = colors.white2 +} + +-- Components -- +M['dummy'] = { + provider = '▊', + hl = {fg = colors.blue}, + right_sep = ' ' +} + +M['vi_mode'] = { + provider = ' ', + hl = function() + return { + name = vi_mode_utils.get_mode_highlight_name(), + fg = vi_mode_utils.get_mode_color() + } + end, + right_sep = ' ' +} + +M['filesize'] = { + provider = 'file_size', + enabled = buffer_not_empty, + hl = {fg = colors.fg, style = 'bold'}, + right_sep = ' ' +} + +M['fileinfo'] = { + provider = { + name = 'file_info', + opts = { + file_modified_icon = ' ', + file_readonly_icon = ' ', + type = 'base-only' -- relative, unique, full-path, short-path, relative-short, unique-short + } + }, + enabled = buffer_not_empty, + hl = {fg = colors.blue, style = 'bold'}, + right_sep = ' ' +} + +M['lineinfo'] = { + provider = 'position', + hl = {fg = colors.fg}, + right_sep = ' ' +} + +M['percent'] = { + provider = 'line_percentage', + hl = {fg = colors.fg, style = 'bold'}, + right_sep = ' ' +} + +-- M['gps'] = { +-- provider = function() +-- return gps.get_location() +-- end, +-- enabled = function() +-- if gps_present then +-- return gps.is_available() +-- else +-- return false +-- end +-- end, +-- hl = {fg = colors.cyan} +-- } + +M['codeact'] = { + provider = function() + return lightbulb.get_status_text() + end, + enabled = function() + return lightbulb_present + end, + hl = {fg = colors.green, style = 'bold'} +} + +M['diagerr'] = { + provider = 'diagnostic_errors', + icon = ' ', + hl = {fg = colors.red}, + left_sep = ' ' +} + +M['diagwarn'] = { + provider = 'diagnostic_warnings', + icon = ' ', + hl = {fg = colors.yellow}, + left_sep = ' ' +} + +M['diaghint'] = { + provider = 'diagnostic_hints', + icon = ' ', + hl = {fg = colors.cyan}, + left_sep = ' ' +} + +M['diaginfo'] = { + provider = 'diagnostic_info', + icon = ' ', + hl = {fg = colors.blue}, + left_sep = ' ' +} + +M['lspclient'] = { + provider = function() + local clients = {} + + -- Typical lsp clients + for _, client in pairs(vim.lsp.buf_get_clients(0)) do + if client.name ~= 'null-ls' then + table.insert(clients, client.name) + end + end + + -- null-ls sources + local null_ls_methods = require('null-ls.methods') + local active_sources = require('null-ls.info').get_active_sources() + + local linter_method = null_ls_methods.internal['DIAGNOSTICS'] + local active_linters = active_sources[linter_method] or {} + vim.list_extend(clients, active_linters) + + local formatter_method = null_ls_methods.internal['FORMATTING'] + local active_formatters = active_sources[formatter_method] or {} + vim.list_extend(clients, active_formatters) + + return table.concat(clients, ', ') + end, + enabled = function() + return next(vim.lsp.buf_get_clients(0)) ~= nil + end, + icon = ' LSP:', + hl = {fg = colors.purple, style = 'bold'}, + left_sep = ' ' +} + +M['format'] = { + provider = file_osinfo, + hl = {fg = colors.cyan}, + left_sep = ' ' +} + +M['encode'] = { + provider = 'file_encoding', + hl = {fg = colors.fg}, + left_sep = ' ' +} + +M['filetype'] = { + provider = 'file_type', + hl = {fg = colors.blue, style = 'bold'}, + left_sep = ' ' +} + +M['gitbranch'] = { + provider = 'git_branch', + icon = ' ', + hl = {fg = colors.green, style = 'bold'}, + left_sep = ' ' +} + +M['diffadd'] = { + provider = 'git_diff_added', + icon = ' ', + hl = {fg = colors.green}, + left_sep = ' ' +} + +M['diffchange'] = { + provider = 'git_diff_changed', + icon = '柳', + hl = {fg = colors.yellow}, + left_sep = ' ' +} + +M['diffremove'] = { + provider = 'git_diff_removed', + icon = ' ', + hl = {fg = colors.red}, + left_sep = ' ' +} + +return M diff --git a/roles/nvim/files/nvim/lua/modules/ui.lua b/roles/nvim/files/nvim/lua/modules/ui/config.lua similarity index 60% rename from roles/nvim/files/nvim/lua/modules/ui.lua rename to roles/nvim/files/nvim/lua/modules/ui/config.lua index 53b5256..1722004 100644 --- a/roles/nvim/files/nvim/lua/modules/ui.lua +++ b/roles/nvim/files/nvim/lua/modules/ui/config.lua @@ -1,6 +1,6 @@ local M = {} -function M.dashboard_conf() +function M.dashboard() local dashboard = require('alpha.themes.dashboard') dashboard.section.header = { @@ -24,14 +24,14 @@ function M.dashboard_conf() dashboard.section.footer = { type = 'text', - val = 'おかえりなさい', + val = '☆*:.。. o(≧▽≦)o .。.:*☆', opts = { position = 'center', hl = 'DashboardFooter' } } - local button = function(sc, txt, keybind, keybind_opts) + dashboard.button = function(sc, txt, keybind, keybind_opts) local sc_ = sc:gsub('%s', ''):gsub('SPC', '') local opts = { @@ -61,6 +61,7 @@ function M.dashboard_conf() } end + local button = dashboard.button dashboard.section.buttons = { type = 'group', val = { @@ -87,195 +88,12 @@ function M.dashboard_conf() } -- Hide tabline in dashboard buffer - vim.api.nvim_command [[ - autocmd FileType alpha set showtabline=0 | autocmd BufUnload set showtabline=2 - ]] + vim.api.nvim_command('autocmd FileType alpha set showtabline=0 | autocmd BufUnload set showtabline=2') end -function M.statusline_conf() - local colors = require('themes.' .. vim.g.colors_name .. '.colors') - - local vi_mode_colors = { - NORMAL = colors.green, - OP = colors.green, - INSERT = colors.blue, - VISUAL = colors.yellow, - LINES = colors.yellow, - BLOCK = colors.yellow, - REPLACE = colors.red, - ['V-REPLACE'] = colors.red, - ENTER = colors.cyan, - MORE = colors.cyan, - SELECT = colors.orange, - COMMAND = colors.purple, - SHELL = colors.green, - TERM = colors.green, - NONE = colors.white2 - } - - local function file_osinfo() - local os = vim.bo.fileformat:upper() - local icon - if os == 'UNIX' then - icon = ' ' - elseif os == 'MAC' then - icon = ' ' - else - icon = ' ' - end - return icon .. os - end - - local function buffer_not_empty() - if vim.fn.empty(vim.fn.expand('%:t')) ~= 1 then - return true - end - return false - end - - local vi_mode_utils = require('feline.providers.vi_mode') - local lightbulb_present, lightbulb = pcall(require, 'nvim-lightbulb') - local gps_present, gps = pcall(require, 'nvim-gps') - - local comps = { - dummy = { - provider = '▊', - hl = {fg = colors.blue}, - right_sep = ' ' - }, - vi_mode = { - provider = ' ', - hl = function() - return { - name = vi_mode_utils.get_mode_highlight_name(), - fg = vi_mode_utils.get_mode_color() - } - end, - right_sep = ' ' - }, - filesize = { - provider = 'file_size', - enabled = buffer_not_empty, - hl = {fg = colors.fg, style = 'bold'}, - right_sep = ' ' - }, - fileinfo = { - provider = { - name = 'file_info', - opts = { - file_modified_icon = ' ', - file_readonly_icon = ' ', - type = 'base-only' -- relative, unique, full-path, short-path, relative-short, unique-short - } - }, - enabled = buffer_not_empty, - hl = {fg = colors.blue, style = 'bold'}, - right_sep = ' ' - }, - lineinfo = { - provider = 'position', - hl = {fg = colors.fg}, - right_sep = ' ' - }, - percent = { - provider = 'line_percentage', - hl = {fg = colors.fg, style = 'bold'}, - right_sep = ' ' - }, - gps = { - provider = function() - return gps.get_location() - end, - enabled = function() - if gps_present then - return gps.is_available() - else - return false - end - end, - hl = {fg = colors.cyan} - }, - codeact = { - provider = function() - return lightbulb.get_status_text() - end, - enabled = function() - return lightbulb_present - end, - hl = {fg = colors.green, style = 'bold'} - }, - diagerr = { - provider = 'diagnostic_errors', - icon = ' ', - hl = {fg = colors.red}, - left_sep = ' ' - }, - diagwarn = { - provider = 'diagnostic_warnings', - icon = ' ', - hl = {fg = colors.yellow}, - left_sep = ' ' - }, - diaghint = { - provider = 'diagnostic_hints', - icon = ' ', - hl = {fg = colors.cyan}, - left_sep = ' ' - }, - diaginfo = { - provider = 'diagnostic_info', - icon = ' ', - hl = {fg = colors.blue}, - left_sep = ' ' - }, - lspclient = { - provider = 'lsp_client_names', - icon = ' LSP:', - hl = {fg = colors.purple, style = 'bold'}, - left_sep = ' ' - }, - format = { - provider = file_osinfo, - hl = {fg = colors.cyan}, - left_sep = ' ' - }, - encode = { - provider = 'file_encoding', - hl = {fg = colors.fg}, - left_sep = ' ' - }, - filetype = { - provider = 'file_type', - hl = {fg = colors.blue, style = 'bold'}, - left_sep = ' ' - }, - gitbranch = { - provider = 'git_branch', - icon = ' ', - hl = {fg = colors.green, style = 'bold'}, - left_sep = ' ' - }, - diffadd = { - provider = 'git_diff_added', - icon = ' ', - hl = {fg = colors.green}, - left_sep = ' ' - }, - diffchange = { - provider = 'git_diff_changed', - icon = '柳', - hl = {fg = colors.yellow}, - left_sep = ' ' - }, - diffremove = { - provider = 'git_diff_removed', - icon = ' ', - hl = {fg = colors.red}, - left_sep = ' ' - } - } - +function M.statusline() -- Initialize the components table before defining it + local comps = require('modules.ui.components') local components = { active = {}, inactive = {} @@ -293,7 +111,7 @@ function M.statusline_conf() table.insert(components.active[1], comps.fileinfo) table.insert(components.active[1], comps.lineinfo) table.insert(components.active[1], comps.percent) - table.insert(components.active[1], comps.gps) + -- table.insert(components.active[1], comps.gps) table.insert(components.active[3], comps.codeact) table.insert(components.active[3], comps.diagerr) table.insert(components.active[3], comps.diagwarn) @@ -312,9 +130,9 @@ function M.statusline_conf() table.insert(components.inactive[2], comps.filetype) require('feline').setup { - colors = {bg = colors.grey1, fg = colors.fg}, + colors = comps.normal_colors, components = components, - vi_mode_colors = vi_mode_colors, + vi_mode_colors = comps.vi_mode_colors, force_inactive = { filetypes = { 'packer', @@ -332,7 +150,7 @@ function M.statusline_conf() } end -function M.bufferline_conf() +function M.bufferline() require('bufferline').setup { options = { numbers = 'none', @@ -376,7 +194,7 @@ function M.bufferline_conf() end -- FIX: wait for config migration to setup() -function M.nvimtree_conf() +function M.nvimtree() vim.g.nvim_tree_gitignore = 1 vim.g.nvim_tree_ignore = {'.git', '.hg', '.svn', 'node_modules'} vim.g.nvim_tree_auto_ignore_ft = {'dashboard', 'alpha'} @@ -453,7 +271,7 @@ function M.nvimtree_conf() } end -function M.whichkey_conf() +function M.whichkey() require('which-key').setup { plugins = { spelling = { @@ -472,7 +290,7 @@ function M.whichkey_conf() } end -function M.gitsigns_conf() +function M.gitsigns() require('gitsigns').setup { signs = { add = {hl = 'DiffAdd' , text = '', numhl='GitSignsAddNr'}, @@ -544,71 +362,69 @@ function M.gitsigns_conf() } end -function M.lightbulb_conf() - vim.api.nvim_command [[ - autocmd CursorHold * lua require('nvim-lightbulb').update_lightbulb({sign = {enabled = false}, status_text = {enabled = true, text = ' Code action', text_unavailable = ''}}) - ]] +function M.lightbulb() + vim.api.nvim_command('autocmd CursorHold * lua require("nvim-lightbulb").update_lightbulb({sign = {enabled = false}, status_text = {enabled = true, text = " Code action", text_unavailable = ""}})') end -function M.gps_conf() - require('nvim-gps').setup { - icons = { - ['class-name'] = '𝓒 ', - ['function-name'] = 'ƒ ', - ['method-name'] = ' ', - ['container-name'] = ' ', - ['tag-name'] = '炙' - }, - -- Add custom configuration per language or - -- Disable the plugin for a language - -- Any language not disabled here is enabled by default - languages = { - -- Some languages have custom icons - ['json'] = { - icons = { - ['array-name'] = ' ', - ['object-name'] = ' ', - ['null-name'] = '[] ', - ['boolean-name'] = 'ﰰﰴ ', - ['number-name'] = '# ', - ['string-name'] = ' ' - } - }, - ['toml'] = { - icons = { - ['table-name'] = ' ', - ['array-name'] = ' ', - ['boolean-name'] = 'ﰰﰴ ', - ['date-name'] = ' ', - ['date-time-name'] = ' ', - ['float-name'] = ' ', - ['inline-table-name'] = ' ', - ['integer-name'] = '# ', - ['string-name'] = ' ', - ['time-name'] = ' ' - } - }, - ['verilog'] = { - icons = { - ['module-name'] = ' ' - } - }, - ['yaml'] = { - icons = { - ['mapping-name'] = ' ', - ['sequence-name'] = ' ', - ['null-name'] = '[] ', - ['boolean-name'] = 'ﰰﰴ ', - ['integer-name'] = '# ', - ['float-name'] = ' ', - ['string-name'] = ' ' - } - } - }, - separator = '  ', - depth = 0, - depth_limit_indicator = '..' - } -end +-- function M.gps() +-- require('nvim-gps').setup { +-- icons = { +-- ['class-name'] = '𝓒 ', +-- ['function-name'] = 'ƒ ', +-- ['method-name'] = ' ', +-- ['container-name'] = ' ', +-- ['tag-name'] = '炙' +-- }, +-- -- Add custom configuration per language or +-- -- Disable the plugin for a language +-- -- Any language not disabled here is enabled by default +-- languages = { +-- -- Some languages have custom icons +-- ['json'] = { +-- icons = { +-- ['array-name'] = ' ', +-- ['object-name'] = ' ', +-- ['null-name'] = '[] ', +-- ['boolean-name'] = 'ﰰﰴ ', +-- ['number-name'] = '# ', +-- ['string-name'] = ' ' +-- } +-- }, +-- ['toml'] = { +-- icons = { +-- ['table-name'] = ' ', +-- ['array-name'] = ' ', +-- ['boolean-name'] = 'ﰰﰴ ', +-- ['date-name'] = ' ', +-- ['date-time-name'] = ' ', +-- ['float-name'] = ' ', +-- ['inline-table-name'] = ' ', +-- ['integer-name'] = '# ', +-- ['string-name'] = ' ', +-- ['time-name'] = ' ' +-- } +-- }, +-- ['verilog'] = { +-- icons = { +-- ['module-name'] = ' ' +-- } +-- }, +-- ['yaml'] = { +-- icons = { +-- ['mapping-name'] = ' ', +-- ['sequence-name'] = ' ', +-- ['null-name'] = '[] ', +-- ['boolean-name'] = 'ﰰﰴ ', +-- ['integer-name'] = '# ', +-- ['float-name'] = ' ', +-- ['string-name'] = ' ' +-- } +-- } +-- }, +-- separator = '  ', +-- depth = 0, +-- depth_limit_indicator = '..' +-- } +-- end return M diff --git a/roles/nvim/files/nvim/lua/modules/ui/plugins.lua b/roles/nvim/files/nvim/lua/modules/ui/plugins.lua new file mode 100644 index 0000000..10ea779 --- /dev/null +++ b/roles/nvim/files/nvim/lua/modules/ui/plugins.lua @@ -0,0 +1,38 @@ +local M = {} +local conf = require('modules.ui.config') + +M['goolord/alpha-nvim'] = { + event = 'VimEnter', + config = conf.dashboard +} +M['famiu/feline.nvim'] = { + event = 'VimEnter', + wants = 'nvim-web-devicons', + config = conf.statusline +} +M['akinsho/bufferline.nvim'] = { + event = {'BufRead', 'BufNewFile'}, + config = conf.bufferline +} +M['kyazdani42/nvim-tree.lua'] = { + cmd = 'NvimTreeToggle', + config = conf.nvimtree +} +M['folke/which-key.nvim'] = { + config = conf.whichkey +} +M['lewis6991/gitsigns.nvim'] = { + event = {'BufRead', 'BufNewFile'}, + wants = 'plenary.nvim', + config = conf.gitsigns +} +M['kosayoda/nvim-lightbulb'] = { + after = 'nvim-lspconfig', + config = conf.lightbulb +} +-- M['SmiteshP/nvim-gps'] = { +-- after = 'nvim-treesitter', +-- config = conf.gps +-- } + +return M diff --git a/roles/nvim/files/nvim/lua/plugins.lua b/roles/nvim/files/nvim/lua/plugins.lua index 4a2577b..0cba566 100644 --- a/roles/nvim/files/nvim/lua/plugins.lua +++ b/roles/nvim/files/nvim/lua/plugins.lua @@ -1,469 +1,41 @@ -- TODO: rust-tools.nvim, crates.nvim, go.nvim, clojure-vim/*, nvim-comment-frame, -- nvim-revJ.lua, nvim-remote-containers, tex.nvim, telescope-dap.nvim, fcitx.nvim, --- pandoc.nvim, qf_helper.nvim -local packer = require('modules.pack') +-- pandoc.nvim, qf_helper.nvim, tldr.nvim +local M = {} +local packer = require('modules.core.pack') +local modules_dir = vim.fn.stdpath('config') .. '/lua/modules' --- This is recommended when using `luafile ` a lot -packer.reset() - --- Necessary stuff -local needed_plugins = function(use) - use {'wbthomason/packer.nvim', opt = true} - - use {'kyazdani42/nvim-web-devicons', module = 'nvim-web-devicons'} - use {'nvim-lua/plenary.nvim', module = 'plenary'} - use {'nvim-lua/popup.nvim', module = 'popup'} +local function get_plugins_list() + local list = {} + local tmp = vim.split(vim.fn.globpath(modules_dir, '*/plugins.lua'), '\n') + for _, f in ipairs(tmp) do + list[#list + 1] = f:sub(#modules_dir - 6, -1) + end + return list end --- UI components -local ui = require('modules.ui') -local ui_plugins = function(use) - use { - 'goolord/alpha-nvim', - event = 'VimEnter', - config = ui.dashboard_conf - } - use { - 'famiu/feline.nvim', - event = 'VimEnter', - wants = 'nvim-web-devicons', - config = ui.statusline_conf - } - use { - 'akinsho/bufferline.nvim', - event = {'BufRead', 'BufNewFile'}, - config = ui.bufferline_conf - } - use { - 'kyazdani42/nvim-tree.lua', - cmd = 'NvimTreeToggle', - config = ui.nvimtree_conf - } - use { - 'folke/which-key.nvim', - config = ui.whichkey_conf - } - use { - 'lewis6991/gitsigns.nvim', - event = {'BufRead', 'BufNewFile'}, - wants = 'plenary.nvim', - config = ui.gitsigns_conf - } - use { - 'kosayoda/nvim-lightbulb', - after = 'nvim-lspconfig', - config = ui.lightbulb_conf - } - use { - 'SmiteshP/nvim-gps', - after = 'nvim-treesitter', - config = ui.gps_conf - } +function M.load_plugins() + local repos = {} + + -- Merge all plugins' definitions into a table + local plugins_file = get_plugins_list() + for _, m in ipairs(plugins_file) do + local local_repos = require(m:sub(0, #m - 4)) + for repo, conf in pairs(local_repos) do + repos[#repos + 1] = vim.tbl_extend('force', {repo}, conf) + end + end + + -- This is recommended when using `luafile ` a lot + packer.reset() + + packer.startup(function(use) + for _, repo in ipairs(repos) do + use(repo) + end + -- Install plugins if missing + packer.install() + end) end --- Editing-related plugins -local editor = require('modules.editor') -local editor_plugins = function(use) - use { - 'norcalli/nvim-colorizer.lua', - cmd = 'ColorizerToggle', - config = editor.colorizer_conf - } - -- use { -- TODO: check out treesitter support, otherwise use nvim-treesitter-refactor - -- 'RRethy/vim-illuminate', - -- event = 'CursorHold', - -- setup = editor.illuminate_conf - -- } - use { -- TODO: config, check out fennel-repl.nvim - 'Olical/conjure', - ft = {'clojure', 'fennel', 'scheme', 'hy', 'janet', 'racket'} - } - use { -- TODO: highlights, check out neorg - 'kristijanhusak/orgmode.nvim', - ft = 'org', - requires = {{ - 'akinsho/org-bullets.nvim', - after = 'orgmode.nvim', - config = editor.bullets_conf - }}, - config = editor.orgmode_conf - } - use { - 'lukas-reineke/headlines.nvim', - ft = {'org', 'markdown'}, - config = editor.headlines_conf - } - use { - 'nvim-treesitter/nvim-treesitter', - run = ':TSUpdate', - event = 'BufRead', - config = editor.treesitter_conf - } - use {'nvim-treesitter/playground', after = 'nvim-treesitter'} - use {'nvim-treesitter/nvim-treesitter-refactor', after = 'nvim-treesitter'} - use {'nvim-treesitter/nvim-treesitter-textobjects', after = 'nvim-treesitter'} - use {'p00f/nvim-ts-rainbow', after = 'nvim-treesitter'} - use {'windwp/nvim-ts-autotag', after = 'nvim-treesitter'} - use {'romgrk/nvim-treesitter-context', after = 'nvim-treesitter'} - use {'JoosepAlviste/nvim-ts-context-commentstring', after = 'nvim-treesitter'} - -- use { - -- 'spywhere/detect-language.nvim', - -- event = 'BufNewFile', - -- config = editor.detect_conf - -- } - use { - 'lukas-reineke/indent-blankline.nvim', - after = 'nvim-treesitter', - config = editor.blankline_conf - } - use { - 'mizlan/iswap.nvim', - cmd = {'ISwapWith', 'ISwap'}, - wants = 'nvim-treesitter', - config = editor.iswap_conf - } - use { - 'andymass/vim-matchup', - after = 'nvim-treesitter', - config = editor.matchup_conf - } - use {'machakann/vim-sandwich', keys = 's'} -- TODO: check out surround.nvim - use { - 'folke/zen-mode.nvim', - cmd = 'ZenMode', - wants = 'twilight.nvim', - requires = {{ - 'folke/twilight.nvim', - cmd = {'Twilight', 'TwilightEnable'}, - config = editor.twilight_conf, - opt = true - }}, - config = editor.zenmode_conf - } - use { - 'max397574/better-escape.nvim', - event = 'InsertCharPre', - config = editor.betterescape_conf - } - use { -- TODO: check out lightspeed.nvim - 'phaazon/hop.nvim', - cmd = {'HopChar1', 'HopChar2', 'HopWord', 'HopPattern', 'HopLine'}, - config = editor.hop_conf - } - use { - 'hrsh7th/vim-eft', - keys = { - {'n', 'f'}, {'x', 'f'}, {'n', 'F'}, {'x', 'F'}, - {'n', 't'}, {'x', 't'}, {'n', 'T'}, {'x', 'T'}, - {'n', ';'}, {'x', ';'} - }, - config = editor.eft_conf - } - use { - 'monaqa/dial.nvim', - keys = { - {'n', ''}, {'v', ''}, {'v', 'g'}, - {'n', ''}, {'v', ''}, {'v', 'g'} - }, - config = editor.dial_conf - } - use {'junegunn/vim-easy-align', cmd = {'EasyAlign', 'LiveEasyAlign'}} - use { - 'dhruvasagar/vim-table-mode', - cmd = {'Tableize', 'TableModeToggle', 'TableModeRealign'}, - setup = editor.table_conf - } - use { - 'numToStr/Comment.nvim', - keys = {'gc', 'gb'}, - wants = 'nvim-ts-context-commentstring', - config = editor.comment_conf - } - use { - 'winston0410/range-highlight.nvim', - event = 'CmdlineEnter', - wants = 'cmd-parser.nvim', - requires = {{'winston0410/cmd-parser.nvim', opt = true}}, - config = editor.range_conf - } - use { - 'danymat/neogen', - keys = 'eg', - wants = 'nvim-treesitter', - config = editor.neogen_conf - } - use { - 'gpanders/editorconfig.nvim', - event = {'BufRead', 'BufNewFile'} - } - use { -- TODO: move to nvim-parinfer (lua) - 'eraserhd/parinfer-rust', - run = 'cargo build --release', - ft = {'clojure', 'lisp', 'scheme', 'fennel', 'racket', 'hy', 'janet', 'carp', 'wast'} - } - use { - 'ahmedkhalf/project.nvim', - event = 'BufEnter', - config = editor.project_conf - } - use { - 'ruifm/gitlinker.nvim', - wants = 'plenary.nvim', - keys = {'gy', 'gY'}, - config = editor.gitlinker_conf - } - use {'jbyuki/venn.nvim', cmd = 'VBox'} -end - --- LSP-related -local lsp = require('modules.lsp') -local lsp_plugins = function(use) - use { - 'neovim/nvim-lspconfig', - event = 'BufReadPre', - wants = {'lsp_signature.nvim', 'lspsaga.nvim', 'SchemaStore.nvim'}, - requires = { - { - 'ray-x/lsp_signature.nvim', - config = lsp.signature_conf, - opt = true - }, - { - 'tami5/lspsaga.nvim', - branch = 'nvim51', - config = lsp.saga_conf, - opt = true - }, - {'b0o/SchemaStore.nvim', opt = true} - }, - config = lsp.lsp_conf - } - use { - 'jose-elias-alvarez/null-ls.nvim', - wants = 'plenary.nvim', - after = 'nvim-lspconfig', - config = lsp.null_ls_conf - } - use { - 'nanotee/sqls.nvim', - ft = {'sql', 'mysql'}, - wants = 'nvim-lspconfig', - config = lsp.sqls_conf - } - use { - 'folke/trouble.nvim', - cmd = {'Trouble', 'TroubleToggle', 'TroubleRefresh'}, - config = lsp.trouble_conf - } - use { - 'folke/todo-comments.nvim', - wants = 'plenary.nvim', - event = 'BufRead', - config = lsp.comments_conf - } - use { - 'simrat39/symbols-outline.nvim', - cmd = {'SymbolsOutline', 'SymbolsOutlineOpen'}, - setup = lsp.outline_conf - } - use { -- TODO: config, scripts to install/update dap servers - 'rcarriga/nvim-dap-ui', - keys = 'd', - wants = 'nvim-dap', - requires = {{ - 'mfussenegger/nvim-dap', - config = lsp.dap_conf, - opt = true - }}, - config = lsp.dapui_conf - } -end - --- Completion -local completion = require('modules.completion') -local completion_plugins = function(use) - use { - 'hrsh7th/nvim-cmp', - event = 'InsertEnter', - wants = {'LuaSnip', 'cmp-under-comparator'}, - requires = { - { - 'L3MON4D3/LuaSnip', - wants = 'friendly-snippets', - requires = {{'rafamadriz/friendly-snippets', opt = true}}, - config = completion.snippets_conf, - opt = true - }, - {'lukas-reineke/cmp-under-comparator', opt = true} - }, - config = completion.cmp_conf - } - use {'saadparwaiz1/cmp_luasnip', after = 'nvim-cmp'} - use {'hrsh7th/cmp-path', after = 'nvim-cmp'} - use {'hrsh7th/cmp-buffer', after = 'nvim-cmp'} - use {'hrsh7th/cmp-calc', after = 'nvim-cmp'} - use {'uga-rosa/cmp-dictionary', after = 'nvim-cmp'} - use {'hrsh7th/cmp-nvim-lsp', after = {'nvim-cmp', 'nvim-lspconfig'}} - -- use { - -- 'tzachar/cmp-tabnine', - -- after = 'nvim-cmp', - -- run = './install.sh', - -- config = completion.tabnine_conf - -- } - use {'kdheepak/cmp-latex-symbols', after = 'nvim-cmp'} - use {'PaterJason/cmp-conjure', after = {'conjure', 'nvim-cmp'}} - use { - 'windwp/nvim-autopairs', - after = 'nvim-cmp', - config = completion.autopairs_conf - } -end - --- Other tools -local tools = require('modules.tools') -local tools_plugins = function(use) - use { -- TODO: check out fzf-lua - 'nvim-telescope/telescope.nvim', - keys = 'fj', - cmd = 'Telescope', - wants = { - 'popup.nvim', - 'plenary.nvim', - 'nvim-notify', - 'yabs.nvim', - 'telescope-symbols.nvim', - 'telescope-project.nvim', - 'telescope-fzf-native.nvim' - }, - requires = { - {'FollieHiyuki/telescope-symbols.nvim', opt = true}, - {'nvim-telescope/telescope-project.nvim', opt = true}, - {'nvim-telescope/telescope-fzf-native.nvim', run = 'make', opt = true} - }, - config = tools.telescope_conf - } - use { -- TODO: colors + config - 'pwntester/octo.nvim', - cmd = 'Octo', - wants = 'telescope.nvim', - config = tools.octo_conf - } - use { - 'TimUntersberger/neogit', - cmd = 'Neogit', - wants = {'diffview.nvim', 'plenary.nvim'}, - requires = {{ - 'sindrets/diffview.nvim', - cmd = { - 'DiffviewOpen','DiffviewClose', - 'DiffviewToggleFiles', 'DiffviewFocusFiles' - }, - config = tools.diffview_conf, - opt = true - }}, - config = tools.neogit_conf - } - use { - 'pianocomposer321/yabs.nvim', - cmd = {'YabsTask', 'YabsDefaultTask'}, - config = tools.yabs_conf - } - use { -- TODO: check out kat0h/bufpreview.vim - 'iamcco/markdown-preview.nvim', - run = 'cd app && yarn install', - ft = {'markdown', 'rmd'}, - config = tools.markdown_preview_conf - } - use { - 'turbio/bracey.vim', - run = 'npm install --prefix server', - cmd = 'Bracey' - } - use { - 'windwp/nvim-spectre', - keys = 'p', - wants = 'plenary.nvim', - config = tools.spectre_conf - } - use { - 'echuraev/translate-shell.vim', - cmd = {'Trans', 'TransSelectDirection'}, - config = tools.translate_conf - } - use { - 'mbbill/undotree', - cmd = 'UndotreeToggle', - setup = tools.undotree_conf - } - use { - 'akinsho/toggleterm.nvim', - cmd = 'ToggleTerm', - config = tools.toggleterm_conf - } - use { - 'michaelb/sniprun', - run = 'cargo build --release', - cmd = 'SnipRun', - wants = 'nvim-notify', - config = tools.sniprun_conf - } - use { - 'NTBBloodbath/rest.nvim', - keys = {'RestNvim', 'RestNvimPreview', 'RestNvimLast'}, - wants = {'plenary.nvim', 'nvim-treesitter'}, - config = tools.rest_conf - } - use { -- TODO: check out auto-session + session-lens - 'folke/persistence.nvim', - event = 'BufReadPre', - keys = 's', - config = tools.session_conf - } - use { - 'nathom/filetype.nvim', - event = {'BufRead', 'BufNewFile'}, - config = tools.filetype_conf - } - use { - 'kazhala/close-buffers.nvim', - cmd = {'BDelete', 'BWipeout'}, - wants = 'bufferline.nvim', - config = tools.closebuf_conf - } - use { - 'sindrets/winshift.nvim', - cmd = 'WinShift', - config = tools.winshift_conf - } - use { - 'ten3roberts/window-picker.nvim', - cmd = {'WindowPick', 'WindowSwap', 'WindowSwapStay'}, - config = tools.winpicker_conf - } - use { - 'chipsenkbeil/distant.nvim', - cmd = {'DistantInstall', 'DistantLaunch'}, - config = tools.distant_conf - } - use { - 'rcarriga/nvim-notify', - module = 'nvim-notify', - config = tools.notify_conf - } - use {'dstein64/vim-startuptime', cmd = 'StartupTime'} -- Just for benchmarking -end - --- Merge everything together -local summary = function(use) - needed_plugins(use) - ui_plugins(use) - editor_plugins(use) - lsp_plugins(use) - completion_plugins(use) - tools_plugins(use) - - -- Install plugins if missing - packer.install() -end - -return packer.startup(summary) +return M diff --git a/roles/nvim/files/nvim/lua/themes/nord/init.lua b/roles/nvim/files/nvim/lua/themes/nord/init.lua index c7c21cd..d44f8ee 100644 --- a/roles/nvim/files/nvim/lua/themes/nord/init.lua +++ b/roles/nvim/files/nvim/lua/themes/nord/init.lua @@ -325,10 +325,10 @@ function M.highlight_plugins() cmd('hi! link EftSubChar LineNr') -- dashboard-nvim / alpha-nvim - hi('DashboardHeader' , c.blue , '', 'bold' , '') - hi('DashboardCenter' , c.green , '', 'bold' , '') - hi('DashboardShortcut', c.grey_bright, '', 'bold,italic', '') - hi('DashboardFooter' , c.purple , '', 'bold' , '') + hi('DashboardHeader' , c.blue , '', 'bold' , '') + hi('DashboardCenter' , c.green , '', 'bold' , '') + hi('DashboardShortcut', c.purple, '', 'bold,italic', '') + hi('DashboardFooter' , c.yellow, '', 'bold' , '') -- symbols-outline.nvim hi('FocusedSymbol', c.yellow, '', 'bold', '') @@ -427,9 +427,9 @@ function M.highlight_plugins() cmd('hi! link DiagnosticWarning LspDiagnosticsDefaultWarning') cmd('hi! link DiagnosticInformation LspDiagnosticsDefaultInformation') cmd('hi! link DiagnosticHint LspDiagnosticsDefaultHint') - hi('LspSagaDiagnosticBorder', c.purple, '', '', '') - hi('LspSagaDiagnosticHeader', c.yellow, '', 'bold', '') - hi('LspSagaDiagnosticTruncateLine', c.purple, '', '', '') + hi('LspSagaDiagnosticBorder', c.fg, '', '', '') + hi('LspSagaDiagnosticHeader', c.blue, '', 'bold', '') + hi('LspSagaDiagnosticTruncateLine', c.fg, '', '', '') cmd('hi! link LspSagaDiagnosticFloatingError LspDiagnosticsDefaultError') cmd('hi! link LspSagaDiagnosticFloatingWarn LspDiagnosticsDefaultWarning') cmd('hi! link LspSagaDiagnosticFloatingInfor LspDiagnosticsDefaultInformation') diff --git a/roles/nvim/files/nvim/lua/util.lua b/roles/nvim/files/nvim/lua/util.lua index 1f4fd95..6d8a986 100644 --- a/roles/nvim/files/nvim/lua/util.lua +++ b/roles/nvim/files/nvim/lua/util.lua @@ -1,4 +1,5 @@ local M = {} +local cmd = vim.api.nvim_command function M.highlight(group, guifg, guibg, attr, guisp) local fg = guifg ~= '' and 'guifg=' .. guifg or 'guifg=NONE' @@ -6,83 +7,18 @@ function M.highlight(group, guifg, guibg, attr, guisp) local style = attr ~= '' and 'gui=' .. attr or 'gui=NONE' local sp = guisp ~= '' and 'guisp=' .. guisp or '' - local hl = 'hi ' .. group .. ' ' .. fg .. ' ' .. bg .. ' ' .. style .. ' ' .. sp - vim.api.nvim_command(hl) + cmd('hi ' .. group .. ' ' .. fg .. ' ' .. bg .. ' ' .. style .. ' ' .. sp) end -function M.lsp_on_attach(client, bufnr) - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - - local lsp_mappings = { - g = { - d = {':lua vim.lsp.buf.definition()', 'Goto definition'}, - D = {':lua vim.lsp.buf.declaration()', 'Goto declaration'}, - i = {':Lspsaga implement', 'Implementations'}, - I = {':Telescope lsp_implementations', 'Implementations (Telescope)'}, - r = {':TroubleToggle lsp_references', 'References'}, - R = {':Telescope lsp_references', 'References (Telescope)'} - }, - K = {':Lspsaga hover_doc', 'Hover doc'}, - ['[d'] = {':Lspsaga diagnostic_jump_prev', 'Previous diagnostics'}, - [']d'] = {':Lspsaga diagnostic_jump_next', 'Next diagnostics'} - } - local lsp_leader_mappings = { - l = { - name = 'LSP', - a = {':lua vim.lsp.buf.add_workspace_folder()', 'Add workspace folder'}, - b = {':TroubleToggle lsp_document_diagnostics', 'Buffer diagnostics'}, - B = {':Telescope lsp_document_diagnostics', 'Buffer diagnostics (Telescope)'}, - c = {':Lspsaga code_action', 'Code action'}, - C = {':Telescope lsp_code_actions', 'Code action (Telescope)'}, - d = {':TroubleToggle lsp_definitions', 'Definitions'}, - D = {':Telescope lsp_definitions', 'Definitions (Telescope)'}, - e = {':Lspsaga show_line_diagnostics', 'Line diagnostics'}, - f = {':Lspsaga lsp_finder', 'Finder'}, - g = {':SymbolsOutline', 'Symbol outline'}, - i = {':LspInfo', 'Lsp info'}, - l = {':TroubleToggle loclist', 'Diagnostics loclist'}, - n = {':Lspsaga rename', 'Rename'}, - p = {':Lspsaga preview_definition', 'Preview definition'}, - r = {':lua vim.lsp.buf.remove_workspace_folder()', 'Remove workspace folder'}, - s = {':Telescope lsp_document_symbols', 'Buffer symbols'}, - S = {':Telescope lsp_workspace_symbols', 'Workspace symbols'}, - t = {':TroubleToggle', 'Toggle Trouble'}, - w = {':TroubleToggle lsp_workspace_diagnostics', 'Workspace diagnostics'}, - W = {':Telescope lsp_workspace_diagnostics', 'Workspace diagnostics (Telescope)'}, - x = {':lua vim.lsp.buf.signature_help()', 'Signature help'}, - y = {':lua vim.notify(vim.inspect(vim.lsp.buf.list_workspace_folders()), vim.log.levels.INFO)', 'List workspace folders'} - } - } - local lsp_visual_mappings = { - l = { - name = 'LSP', - c = {':Lspsaga range_code_action', 'Range code action'}, - C = {':Telescope lsp_range_code_actions', 'Range code action (Telescope)'} - } - } - - local wk = require('which-key') - wk.register(lsp_mappings, {buffer = bufnr}) - wk.register(lsp_leader_mappings, {buffer = bufnr, prefix = ''}) - wk.register(lsp_visual_mappings, {buffer = bufnr, prefix = '', mode = 'v'}) - - local opts = {noremap = true, silent = true} - vim.api.nvim_buf_set_keymap(bufnr, 'n', '', ':lua require("lspsaga.action").smart_scroll_with_saga(1)', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', '', ':lua require("lspsaga.action").smart_scroll_with_saga(-1)', opts) - - if client.resolved_capabilities.document_formatting then - wk.register({ - ['lo'] = {':lua vim.lsp.buf.formatting()', 'Format buffer'} - }, {buffer = bufnr, prefix = ''}) - -- vim.api.nvim_command('autocmd BufWritePre lua vim.lsp.buf.formatting_sync()') - elseif client.resolved_capabilities.document_range_formatting then - wk.register({ - ['lo'] = {':lua vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0})', 'Format buffer'} - }, {buffer = bufnr, prefix = ''}) - wk.register({ - ['lo'] = {':lua vim.lsp.buf.range_formatting()', 'Format range'} - }, {buffer = bufnr, prefix = '', mode = 'v'}) - -- vim.api.nvim_command('autocmd BufWritePre lua vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0})') +function M.load_autocmd(definitions) + for group_name, definition in pairs(definitions) do + cmd('augroup ' .. group_name) + cmd('autocmd!') + for _, def in ipairs(definition) do + local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ') + cmd(command) + end + cmd('augroup END') end end diff --git a/roles/nvim/files/nvim/scripts/lint/autopep8 b/roles/nvim/files/nvim/scripts/lint/autopep8 deleted file mode 100755 index ee29240..0000000 --- a/roles/nvim/files/nvim/scripts/lint/autopep8 +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lint/autopep8" -[ ! -d "${server_path}" ] && mkdir -p "${server_path}" - -python3 -m venv ${server_path}/venv -${server_path}/venv/bin/pip3 install -U pip -${server_path}/venv/bin/pip3 install -U autopep8 diff --git a/roles/nvim/files/nvim/scripts/lint/black b/roles/nvim/files/nvim/scripts/lint/black deleted file mode 100755 index 85bfd75..0000000 --- a/roles/nvim/files/nvim/scripts/lint/black +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lint/black" -[ ! -d "${server_path}" ] && mkdir -p "${server_path}" - -python3 -m venv ${server_path}/venv -${server_path}/venv/bin/pip3 install -U pip -${server_path}/venv/bin/pip3 install -U black diff --git a/roles/nvim/files/nvim/scripts/lint/flake8 b/roles/nvim/files/nvim/scripts/lint/flake8 deleted file mode 100755 index 218fa24..0000000 --- a/roles/nvim/files/nvim/scripts/lint/flake8 +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lint/flake8" -[ ! -d "${server_path}" ] && mkdir -p "${server_path}" - -python3 -m venv ${server_path}/venv -${server_path}/venv/bin/pip3 install -U pip -${server_path}/venv/bin/pip3 install -U flake8 diff --git a/roles/nvim/files/nvim/scripts/lint/isort b/roles/nvim/files/nvim/scripts/lint/isort deleted file mode 100755 index 24e27db..0000000 --- a/roles/nvim/files/nvim/scripts/lint/isort +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lint/isort" -[ ! -d "${server_path}" ] && mkdir -p "${server_path}" - -python3 -m venv ${server_path}/venv -${server_path}/venv/bin/pip3 install -U pip -${server_path}/venv/bin/pip3 install -U isort diff --git a/roles/nvim/files/nvim/scripts/lint/pylint b/roles/nvim/files/nvim/scripts/lint/pylint deleted file mode 100755 index 340aa0f..0000000 --- a/roles/nvim/files/nvim/scripts/lint/pylint +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lint/pylint" -[ ! -d "${server_path}" ] && mkdir -p "${server_path}" - -python3 -m venv ${server_path}/venv -${server_path}/venv/bin/pip3 install -U pip -${server_path}/venv/bin/pip3 install -U pylint diff --git a/roles/nvim/files/nvim/scripts/lint/yapf b/roles/nvim/files/nvim/scripts/lint/yapf deleted file mode 100755 index 4316415..0000000 --- a/roles/nvim/files/nvim/scripts/lint/yapf +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -# This iss not spellings goor -server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lint/yapf" -[ ! -d "${server_path}" ] && mkdir -p "${server_path}" - -python3 -m venv ${server_path}/venv -${server_path}/venv/bin/pip3 install -U pip -${server_path}/venv/bin/pip3 install -U yapf diff --git a/roles/nvim/files/nvim/scripts/lsp/pylsp b/roles/nvim/files/nvim/scripts/lsp/pylsp new file mode 100755 index 0000000..349e392 --- /dev/null +++ b/roles/nvim/files/nvim/scripts/lsp/pylsp @@ -0,0 +1,14 @@ +#!/bin/sh + +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/pylsp" +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" + +python3 -m venv ${server_path}/venv +${server_path}/venv/bin/pip3 install -U pip +${server_path}/venv/bin/pip3 install -U 'python-lsp-server[all]' +# ${server_path}/venv/bin/pip3 install -U pyls-flake8 +# ${server_path}/venv/bin/pip3 install -U pylsp-mypy +# ${server_path}/venv/bin/pip3 install -U pyls-isort +# ${server_path}/venv/bin/pip3 install -U pyls-memestra +# ${server_path}/venv/bin/pip3 install -U pylsp-rope +# ${server_path}/venv/bin/pip3 install -U python-lsp-black diff --git a/roles/nvim/files/nvim/scripts/lsp/pyright b/roles/nvim/files/nvim/scripts/lsp/pyright deleted file mode 100755 index db0e866..0000000 --- a/roles/nvim/files/nvim/scripts/lsp/pyright +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -current_path="$PWD" -server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/pyright" - -[ ! -d "${server_path}" ] && mkdir -p "${server_path}" -cd ${server_path} - -[ ! -f package.json ] && npm init -y --scope=lsp || true -npm install pyright@latest - -cd ${current_path} diff --git a/roles/nvim/files/nvim/scripts/pylsp b/roles/nvim/files/nvim/scripts/pylsp new file mode 100755 index 0000000..b118dba --- /dev/null +++ b/roles/nvim/files/nvim/scripts/pylsp @@ -0,0 +1,4 @@ +#!/bin/bash + +source ${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/pylsp/venv/bin/activate +exec pylsp