refactor(nvim): move and change stuff, improve java lsp

chezmoi
sgoudham 2 years ago
parent 525db2a20e
commit b401dbb587
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -4,6 +4,9 @@ vim.g.mapleader = " "
vim.g.loaded_netrw = 1 vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1 vim.g.loaded_netrwPlugin = 1
vim.lsp.set_log_level("TRACE")
print(vim.lsp.get_log_path())
-- bootstrap & set up lazy -- bootstrap & set up lazy
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then if not vim.loop.fs_stat(lazypath) then

@ -17,7 +17,7 @@
"feline.nvim": { "branch": "master", "commit": "d48b6f92c6ccdd6654c956f437be49ea160b5b0c" }, "feline.nvim": { "branch": "master", "commit": "d48b6f92c6ccdd6654c956f437be49ea160b5b0c" },
"gitsigns.nvim": { "branch": "main", "commit": "ec4742a7eebf68bec663041d359b95637242b5c3" }, "gitsigns.nvim": { "branch": "main", "commit": "ec4742a7eebf68bec663041d359b95637242b5c3" },
"haskell-tools.nvim": { "branch": "master", "commit": "03dfa7fa3d08a34cdef09ca05a6da166a1ba22a2" }, "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-format.nvim": { "branch": "master", "commit": "ca0df5c8544e51517209ea7b86ecc522c98d4f0a" },
"lsp_signature.nvim": { "branch": "master", "commit": "6f6252f63b0baf0f2224c4caea33819a27f3f550" }, "lsp_signature.nvim": { "branch": "master", "commit": "6f6252f63b0baf0f2224c4caea33819a27f3f550" },
"lspkind.nvim": { "branch": "master", "commit": "c68b3a003483cf382428a43035079f78474cd11e" }, "lspkind.nvim": { "branch": "master", "commit": "c68b3a003483cf382428a43035079f78474cd11e" },
@ -37,13 +37,13 @@
"nvim-dap-virtual-text": { "branch": "master", "commit": "7f7f2af549e72a0b7bddc3b4f827beb027ea8ce3" }, "nvim-dap-virtual-text": { "branch": "master", "commit": "7f7f2af549e72a0b7bddc3b4f827beb027ea8ce3" },
"nvim-jdtls": { "branch": "master", "commit": "1f640d14d17f20cfc63c1acc26a10f9466e66a75" }, "nvim-jdtls": { "branch": "master", "commit": "1f640d14d17f20cfc63c1acc26a10f9466e66a75" },
"nvim-lspconfig": { "branch": "master", "commit": "902d6aa31450d26e11bedcbef8af5b6fe2e1ffe8" }, "nvim-lspconfig": { "branch": "master", "commit": "902d6aa31450d26e11bedcbef8af5b6fe2e1ffe8" },
"nvim-navic": { "branch": "master", "commit": "11e08391eeed00effa85ca24ff9d1e0472cbcd6a" },
"nvim-surround": { "branch": "main", "commit": "ad56e6234bf42fb7f7e4dccc7752e25abd5ec80e" }, "nvim-surround": { "branch": "main", "commit": "ad56e6234bf42fb7f7e4dccc7752e25abd5ec80e" },
"nvim-tree.lua": { "branch": "master", "commit": "215b29bfad74518442621b9d0483a621483b066b" }, "nvim-tree.lua": { "branch": "master", "commit": "215b29bfad74518442621b9d0483a621483b066b" },
"nvim-treesitter": { "branch": "master", "commit": "0e6d4b4172f30c4aa44a9adc9ea5719723a1fac3" }, "nvim-treesitter": { "branch": "master", "commit": "0e6d4b4172f30c4aa44a9adc9ea5719723a1fac3" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "249d90a84df63f3ffff65fcc06a45d58415672de" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "249d90a84df63f3ffff65fcc06a45d58415672de" },
"nvim-web-devicons": { "branch": "master", "commit": "2b96193abe4372e18e4f4533895a42a466d53c17" }, "nvim-web-devicons": { "branch": "master", "commit": "2b96193abe4372e18e4f4533895a42a466d53c17" },
"overseer.nvim": { "branch": "master", "commit": "42c0d69f505314d6994a84da4e3fcbaf308c1a86" }, "overseer.nvim": { "branch": "master", "commit": "42c0d69f505314d6994a84da4e3fcbaf308c1a86" },
"playground": { "branch": "master", "commit": "c481c660fa903a0e295902b1765ecfbd6e76a556" },
"plenary.nvim": { "branch": "master", "commit": "9a0d3bf7b832818c042aaf30f692b081ddd58bd9" }, "plenary.nvim": { "branch": "master", "commit": "9a0d3bf7b832818c042aaf30f692b081ddd58bd9" },
"presence.nvim": { "branch": "main", "commit": "87c857a56b7703f976d3a5ef15967d80508df6e6" }, "presence.nvim": { "branch": "main", "commit": "87c857a56b7703f976d3a5ef15967d80508df6e6" },
"project.nvim": { "branch": "main", "commit": "685bc8e3890d2feb07ccf919522c97f7d33b94e4" }, "project.nvim": { "branch": "main", "commit": "685bc8e3890d2feb07ccf919522c97f7d33b94e4" },

