From 592e348689a3fba6467249be1163f8f91572e15f Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Tue, 29 Jun 2021 22:45:48 -0400 Subject: updates --- lua/keymappings.lua | 2 - lua/lv-autocommands/init.lua | 125 +++++++++++++++++++++++---------- lua/lv-utils/init.lua | 163 ------------------------------------------- lua/lv-which-key/init.lua | 81 +++++++++++++-------- 4 files changed, 141 insertions(+), 230 deletions(-) (limited to 'lua') diff --git a/lua/keymappings.lua b/lua/keymappings.lua index dcce2562..0e8284d3 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -1,5 +1,3 @@ -vim.api.nvim_set_keymap('n', '-', ':RnvimrToggle', {noremap = true, silent = true}) - -- better window movement vim.api.nvim_set_keymap('n', '', 'h', {silent = true}) vim.api.nvim_set_keymap('n', '', 'j', {silent = true}) diff --git a/lua/lv-autocommands/init.lua b/lua/lv-autocommands/init.lua index 28dda448..0026690b 100644 --- a/lua/lv-autocommands/init.lua +++ b/lua/lv-autocommands/init.lua @@ -1,54 +1,103 @@ +-- TODO when autocommands are better in lua, scope these to plugins and langs local utils = require('lv-utils') -local auto_formatters = { } +local auto_formatters = {} -local python_autoformat = {'BufWritePre', '*.py', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'} -if O.lang.python.autoformat then table.insert(auto_formatters, python_autoformat) end +if O.lang.python.active then + local python_autoformat = { + 'BufWritePre', '*.py', 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + } + if O.lang.python.autoformat then + table.insert(auto_formatters, python_autoformat) + end +end -local javascript_autoformat = {'BufWritePre', '*.js', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'} -local javascriptreact_autoformat = {'BufWritePre', '*.jsx', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'} -local typescript_autoformat = {'BufWritePre', '*.ts', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'} -local typescriptreact_autoformat = {'BufWritePre', '*.tsx', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'} -if O.lang.tsserver.autoformat then - table.insert(auto_formatters, javascript_autoformat) - table.insert(auto_formatters, javascriptreact_autoformat) - table.insert(auto_formatters, typescript_autoformat) - table.insert(auto_formatters, typescriptreact_autoformat) +if O.lang.tsserver.active then + local javascript_autoformat = { + 'BufWritePre', '*.js', 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + } + local javascriptreact_autoformat = { + 'BufWritePre', '*.jsx', 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + } + local typescript_autoformat = { + 'BufWritePre', '*.ts', 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + } + local typescriptreact_autoformat = { + 'BufWritePre', '*.tsx', 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + } + if O.lang.tsserver.autoformat then + table.insert(auto_formatters, javascript_autoformat) + table.insert(auto_formatters, javascriptreact_autoformat) + table.insert(auto_formatters, typescript_autoformat) + table.insert(auto_formatters, typescriptreact_autoformat) + end end -local lua_format = {'BufWritePre', '*.lua', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'} -if O.lang.lua.autoformat then table.insert(auto_formatters, lua_format) end +if O.lang.lua.active then + local lua_format = { + 'BufWritePre', '*.lua', 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + } + if O.lang.lua.autoformat then table.insert(auto_formatters, lua_format) end +end -local json_format = {'BufWritePre', '*.json', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'} -if O.lang.json.autoformat then table.insert(auto_formatters, json_format) end +if O.lang.json.active then + local json_format = { + 'BufWritePre', '*.json', 'lua vim.lsp.buf.formatting_sync(nil, 1000)' + } + if O.lang.json.autoformat then table.insert(auto_formatters, json_format) end +end -local ruby_format = {'BufWritePre', '*.rb', 'lua vim.lsp.buf.formatting_sync(nil,1000)'} -if O.lang.ruby.autoformat then table.insert(auto_formatters, ruby_format) end +if O.lang.ruby.active then + local ruby_format = { + 'BufWritePre', '*.rb', 'lua vim.lsp.buf.formatting_sync(nil,1000)' + } + if O.lang.ruby.autoformat then table.insert(auto_formatters, ruby_format) end +end -local go_format = {'BufWritePre', '*.go', 'lua vim.lsp.buf.formatting_sync(nil,1000)'} -if O.lang.go.autoformat then table.insert(auto_formatters, go_format) end +if O.lang.go.active then + local go_format = { + 'BufWritePre', '*.go', 'lua vim.lsp.buf.formatting_sync(nil,1000)' + } + if O.lang.go.autoformat then table.insert(auto_formatters, go_format) end +end -local rust_format = {'BufWritePre', '*.rs', 'lua vim.lsp.buf.formatting_sync(nil,1000)'} -if O.lang.rust.autoformat then table.insert(auto_formatters, rust_format) end +if O.lang.rust.active then + local rust_format = { + 'BufWritePre', '*.rs', 'lua vim.lsp.buf.formatting_sync(nil,1000)' + } + if O.lang.rust.autoformat then table.insert(auto_formatters, rust_format) end +end utils.define_augroups({ _general_settings = { - {'TextYankPost', '*', 'lua require(\'vim.highlight\').on_yank({higroup = \'Search\', timeout = 200})'}, - {'BufWinEnter', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'}, - {'BufRead', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'}, - {'BufNewFile', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'}, - {'VimLeavePre', '*', 'set title set titleold='}, + { + 'TextYankPost', '*', + 'lua require(\'vim.highlight\').on_yank({higroup = \'Search\', timeout = 200})' + }, { + 'BufWinEnter', '*', + 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o' + }, + { + 'BufRead', '*', + 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o' + }, { + 'BufNewFile', '*', + 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o' + }, {'VimLeavePre', '*', 'set title set titleold='}, {'FileType', 'qf', 'set nobuflisted'}, - {'BufWinEnter', 'lv-config.lua', 'PackerCompile'}, - {'BufWinLeave', 'lv-config.lua', 'PackerCompile'}, - {'BufWritePost', 'lv-config.lua', 'PackerCompile'} + -- {'BufWinEnter', 'lv-config.lua', 'PackerCompile'}, + -- {'BufWinLeave', 'lv-config.lua', 'PackerCompile'}, + -- {'BufWritePost', 'lv-config.lua', 'PackerCompile'} -- {'User', 'GoyoLeave', 'lua require(\'galaxyline\').disable_galaxyline()'}, -- {'User', 'GoyoEnter', 'lua require(\'galaxyline\').galaxyline_augroup()'}, }, _java = { -- {'FileType', 'java', 'luafile '..CONFIG_PATH..'/lua/lsp/java-ls.lua'}, - {'FileType', 'java', 'nnoremap ca lua require(\'jdtls\').code_action()'} + { + 'FileType', 'java', + 'nnoremap ca lua require(\'jdtls\').code_action()' + } }, _go = { @@ -56,16 +105,22 @@ utils.define_augroups({ {'FileType', 'go', 'setlocal tabstop=4'}, {'FileType', 'go', 'setlocal shiftwidth=4'}, {'FileType', 'go', 'setlocal softtabstop=4'}, - {'FileType', 'go', 'setlocal noexpandtab'}, + {'FileType', 'go', 'setlocal noexpandtab'} }, _dashboard = { -- seems to be nobuflisted that makes my stuff disapear will do more testing { 'FileType', 'dashboard', 'setlocal nocursorline noswapfile synmaxcol& signcolumn=no norelativenumber nocursorcolumn nospell nolist nonumber bufhidden=wipe colorcolumn= foldcolumn=0 matchpairs= ' - }, {'FileType', 'dashboard', 'set showtabline=0 | autocmd BufLeave set showtabline=2'} + }, { + 'FileType', 'dashboard', + 'set showtabline=0 | autocmd BufLeave set showtabline=2' + } + }, + _markdown = { + {'FileType', 'markdown', 'setlocal wrap'}, + {'FileType', 'markdown', 'setlocal spell'} }, - _markdown = {{'FileType', 'markdown', 'setlocal wrap'}, {'FileType', 'markdown', 'setlocal spell'}}, -- _solidity = { -- {'BufWinEnter', '.sol', 'setlocal filetype=solidity'}, {'BufRead', '*.sol', 'setlocal filetype=solidity'}, -- {'BufNewFile', '*.sol', 'setlocal filetype=solidity'} @@ -77,7 +132,7 @@ utils.define_augroups({ _buffer_bindings = { {'FileType', 'dashboard', 'nnoremap q :q'}, {'FileType', 'lspinfo', 'nnoremap q :q'}, - {'FileType', 'floaterm', 'nnoremap q :q'}, + {'FileType', 'floaterm', 'nnoremap q :q'} }, _auto_formatters = auto_formatters }) diff --git a/lua/lv-utils/init.lua b/lua/lv-utils/init.lua index 0fb30971..016bba62 100644 --- a/lua/lv-utils/init.lua +++ b/lua/lv-utils/init.lua @@ -22,169 +22,6 @@ function lv_utils.define_augroups(definitions) -- {{{1 end end --- lsp - -function lv_utils.add_to_workspace_folder() - vim.lsp.buf.add_workspace_folder() -end - -function lv_utils.clear_references() - vim.lsp.buf.clear_references() -end - -function lv_utils.code_action() - vim.lsp.buf.code_action() -end - -function lv_utils.declaration() - vim.lsp.buf.declaration() - vim.lsp.buf.clear_references() -end - -function lv_utils.definition() - vim.lsp.buf.definition() - vim.lsp.buf.clear_references() -end - -function lv_utils.document_highlight() - vim.lsp.buf.document_highlight() -end - -function lv_utils.document_symbol() - vim.lsp.buf.document_symbol() -end - -function lv_utils.formatting() - vim.lsp.buf.formatting() -end - -function lv_utils.formatting_sync() - vim.lsp.buf.formatting_sync() -end - -function lv_utils.hover() - vim.lsp.buf.hover() -end - -function lv_utils.implementation() - vim.lsp.buf.implementation() -end - -function lv_utils.incoming_calls() - vim.lsp.buf.incoming_calls() -end - -function lv_utils.list_workspace_folders() - vim.lsp.buf.list_workspace_folders() -end - -function lv_utils.outgoing_calls() - vim.lsp.buf.outgoing_calls() -end - -function lv_utils.range_code_action() - vim.lsp.buf.range_code_action() -end - -function lv_utils.range_formatting() - vim.lsp.buf.range_formatting() -end - -function lv_utils.references() - vim.lsp.buf.references() - vim.lsp.buf.clear_references() -end - -function lv_utils.remove_workspace_folder() - vim.lsp.buf.remove_workspace_folder() -end - -function lv_utils.rename() - vim.lsp.buf.rename() -end - -function lv_utils.signature_help() - vim.lsp.buf.signature_help() -end - -function lv_utils.type_definition() - vim.lsp.buf.type_definition() -end - -function lv_utils.workspace_symbol() - vim.lsp.buf.workspace_symbol() -end - --- diagnostic - -function lv_utils.get_all() - vim.lsp.diagnostic.get_all() -end - -function lv_utils.get_next() - vim.lsp.diagnostic.get_next() -end - -function lv_utils.get_prev() - vim.lsp.diagnostic.get_prev() -end - -function lv_utils.goto_next() - vim.lsp.diagnostic.goto_next() -end - -function lv_utils.goto_prev() - vim.lsp.diagnostic.goto_prev() -end - -function lv_utils.show_line_diagnostics() - vim.lsp.diagnostic.show_line_diagnostics() -end - --- git signs - -function lv_utils.next_hunk() - require('gitsigns').next_hunk() -end - -function lv_utils.prev_hunk() - require('gitsigns').prev_hunk() -end - -function lv_utils.stage_hunk() - require('gitsigns').stage_hunk() -end - -function lv_utils.undo_stage_hunk() - require('gitsigns').undo_stage_hunk() -end - -function lv_utils.reset_hunk() - require('gitsigns').reset_hunk() -end - -function lv_utils.reset_buffer() - require('gitsigns').reset_buffer() -end - -function lv_utils.preview_hunk() - require('gitsigns').preview_hunk() -end - -function lv_utils.blame_line() - require('gitsigns').blame_line() -end - --- misc -function lv_utils.file_exists(name) - local f = io.open(name, "r") - if f ~= nil then - io.close(f) - return true - else - return false - end -end return lv_utils diff --git a/lua/lv-which-key/init.lua b/lua/lv-which-key/init.lua index f3e05cad..3ca4a1cd 100644 --- a/lua/lv-which-key/init.lua +++ b/lua/lv-which-key/init.lua @@ -92,7 +92,7 @@ local mappings = { ["f"] = "Find File", ["h"] = "No Highlight", b = { - name = "+Buffers", + name = "Buffers", j = {"BufferPick", "jump to buffer"}, w = {"BufferWipeout", "wipeout buffer"}, e = { @@ -113,22 +113,31 @@ local mappings = { } }, - d = { - name = "Diagnostics", - t = {"TroubleToggle", "trouble"}, - w = {"TroubleToggle lsp_workspace_diagnostics", "workspace"}, - d = {"TroubleToggle lsp_document_diagnostics", "document"}, - q = {"TroubleToggle quickfix", "quickfix"}, - l = {"TroubleToggle loclist", "loclist"}, - r = {"TroubleToggle lsp_references", "references"} - }, +-- diagnostics vanilla nvim +-- -- diagnostic +-- function lv_utils.get_all() +-- vim.lsp.diagnostic.get_all() +-- end +-- function lv_utils.get_next() +-- vim.lsp.diagnostic.get_next() +-- end +-- function lv_utils.get_prev() +-- vim.lsp.diagnostic.get_prev() +-- end +-- function lv_utils.goto_next() +-- vim.lsp.diagnostic.goto_next() +-- end +-- function lv_utils.goto_prev() +-- vim.lsp.diagnostic.goto_prev() +-- end +-- function lv_utils.show_line_diagnostics() +-- vim.lsp.diagnostic.show_line_diagnostics() +-- end -- " Available Debug Adapters: -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/ - -- " -- " Adapter configuration and installation instructions: -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation - -- " -- " Debug Adapter protocol: -- " https://microsoft.github.io/debug-adapter-protocol/ -- " Debugging @@ -151,15 +160,15 @@ local mappings = { -- }, g = { name = "Git", - j = {"lua require 'lv-utils'.next_hunk()", "Next Hunk"}, - k = {"lua require 'lv-utils'.prev_hunk()", "Prev Hunk"}, - l = {"lua require 'lv-utils'.blame_line()", "Blame"}, - p = {"lua require 'lv-utils'.preview_hunk()", "Preview Hunk"}, - r = {"lua require 'lv-utils'.reset_hunk()", "Reset Hunk"}, - R = {"lua require 'lv-utils'.reset_buffer()", "Reset Buffer"}, - s = {"lua require 'lv-utils'.stage_hunk()", "Stage Hunk"}, + j = {"lua require 'gitsigns'.next_hunk()", "Next Hunk"}, + k = {"lua require 'gitsigns'.prev_hunk()", "Prev Hunk"}, + l = {"lua require 'gitsigns'.blame_line()", "Blame"}, + p = {"lua require 'gitsigns'.preview_hunk()", "Preview Hunk"}, + r = {"lua require 'gitsigns'.reset_hunk()", "Reset Hunk"}, + R = {"lua require 'gitsigns'.reset_buffer()", "Reset Buffer"}, + s = {"lua require 'gitsigns'.stage_hunk()", "Stage Hunk"}, u = { - "lua require 'lv-utils'.undo_stage_hunk()", + "lua require 'gitsigns'.undo_stage_hunk()", "Undo Stage Hunk" }, o = {"Telescope git_status", "Open changed file"}, @@ -182,7 +191,7 @@ local mappings = { "Telescope lsp_workspace_diagnostics", "Workspace Diagnostics" }, - f = {"lua require 'lv-utils'.formatting()", "Format"}, + f = {"lua vim.lsp.buf.formatting()", "Format"}, h = {"Lspsaga hover_doc", "Hover Doc"}, i = {"LspInfo", "Info"}, l = {"Lspsaga lsp_finder", "LSP Finder"}, @@ -209,17 +218,17 @@ local mappings = { name = "Search", b = {"Telescope git_branches", "Checkout branch"}, c = {"Telescope colorscheme", "Colorscheme"}, - d = { - "Telescope lsp_document_diagnostics", - "Document Diagnostics" - }, - D = { - "Telescope lsp_workspace_diagnostics", - "Workspace Diagnostics" - }, + -- d = { + -- "Telescope lsp_document_diagnostics", + -- "Document Diagnostics" + -- }, + -- D = { + -- "Telescope lsp_workspace_diagnostics", + -- "Workspace Diagnostics" + -- }, f = {"Telescope find_files", "Find File"}, h = {"Telescope help_tags", "Find Help"}, - m = {"Telescope marks", "Marks"}, + -- m = {"Telescope marks", "Marks"}, M = {"Telescope man_pages", "Man Pages"}, r = {"Telescope oldfiles", "Open Recent File"}, R = {"Telescope registers", "Registers"}, @@ -232,6 +241,18 @@ local mappings = { } } +if O.plugin.trouble.active then + mappings['d'] = { + name = "Diagnostics", + t = {"TroubleToggle", "trouble"}, + w = {"TroubleToggle lsp_workspace_diagnostics", "workspace"}, + d = {"TroubleToggle lsp_document_diagnostics", "document"}, + q = {"TroubleToggle quickfix", "quickfix"}, + l = {"TroubleToggle loclist", "loclist"}, + r = {"TroubleToggle lsp_references", "references"} + } +end + if O.plugin.gitlinker.active then mappings["gy"] = "Gitlink" end if O.plugin.zen.active then vim.api.nvim_set_keymap("n", "z", ":ZenMode", -- cgit v1.2.3