From 524afbb9aa114b5a58494d3e27e4648594b0b47e Mon Sep 17 00:00:00 2001 From: Amanda Graven Date: Sat, 17 Jun 2023 10:13:05 +0200 Subject: [PATCH] jdtls, sqls, more leader mappings --- init.lua | 120 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 106 insertions(+), 14 deletions(-) diff --git a/init.lua b/init.lua index 9b3bec0..157997b 100644 --- a/init.lua +++ b/init.lua @@ -144,7 +144,7 @@ do end end vim.cmd [[ -tnoremap ' +tnoremap ]] -- Commands @@ -174,7 +174,7 @@ au('BufWritePost', { desc = 'Reload config when it is saved, and compile packer cache', }) au('TextYankPost', { - callback = vim.highlight.on_yank, + callback = function() vim.highlight.on_yank() end, desc = 'Highlight when text is yanked', }) au('BufReadPost', { @@ -290,6 +290,8 @@ require'packer'.startup(function(use) use 'hrsh7th/cmp-buffer' use 'hrsh7th/cmp-path' use 'hrsh7th/cmp-cmdline' + use 'nanotee/sqls.nvim' + use 'mfussenegger/nvim-jdtls' use 'simrat39/rust-tools.nvim' use {'jose-elias-alvarez/null-ls.nvim', requires = {'nvim-lua/plenary.nvim'}, config = function () local null_ls = require'null-ls' @@ -302,7 +304,9 @@ require'packer'.startup(function(use) end} use 'SmiteshP/nvim-navic' use {'utilyre/barbecue.nvim', config = function () - require'barbecue'.setup() + require'barbecue'.setup { + show_modified = true, + } end} -- UI elements -- @@ -380,7 +384,7 @@ require'packer'.startup(function(use) r = {dap.step_back, 'Step back'}, R = {dap.reverse_continue, 'Continue backwards'}, C = {dap.run_to_cursor, 'Continue to cursor'}, - p = {dap.paise, 'Pause execution'} + p = {dap.pause, 'Pause execution'} } } end} @@ -475,7 +479,7 @@ require'packer'.startup(function(use) }, } end} - use 'j-hui/fidget.nvim' + use {'j-hui/fidget.nvim', branch = 'legacy'} use 'tpope/vim-fugitive' use 'tpope/vim-rhubarb' use 'shumphrey/fugitive-gitlab.vim' @@ -498,7 +502,16 @@ require'packer'.startup(function(use) end} use {'williamboman/mason-lspconfig.nvim', config = function() require'mason-lspconfig'.setup { - automatic_installation = true, + automatic_installation = true + -- figure out how to ensure java-test and java-debug-adapter + } + end} + use {'TimUntersberger/neogit', config = function () + require'neogit'.setup { + disable_context_highlighting = true, + integrations = { + diffview = true, + }, } end} use {'rcarriga/nvim-notify', after = 'telescope.nvim', config = function () @@ -558,6 +571,7 @@ require'packer'.startup(function(use) h = {'Telescope help_tags', 'Help page'}, p = {'Telescope project', 'Projects'}, s = {'Telescope lsp_dynamic_workspace_symbols', 'Symbols'}, + S = {'Telescope lsp_document_symbols', 'Symbols - current file'}, n = {'Telescope notify', 'Notifications'}, m = {'Telescope man_pages', 'Man pages'}, [':'] = {'Telescope commands', 'Commands'}, @@ -696,6 +710,8 @@ require'gitsigns'.setup { v = {gitsigns.select_hunk, 'Visual select hunk'}, d = {gitsigns.toggle_deleted, 'Toggle deleted lines'}, w = {gitsigns.toggle_word_diff, 'Toggle word diffs'}, + l = {gitsigns.blame_line, 'Blame current line'}, + L = {gitsigns.toggle_line_blame, 'Toggle line blame'}, b = {':Gitsigns change_base ', 'Change diff base'}, B = {gitsigns.reset_base, 'Reset diff base'}, } @@ -783,6 +799,14 @@ local capabilities = require'cmp_nvim_lsp'.default_capabilities() local function on_attach(client, bufnr) require'which-key'.register({ + ['l'] = { + d = {vim.lsp.buf.definition, 'Goto definition'}, + D = {vim.lsp.buf.implementation, 'Goto implementation'}, + a = {vim.lsp.buf.code_action, 'Code action'}, + r = {vim.lsp.buf.rename, 'Rename'}, + t = {vim.lsp.buf.type_definition, 'Type definition'}, + u = {vim.lsp.buf.references, 'Usages/references'} + }, g = { d = {vim.lsp.buf.definition, 'Goto definition'}, D = {vim.lsp.buf.implementation, 'Goto implementation'}, @@ -849,9 +873,78 @@ require'lspconfig'.lua_ls.setup { require'lspconfig'.bashls.setup(default) require'lspconfig'.clangd.setup(default) -require'lspconfig'.jdtls.setup(default) +au('FileType', { + pattern = 'java', + callback = function () + local ok, jdtls = pcall(require, 'jdtls') + if not ok then return end + + local path = vim.fn.stdpath('data') .. '/mason/packages/jdtls' + local root_dir = jdtls.setup.find_root({'.git', 'mvnw', 'gradlew'}) + + local config = { + -- The command to launch jdtls with + cmd = { + 'jdtls', + -- Enable logging + '--jvm-arg=-Dlog.level=ALL', + '--jvm-arg=-Dlog.protocol=true', + -- Enable lombok + '--jvm-arg=-javaagent:' .. path .. '/lombok.jar', + -- store workpace data in ~/.local/share/eclipse/ + '-data', vim.fn.expand('~/.local/share/eclipse/') .. vim.fn.fnamemodify(root_dir, ':p:h:t') + }, + + root_dir = root_dir, + + settings = { + java = {}, + }, + + init_options = { + -- JDTLS plugins + bundles = (function () + -- add java-debug-adapter + local bundles = { + vim.fn.glob(vim.fn.stdpath('data') .. '/mason/packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar', 1) + } + -- add java-test + vim.list_extend(bundles, vim.split( + vim.fn.glob(vim.fn.stdpath'data' .. '/mason/packages/java-test/extension/server/*.jar', 1), + '\n' + )) + + return bundles + end)(), + }, + + on_attach = function (client, bufnr) + on_attach(client, bufnr) + jdtls.setup_dap() + jdtls.setup.add_commands() + end, + } + + jdtls.start_or_attach(config) + end +}) require'lspconfig'.nil_ls.setup(default) require'lspconfig'.pyright.setup(default) +-- Defer setup to silence deprecation notice +au('FileType', { + pattern = 'sql', + callback = function () + require'lspconfig'.sqls.setup { + capabilities = capabilities, + on_attach = function (client, bufnr) + on_attach(client, bufnr) + local ok, sqls = pcall(require, 'sqls') + if not ok then return end + sqls.on_attach(client, bufnr) + end + } + end, +}) require'lspconfig'.tsserver.setup(default) require'lspconfig'.vimls.setup(default) @@ -954,7 +1047,7 @@ g.startify_lists = { ---- symbols-outline ---- -vim.g.symbols_outline = { +require'symbols-outline'.setup { -- Don't display preview automatically auto_preview = false, -- Don't highlight the hovered item @@ -1021,14 +1114,13 @@ require('nvim-tree').setup { }, -- Match tree cwd to vim's cwd update_cwd = true, + view = { + width = 45, + }, } vim.cmd'highlight NvimTreeOpenedFile guifg=NONE guibg=NONE gui=italic' -au('ColorScheme', { - desc = 'Change NvimTreeOpenedFile highlight', - command = 'highlight NvimTreeOpenedFile guifg=NONE guibg=NONE gui=italic' -}) -vim.keymap.set('n', 't', 'NvimTreeFindFileToggle', {desc = 'Nvim Tree'}) +vim.keymap.set('n', 't', 'NvimTreeFindFile', {desc = 'Nvim Tree'}) ---- treesitter ---- @@ -1038,7 +1130,7 @@ require'nvim-treesitter.configs'.setup { enable = true, }, ensure_installed = {'lua', 'html', 'c', 'cpp', 'nix', 'vim', 'rust', 'bash', 'markdown', 'java', 'markdown_inline'}, - highlight = { enable = true, disable = 'rust' }, + highlight = { enable = true, disable = {'rust', 'bash'} }, incremental_selection = { enable = true }, }