From 8674b854949f3b16e9b89f6482b60d1b79ceeda0 Mon Sep 17 00:00:00 2001 From: Stephens Jean-Jacques Date: Tue, 12 Sep 2023 22:59:41 -0400 Subject: [PATCH] updated neovim config --- ftplugin/java.lua | 196 ++++++++++++++++++++++++++++++++++++++++++++++ init.lua | 40 +++++++++- 2 files changed, 232 insertions(+), 4 deletions(-) create mode 100644 ftplugin/java.lua diff --git a/ftplugin/java.lua b/ftplugin/java.lua new file mode 100644 index 00000000..05c70ad3 --- /dev/null +++ b/ftplugin/java.lua @@ -0,0 +1,196 @@ +local capabilities = vim.lsp.protocol.make_client_capabilities() +local path = {} + +path.data_dir = vim.fn.stdpath('cache') .. '/nvim-jdtls' +local data_dir = path.data_dir .. '/' .. vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t') + +local jdtls_install = require('mason-registry') + .get_package('jdtls') + :get_install_path() + +path.java_agent = jdtls_install .. '/lombok.jar' +path.launcher_jar = vim.fn.glob(jdtls_install .. '/plugins/org.eclipse.equinox.launcher_*.jar') +path.platform_config = jdtls_install .. '/config_mac' + + +-- See `:help vim.lsp.start_client` for an overview of the supported `config` options. +local config = { + -- The command that starts the language server + -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line + cmd = { + + -- 💀 + -- 'java', -- or '/path/to/java17_or_newer/bin/java' + -- depends on if `java` is in your $PATH env variable and if it points to the right version. + '/Library/Java/JavaVirtualMachines/temurin-19.jdk/Contents/Home/bin/java', + -- '/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/bin/java', + -- '/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home/bin/java', + + '-Declipse.application=org.eclipse.jdt.ls.core.id1', + '-Dosgi.bundles.defaultStartLevel=4', + '-Declipse.product=org.eclipse.jdt.ls.core.product', + '-Dlog.protocol=true', + '-Dlog.level=ALL', + '-javaagent:' .. path.java_agent, + '-Xmx1g', + '--add-modules=ALL-SYSTEM', + '--add-opens', 'java.base/java.util=ALL-UNNAMED', + '--add-opens', 'java.base/java.lang=ALL-UNNAMED', + + -- 💀 + -- '-jar', '/path/to/jdtls_install_location/plugins/org.eclipse.equinox.launcher_VERSION_NUMBER.jar', + '-jar', path.launcher_jar, + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ + -- Must point to the Change this to + -- eclipse.jdt.ls installation the actual version + + + -- 💀 + -- '-configuration', '/path/to/jdtls_install_location/config_SYSTEM', + '-configuration', path.platform_config, + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^ + -- Must point to the Change to one of `linux`, `win` or `mac` + -- eclipse.jdt.ls installation Depending on your system. + + + -- 💀 + -- See `data directory configuration` section in the README + -- '-data', '/path/to/unique/per/project/workspace/folder' + '-data', data_dir, + }, + + -- 💀 + -- This is the default if not provided, you can remove it. Or adjust as needed. + -- One dedicated LSP server & client will be started per unique root_dir + -- root_dir = require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew', 'pom.xml', 'build.gradle'}), + root_dir = vim.fs.dirname(vim.fs.find({ '.git', 'mvnw', 'gradlew', 'pom.xml', 'build.gradle' }, { upward = true }) + [1]), + -- Here you can configure eclipse.jdt.ls specific settings + -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request + -- for a list of options + settings = { + java = { + home = '/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home', + eclipse = { + downloadSources = true, + }, + maven = { + downloadSources = true, + }, + configuration = { + updateBuildConfiguration = "interactive", + runtimes = { + name = 'JavaSE-1.8', + path = '/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home', + default = true, + }, + -- runtimes = { + -- name = 'JavaSE-19', + -- path = '/Library/Java/JavaVirtualMachines/temurin-19.jdk', + -- default = true, + -- }, + }, + import = { + gradle = { + enabled = true, + java = { + home = '/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home', + }, + } + } + } + }, + + -- Language server `initializationOptions` + -- You need to extend the `bundles` with paths to jar files + -- if you want to use additional eclipse.jdt.ls plugins. + -- + -- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation + -- + -- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this + init_options = { + bundles = {} + }, + on_attach = function(client, bufnr) + -- Diagnostic keymaps + -- vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) + -- vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) + -- vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) + -- vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) + + -- [[ Configure LSP ]] + -- This function gets run when an LSP connects to a particular buffer. + -- local on_attach = function(_, bufnr) + -- NOTE: Remember that lua is a real programming language, and as such it is possible + -- to define small helper and utility functions so you don't have to repeat yourself + -- many times. + -- + -- In this case, we create a function that lets us more easily define mappings specific + -- for LSP related items. It sets the mode, buffer and description for us each time. + local nmap = function(keys, func, desc) + if desc then + desc = 'LSP: ' .. desc + end + + vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) + end + + nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') + nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') + + nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') + nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') + nmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') + nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + + -- See `:help K` for why this keymap + nmap('K', vim.lsp.buf.hover, 'Hover Documentation') + nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') + + -- Lesser used LSP functionality + nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') + nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') + nmap('wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, '[W]orkspace [L]ist Folders') + + -- Create a command `:Format` local to the LSP buffer + vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) + vim.lsp.buf.format() + end, { desc = 'Format current buffer with LSP' }) + -- end + end +} + +-- This starts a new client & server, +-- or attaches to an existing client & server depending on the `root_dir`. +require('jdtls').start_or_attach(config) + +-- local opts = { +-- noremap = true, +-- silent = true, +-- } +-- vim.keymap.set('n', 'q', vim.diagnostic.setloclist) +-- vim.api.nvim_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) +-- vim.api.nvim_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) +-- vim.api.nvim_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) +-- vim.api.nvim_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) +-- vim.api.nvim_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) +-- vim.api.nvim_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) +-- vim.api.nvim_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) +-- vim.api.nvim_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) +-- vim.api.nvim_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) +-- vim.api.nvim_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) +-- vim.api.nvim_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) +-- vim.api.nvim_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) +-- vim.api.nvim_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next', opts) +-- vim.api.nvim_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev', opts) +-- -- vim.api.nvim_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) +-- vim.api.nvim_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) +-- vim.api.nvim_set_keymap('n', 'lg', 'lua vim.lsp.buf.formatting_sync(nil, 1000)', opts) +-- +-- vim.api.nvim_set_keymap('n', 'lA', 'lua vim.lsp.buf.code_action()', { silent = true }) +-- vim.api.nvim_set_keymap('n', 'lA', 'lua require(\'jdtls\').code_action()', { silent = true }) diff --git a/init.lua b/init.lua index 1332c3b9..c3ad29fd 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: missing-fields --[[ ===================================================================== @@ -84,9 +85,13 @@ require('lazy').setup({ { 'williamboman/mason.nvim', config = true }, 'williamboman/mason-lspconfig.nvim', + -- Extensions for the built-in LSP support in Neovim + -- for eclipse.jdt.ls to enable LSPs for Java + 'mfussenegger/nvim-jdtls', + -- Useful status updates for LSP -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` - { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, + { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, -- Additional lua configuration, makes nvim stuff amazing! 'folke/neodev.nvim', @@ -110,7 +115,7 @@ require('lazy').setup({ }, -- Useful plugin to show you pending keybinds. - { 'folke/which-key.nvim', opts = {} }, + { 'folke/which-key.nvim', opts = {} }, { -- Adds git related signs to the gutter, as well as utilities for managing changes 'lewis6991/gitsigns.nvim', @@ -124,7 +129,8 @@ require('lazy').setup({ changedelete = { text = '~' }, }, on_attach = function(bufnr) - vim.keymap.set('n', 'gp', require('gitsigns').prev_hunk, { buffer = bufnr, desc = '[G]o to [P]revious Hunk' }) + vim.keymap.set('n', 'gp', require('gitsigns').prev_hunk, + { buffer = bufnr, desc = '[G]o to [P]revious Hunk' }) vim.keymap.set('n', 'gn', require('gitsigns').next_hunk, { buffer = bufnr, desc = '[G]o to [N]ext Hunk' }) vim.keymap.set('n', 'ph', require('gitsigns').preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' }) end, @@ -189,6 +195,23 @@ require('lazy').setup({ }, }, + { 'echasnovski/mini.pairs', version = false }, + + { + "folke/flash.nvim", + event = "VeryLazy", + ---@type Flash.Config + opts = {}, + -- stylua: ignore + keys = { + { "s", mode = { "n", "o", "x" }, function() require("flash").jump() end, desc = "Flash" }, + { "S", mode = { "n", "o", "x" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, + { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, + { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, + { "", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, + }, + }, + { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', @@ -254,6 +277,9 @@ vim.o.completeopt = 'menuone,noselect' -- NOTE: You should make sure your terminal supports this vim.o.termguicolors = true +-- Center the cursor in the middle of the screen when scrolling +vim.o.scrolloff = 999 + -- [[ Basic Keymaps ]] -- Keymaps for better default experience @@ -439,7 +465,7 @@ local servers = { -- gopls = {}, -- pyright = {}, -- rust_analyzer = {}, - -- tsserver = {}, + tsserver = {}, -- html = { filetypes = { 'html', 'twig', 'hbs'} }, lua_ls = { @@ -450,9 +476,13 @@ local servers = { }, } +require('flash').toggle(false) + -- Setup neovim lua configuration require('neodev').setup() +require('mini.pairs').setup() + -- nvim-cmp supports additional completion capabilities, so broadcast that to servers local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) @@ -475,6 +505,8 @@ mason_lspconfig.setup_handlers { end } +vim.lsp.set_log_level('debug') + -- [[ Configure nvim-cmp ]] -- See `:help cmp` local cmp = require 'cmp'