@ -50,7 +50,7 @@ wk.register({
-- nv leader binds -- nv leader binds
wk.register({ wk.register({
d = { [["_d]], "Delete w/o yank" }, -- d = { [["_d]], "Delete w/o yank" },
y = { [["+y]], "Yank to clipboard" }, y = { [["+y]], "Yank to clipboard" },
}, { prefix = "<leader>", mode = { "n", "v" } }) }, { prefix = "<leader>", mode = { "n", "v" } })

@ -5,9 +5,7 @@ local SDKMAN_DIR = os.getenv("SDKMAN_DIR")
local lsp = require("lsp") local lsp = require("lsp")
local jdtls = require("jdtls") local jdtls = require("jdtls")
-- File types that signify a Java project's root directory. This will be local root_markers = { "gradlew", "mvnw", ".git", "pom.xml", "build.gradle" }
-- used by eclipse to determine what constitutes a workspace
local root_markers = { "gradlew", "mvnw", ".git" }
local root_dir = require("jdtls.setup").find_root(root_markers) local root_dir = require("jdtls.setup").find_root(root_markers)
-- eclipse.jdt.ls stores project specific data within a folder. If you are working -- 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. -- 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") local workspace_folder = HOME .. "/.local/share/eclipse/" .. vim.fn.fnamemodify(root_dir, ":p:h:t")
-- Helper function for creating keymaps local bundles = {}
function nnoremap(rhs, lhs, bufopts, desc) 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 bufopts.desc = desc
vim.keymap.set("n", rhs, lhs, bufopts) vim.keymap.set("n", rhs, lhs, bufopts)
end 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) 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) lsp.default_config.on_attach(client, bufnr)
-- Regular Neovim LSP client keymappings -- Regular Neovim LSP client keymappings
@ -45,36 +54,35 @@ local on_attach = function(client, bufnr)
[[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]], [[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]],
{ noremap = true, silent = true, buffer = bufnr, desc = "Extract method" } { noremap = true, silent = true, buffer = bufnr, desc = "Extract method" }
) )
nnoremap("<leader>tc", jdtls.test_class, bufopts, "Test class (DAP)")
nnoremap("<leader>tm", jdtls.test_nearest_method, bufopts, "Test method (DAP)")
end end
local config = { local config = {
flags = { flags = {
debounce_text_changes = 80, 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 -- https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
-- 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
settings = { settings = {
java = { java = {
format = { format = {
settings = { settings = {
-- Use Google Java style guidelines for formatting -- https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml
-- 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
url = "/.local/share/eclipse/eclipse-java-google-style.xml", url = "/.local/share/eclipse/eclipse-java-google-style.xml",
profile = "GoogleStyle", profile = "GoogleStyle",
}, },
}, },
implementationsCodeLens = { enabled = true },
referenceCodeLens = { enabled = true },
signatureHelp = { enabled = true },
contentProvider = { preferred = "fernflower" }, -- Use fernflower to decompile library code contentProvider = { preferred = "fernflower" }, -- Use fernflower to decompile library code
-- Specify any completion options -- Specify any completion options
completion = { completion = {
maxResults = 20, maxResults = 30,
postfix = { enabled = true }, postfix = { enabled = true },
favoriteStaticMembers = { favoriteStaticMembers = {
"org.hamcrest.MatcherAssert.assertThat", "org.hamcrest.MatcherAssert.assertThat",
@ -93,6 +101,13 @@ local config = {
"sun.*", "sun.*",
}, },
}, },
-- LSP Related
implementationsCodeLens = { enabled = true },
referenceCodeLens = { enabled = true },
signatureHelp = { enabled = true },
inlayHints = {
parameterNames = { enabled = true },
},
-- Specify any options for organizing imports -- Specify any options for organizing imports
sources = { sources = {
organizeImports = { organizeImports = {
@ -100,11 +115,14 @@ local config = {
staticStarThreshold = 9999, staticStarThreshold = 9999,
}, },
}, },
maven = {
downloadSources = true,
updateSnapshots = true,
},
-- On Save Cleanup -- On Save Cleanup
cleanup = { cleanup = {
actionsOnSave = { actionsOnSave = {
"addOverride", "addOverride",
"qualifyStaticMembers",
}, },
}, },
-- How code generation should act -- How code generation should act
@ -117,11 +135,8 @@ local config = {
}, },
useBlocks = true, useBlocks = true,
}, },
-- If you are developing in projects with different Java versions, you need -- https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
-- to tell eclipse.jdt.ls to use the location of the JDK for your Java version -- `interface RuntimeOption`
-- 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
configuration = { configuration = {
maven = { maven = {
userSettings = HOME .. "/.m2/settings.xml", 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 -- 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 -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
-- for the full list of options
cmd = { cmd = {
SDKMAN_DIR .. "/candidates/java/17.0.5-amzn/bin/java", SDKMAN_DIR .. "/candidates/java/17.0.5-amzn/bin/java",
"-Declipse.application=org.eclipse.jdt.ls.core.id1", "-Declipse.application=org.eclipse.jdt.ls.core.id1",
@ -166,18 +178,12 @@ local config = {
-- .. HOME -- .. HOME
-- .. "/.local/share/eclipse/lombok.jar", -- .. "/.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", "-jar",
-- HOME .. "/.local/share/eclipse.jdt.ls/bin",
vim.fn.glob(HOME .. "/.local/share/eclipse.jdt.ls/plugins/org.eclipse.equinox.launcher_*.jar"), 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", "-configuration",
HOME .. "/.local/share/eclipse.jdt.ls/config_linux", HOME .. "/.local/share/eclipse.jdt.ls/config_linux",
-- Use the workspace_folder defined above to store data for this project
"-data", "-data",
workspace_folder, workspace_folder,
}, },

@ -41,7 +41,8 @@ return {
}, },
custom_highlights = { custom_highlights = {
ErrorMsg = { fg = cp.red, style = { "bold" } }, ErrorMsg = { fg = cp.red, style = { "bold" } },
["@function.builtin"] = { fg = cp.blue }, ["@method.call"] = { fg = cp.blue },
["@constant"] = { fg = cp.sapphire },
LspInfoBorder = { link = "FloatBorder" }, LspInfoBorder = { link = "FloatBorder" },
PmenuSel = { bg = cp.surface0 }, PmenuSel = { bg = cp.surface0 },
FloatBorder = { fg = cp.overlay0, bg = "NONE" }, FloatBorder = { fg = cp.overlay0, bg = "NONE" },

@ -1,5 +1,5 @@
local get_python_path = function() 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 if client.name == "pyright" then
local path = client.config.settings.python.pythonPath local path = client.config.settings.python.pythonPath
if path ~= nil then if path ~= nil then
@ -62,11 +62,52 @@ return {
sign("DapLogPoint", { text = "", texthl = "DapLogPoint", linehl = "", numhl = "" }) sign("DapLogPoint", { text = "", texthl = "DapLogPoint", linehl = "", numhl = "" })
end, end,
keys = { keys = {
{ "<leader>bb", vim.cmd.DapToggleBreakpoint, desc = "Toggle Breakpoint" },
{ {
"<leader>db", "<leader>bf",
vim.cmd.DapToggleBreakpoint, function()
desc = "Toggle breakpoint", require("dap").list_breakpoints()
end,
desc = "List Breakpoints",
},
{
"<leader>bc",
function()
require("dap").clear_breakpoints()
end,
desc = "Clear Breakpoints",
},
{ "<leader>dc", vim.cmd.DapContinue, desc = "Start / Continue" },
{
"<leader>dj",
function()
require("dap").step_over()
end,
desc = "Step Over",
},
{
"<leader>dk",
function()
require("dap").step_into()
end,
desc = "Step Into",
}, },
{
"<leader>do",
function()
require("dap").step_out()
end,
desc = "Step Out",
},
{
"<leader>dd",
function()
require("dap").disconnect()
end,
desc = "Disconnect",
},
{ {
"<leader>du", "<leader>du",
function() function()
@ -74,11 +115,6 @@ return {
end, end,
desc = "Toggle UI", desc = "Toggle UI",
}, },
{
"<leader>dx",
vim.cmd.DapContinue,
desc = "Start / Continue",
},
}, },
dependencies = { dependencies = {
"williamboman/mason.nvim", "williamboman/mason.nvim",

@ -5,5 +5,4 @@ return {
"stevearc/dressing.nvim", "stevearc/dressing.nvim",
"mong8se/actually.nvim", "mong8se/actually.nvim",
"andweeb/presence.nvim", "andweeb/presence.nvim",
"mfussenegger/nvim-jdtls"
} }

@ -114,11 +114,17 @@ return {
"simrat39/rust-tools.nvim", "simrat39/rust-tools.nvim",
"mrcjkb/haskell-tools.nvim", "mrcjkb/haskell-tools.nvim",
"HallerPatrick/py_lsp.nvim", "HallerPatrick/py_lsp.nvim",
{ "SmiteshP/nvim-navic", config = { highlight = true } }, "mfussenegger/nvim-jdtls",
"onsails/lspkind.nvim", "onsails/lspkind.nvim",
{ "lukas-reineke/lsp-format.nvim", config = true },
"folke/neodev.nvim",
"ray-x/lsp_signature.nvim", "ray-x/lsp_signature.nvim",
{
"lukas-reineke/lsp-format.nvim",
config = {
java = {
exclude = { "jdtls" },
},
},
},
}, },
}, },
{ {

@ -26,6 +26,9 @@ return {
}, },
}) })
end, end,
dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" }, dependencies = {
"nvim-treesitter/nvim-treesitter-textobjects",
"nvim-treesitter/playground",
},
}, },
} }

Loading…
Cancel
Save