From b401dbb58739896380f1dbe0e0f1e014003d7cea Mon Sep 17 00:00:00 2001 From: sgoudham Date: Thu, 9 Feb 2023 06:47:01 +0000 Subject: [PATCH] refactor(nvim): move and change stuff, improve java lsp --- dot_config/nvim/init.lua | 3 + dot_config/nvim/lazy-lock.json | 4 +- dot_config/nvim/lua/binds.lua | 2 +- dot_config/nvim/lua/lsp/java.lua | 76 ++++++++++++---------- dot_config/nvim/lua/plugins/catppuccin.lua | 3 +- dot_config/nvim/lua/plugins/dap.lua | 54 ++++++++++++--- dot_config/nvim/lua/plugins/init.lua | 1 - dot_config/nvim/lua/plugins/lsp.lua | 12 +++- dot_config/nvim/lua/plugins/treesitter.lua | 5 +- 9 files changed, 107 insertions(+), 53 deletions(-) diff --git a/dot_config/nvim/init.lua b/dot_config/nvim/init.lua index 7c97291..0413f2e 100644 --- a/dot_config/nvim/init.lua +++ b/dot_config/nvim/init.lua @@ -4,6 +4,9 @@ vim.g.mapleader = " " vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 +vim.lsp.set_log_level("TRACE") +print(vim.lsp.get_log_path()) + -- bootstrap & set up lazy local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then diff --git a/dot_config/nvim/lazy-lock.json b/dot_config/nvim/lazy-lock.json index 560e0be..82ba67e 100644 --- a/dot_config/nvim/lazy-lock.json +++ b/dot_config/nvim/lazy-lock.json @@ -17,7 +17,7 @@ "feline.nvim": { "branch": "master", "commit": "d48b6f92c6ccdd6654c956f437be49ea160b5b0c" }, "gitsigns.nvim": { "branch": "main", "commit": "ec4742a7eebf68bec663041d359b95637242b5c3" }, "haskell-tools.nvim": { "branch": "master", "commit": "03dfa7fa3d08a34cdef09ca05a6da166a1ba22a2" }, - "lazy.nvim": { "branch": "main", "commit": "48c9b37294f31e3875435bca41d0c923fdd6eea4" }, + "lazy.nvim": { "branch": "main", "commit": "3d2dcb2d5ef99106c5ff412da88c6f59a9f8a693" }, "lsp-format.nvim": { "branch": "master", "commit": "ca0df5c8544e51517209ea7b86ecc522c98d4f0a" }, "lsp_signature.nvim": { "branch": "master", "commit": "6f6252f63b0baf0f2224c4caea33819a27f3f550" }, "lspkind.nvim": { "branch": "master", "commit": "c68b3a003483cf382428a43035079f78474cd11e" }, @@ -37,13 +37,13 @@ "nvim-dap-virtual-text": { "branch": "master", "commit": "7f7f2af549e72a0b7bddc3b4f827beb027ea8ce3" }, "nvim-jdtls": { "branch": "master", "commit": "1f640d14d17f20cfc63c1acc26a10f9466e66a75" }, "nvim-lspconfig": { "branch": "master", "commit": "902d6aa31450d26e11bedcbef8af5b6fe2e1ffe8" }, - "nvim-navic": { "branch": "master", "commit": "11e08391eeed00effa85ca24ff9d1e0472cbcd6a" }, "nvim-surround": { "branch": "main", "commit": "ad56e6234bf42fb7f7e4dccc7752e25abd5ec80e" }, "nvim-tree.lua": { "branch": "master", "commit": "215b29bfad74518442621b9d0483a621483b066b" }, "nvim-treesitter": { "branch": "master", "commit": "0e6d4b4172f30c4aa44a9adc9ea5719723a1fac3" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "249d90a84df63f3ffff65fcc06a45d58415672de" }, "nvim-web-devicons": { "branch": "master", "commit": "2b96193abe4372e18e4f4533895a42a466d53c17" }, "overseer.nvim": { "branch": "master", "commit": "42c0d69f505314d6994a84da4e3fcbaf308c1a86" }, + "playground": { "branch": "master", "commit": "c481c660fa903a0e295902b1765ecfbd6e76a556" }, "plenary.nvim": { "branch": "master", "commit": "9a0d3bf7b832818c042aaf30f692b081ddd58bd9" }, "presence.nvim": { "branch": "main", "commit": "87c857a56b7703f976d3a5ef15967d80508df6e6" }, "project.nvim": { "branch": "main", "commit": "685bc8e3890d2feb07ccf919522c97f7d33b94e4" }, diff --git a/dot_config/nvim/lua/binds.lua b/dot_config/nvim/lua/binds.lua index fa0049d..aaa48c7 100644 --- a/dot_config/nvim/lua/binds.lua +++ b/dot_config/nvim/lua/binds.lua @@ -50,7 +50,7 @@ wk.register({ -- nv leader binds wk.register({ - d = { [["_d]], "Delete w/o yank" }, + -- d = { [["_d]], "Delete w/o yank" }, y = { [["+y]], "Yank to clipboard" }, }, { prefix = "", mode = { "n", "v" } }) diff --git a/dot_config/nvim/lua/lsp/java.lua b/dot_config/nvim/lua/lsp/java.lua index 8643125..f9fe4dc 100644 --- a/dot_config/nvim/lua/lsp/java.lua +++ b/dot_config/nvim/lua/lsp/java.lua @@ -5,9 +5,7 @@ local SDKMAN_DIR = os.getenv("SDKMAN_DIR") local lsp = require("lsp") local jdtls = require("jdtls") --- File types that signify a Java project's root directory. This will be --- used by eclipse to determine what constitutes a workspace -local root_markers = { "gradlew", "mvnw", ".git" } +local root_markers = { "gradlew", "mvnw", ".git", "pom.xml", "build.gradle" } local root_dir = require("jdtls.setup").find_root(root_markers) -- eclipse.jdt.ls stores project specific data within a folder. If you are working @@ -16,15 +14,26 @@ local root_dir = require("jdtls.setup").find_root(root_markers) -- current project found using the root_marker as the folder for project specific data. local workspace_folder = HOME .. "/.local/share/eclipse/" .. vim.fn.fnamemodify(root_dir, ":p:h:t") --- Helper function for creating keymaps -function nnoremap(rhs, lhs, bufopts, desc) +local bundles = {} +local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason/") +vim.list_extend(bundles, vim.split(vim.fn.glob(mason_path .. "packages/java-test/extension/server/*.jar"), "\n")) +vim.list_extend( + bundles, + vim.split( + vim.fn.glob(mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar"), + "\n" + ) +) + +local function nnoremap(rhs, lhs, bufopts, desc) bufopts.desc = desc vim.keymap.set("n", rhs, lhs, bufopts) end --- The on_attach function is used to set key maps after the language server --- attaches to the current buffer local on_attach = function(client, bufnr) + require("jdtls").setup_dap({ hotcodereplace = "auto" }) + require("jdtls.dap").setup_dap_main_class_configs() + require("jdtls.setup").add_commands() lsp.default_config.on_attach(client, bufnr) -- Regular Neovim LSP client keymappings @@ -45,36 +54,35 @@ local on_attach = function(client, bufnr) [[lua require('jdtls').extract_method(true)]], { noremap = true, silent = true, buffer = bufnr, desc = "Extract method" } ) + nnoremap("tc", jdtls.test_class, bufopts, "Test class (DAP)") + nnoremap("tm", jdtls.test_nearest_method, bufopts, "Test method (DAP)") end local config = { flags = { debounce_text_changes = 80, + allow_incremental_sync = true, + }, + on_attach = on_attach, + root_dir = root_dir, + init_options = { + bundles = bundles, }, - on_attach = on_attach, -- We pass our on_attach keybindings to the configuration map - root_dir = root_dir, -- Set the root directory to our found root_marker - -- Here you can configure eclipse.jdt.ls specific settings - -- These are defined by the eclipse.jdt.ls project and will be passed to eclipse when starting. - -- 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 + + -- https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request settings = { java = { format = { settings = { - -- Use Google Java style guidelines for formatting - -- To use, make sure to download the file from https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml - -- and place it in the ~/.local/share/eclipse directory + -- https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml url = "/.local/share/eclipse/eclipse-java-google-style.xml", profile = "GoogleStyle", }, }, - implementationsCodeLens = { enabled = true }, - referenceCodeLens = { enabled = true }, - signatureHelp = { enabled = true }, contentProvider = { preferred = "fernflower" }, -- Use fernflower to decompile library code -- Specify any completion options completion = { - maxResults = 20, + maxResults = 30, postfix = { enabled = true }, favoriteStaticMembers = { "org.hamcrest.MatcherAssert.assertThat", @@ -93,6 +101,13 @@ local config = { "sun.*", }, }, + -- LSP Related + implementationsCodeLens = { enabled = true }, + referenceCodeLens = { enabled = true }, + signatureHelp = { enabled = true }, + inlayHints = { + parameterNames = { enabled = true }, + }, -- Specify any options for organizing imports sources = { organizeImports = { @@ -100,11 +115,14 @@ local config = { staticStarThreshold = 9999, }, }, + maven = { + downloadSources = true, + updateSnapshots = true, + }, -- On Save Cleanup cleanup = { actionsOnSave = { "addOverride", - "qualifyStaticMembers", }, }, -- How code generation should act @@ -117,11 +135,8 @@ local config = { }, useBlocks = true, }, - -- If you are developing in projects with different Java versions, you need - -- to tell eclipse.jdt.ls to use the location of the JDK for your Java version - -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request - -- And search for `interface RuntimeOption` - -- The `name` is NOT arbitrary, but must match one of the elements from `enum ExecutionEnvironment` in the link above + -- https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request + -- `interface RuntimeOption` configuration = { maven = { userSettings = HOME .. "/.m2/settings.xml", @@ -143,11 +158,8 @@ local config = { }, }, }, - -- cmd is the command that starts the language server. Whatever is placed - -- here is what is passed to the command line to execute jdtls. -- Note that eclipse.jdt.ls must be started with a Java version of 17 or higher -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line - -- for the full list of options cmd = { SDKMAN_DIR .. "/candidates/java/17.0.5-amzn/bin/java", "-Declipse.application=org.eclipse.jdt.ls.core.id1", @@ -166,18 +178,12 @@ local config = { -- .. HOME -- .. "/.local/share/eclipse/lombok.jar", - -- The jar file is located where jdtls was installed. This will need to be updated - -- to the location where you installed jdtls "-jar", - -- HOME .. "/.local/share/eclipse.jdt.ls/bin", vim.fn.glob(HOME .. "/.local/share/eclipse.jdt.ls/plugins/org.eclipse.equinox.launcher_*.jar"), - -- The configuration for jdtls is also placed where jdtls was installed. This will - -- need to be updated depending on your environment "-configuration", HOME .. "/.local/share/eclipse.jdt.ls/config_linux", - -- Use the workspace_folder defined above to store data for this project "-data", workspace_folder, }, diff --git a/dot_config/nvim/lua/plugins/catppuccin.lua b/dot_config/nvim/lua/plugins/catppuccin.lua index e97d84b..f568787 100644 --- a/dot_config/nvim/lua/plugins/catppuccin.lua +++ b/dot_config/nvim/lua/plugins/catppuccin.lua @@ -41,7 +41,8 @@ return { }, custom_highlights = { ErrorMsg = { fg = cp.red, style = { "bold" } }, - ["@function.builtin"] = { fg = cp.blue }, + ["@method.call"] = { fg = cp.blue }, + ["@constant"] = { fg = cp.sapphire }, LspInfoBorder = { link = "FloatBorder" }, PmenuSel = { bg = cp.surface0 }, FloatBorder = { fg = cp.overlay0, bg = "NONE" }, diff --git a/dot_config/nvim/lua/plugins/dap.lua b/dot_config/nvim/lua/plugins/dap.lua index 7bb34fa..1136da6 100644 --- a/dot_config/nvim/lua/plugins/dap.lua +++ b/dot_config/nvim/lua/plugins/dap.lua @@ -1,5 +1,5 @@ local get_python_path = function() - for _, client in pairs(vim.lsp.buf_get_clients()) do + for _, client in pairs(vim.lsp.get_active_clients()) do if client.name == "pyright" then local path = client.config.settings.python.pythonPath if path ~= nil then @@ -62,11 +62,52 @@ return { sign("DapLogPoint", { text = "◆", texthl = "DapLogPoint", linehl = "", numhl = "" }) end, keys = { + { "bb", vim.cmd.DapToggleBreakpoint, desc = "Toggle Breakpoint" }, { - "db", - vim.cmd.DapToggleBreakpoint, - desc = "Toggle breakpoint", + "bf", + function() + require("dap").list_breakpoints() + end, + desc = "List Breakpoints", + }, + { + "bc", + function() + require("dap").clear_breakpoints() + end, + desc = "Clear Breakpoints", + }, + + { "dc", vim.cmd.DapContinue, desc = "Start / Continue" }, + { + "dj", + function() + require("dap").step_over() + end, + desc = "Step Over", + }, + { + "dk", + function() + require("dap").step_into() + end, + desc = "Step Into", }, + { + "do", + function() + require("dap").step_out() + end, + desc = "Step Out", + }, + { + "dd", + function() + require("dap").disconnect() + end, + desc = "Disconnect", + }, + { "du", function() @@ -74,11 +115,6 @@ return { end, desc = "Toggle UI", }, - { - "dx", - vim.cmd.DapContinue, - desc = "Start / Continue", - }, }, dependencies = { "williamboman/mason.nvim", diff --git a/dot_config/nvim/lua/plugins/init.lua b/dot_config/nvim/lua/plugins/init.lua index e8d16ab..feacb47 100644 --- a/dot_config/nvim/lua/plugins/init.lua +++ b/dot_config/nvim/lua/plugins/init.lua @@ -5,5 +5,4 @@ return { "stevearc/dressing.nvim", "mong8se/actually.nvim", "andweeb/presence.nvim", - "mfussenegger/nvim-jdtls" } diff --git a/dot_config/nvim/lua/plugins/lsp.lua b/dot_config/nvim/lua/plugins/lsp.lua index 50235cc..0be1e05 100644 --- a/dot_config/nvim/lua/plugins/lsp.lua +++ b/dot_config/nvim/lua/plugins/lsp.lua @@ -114,11 +114,17 @@ return { "simrat39/rust-tools.nvim", "mrcjkb/haskell-tools.nvim", "HallerPatrick/py_lsp.nvim", - { "SmiteshP/nvim-navic", config = { highlight = true } }, + "mfussenegger/nvim-jdtls", "onsails/lspkind.nvim", - { "lukas-reineke/lsp-format.nvim", config = true }, - "folke/neodev.nvim", "ray-x/lsp_signature.nvim", + { + "lukas-reineke/lsp-format.nvim", + config = { + java = { + exclude = { "jdtls" }, + }, + }, + }, }, }, { diff --git a/dot_config/nvim/lua/plugins/treesitter.lua b/dot_config/nvim/lua/plugins/treesitter.lua index 5ca48d8..86bd94e 100644 --- a/dot_config/nvim/lua/plugins/treesitter.lua +++ b/dot_config/nvim/lua/plugins/treesitter.lua @@ -26,6 +26,9 @@ return { }, }) end, - dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" }, + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects", + "nvim-treesitter/playground", + }, }, }