diff --git a/dot_config/nvim/ftplugin/java.lua b/dot_config/nvim/ftplugin/java.lua new file mode 100644 index 0000000..f8161f7 --- /dev/null +++ b/dot_config/nvim/ftplugin/java.lua @@ -0,0 +1,2 @@ +local config = require("lsp.java").make_jdtls_config() +require("jdtls").start_or_attach(config) diff --git a/dot_config/nvim/lazy-lock.json b/dot_config/nvim/lazy-lock.json index 7701b63..560e0be 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": "3d2dcb2d5ef99106c5ff412da88c6f59a9f8a693" }, + "lazy.nvim": { "branch": "main", "commit": "48c9b37294f31e3875435bca41d0c923fdd6eea4" }, "lsp-format.nvim": { "branch": "master", "commit": "ca0df5c8544e51517209ea7b86ecc522c98d4f0a" }, "lsp_signature.nvim": { "branch": "master", "commit": "6f6252f63b0baf0f2224c4caea33819a27f3f550" }, "lspkind.nvim": { "branch": "master", "commit": "c68b3a003483cf382428a43035079f78474cd11e" }, @@ -35,6 +35,7 @@ "nvim-dap": { "branch": "master", "commit": "0e376f00e7fac143e29e1017d2ac2cc3df13d185" }, "nvim-dap-ui": { "branch": "master", "commit": "885e958ff9de30cfbc359259eccf28cc493ad46b" }, "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" }, diff --git a/dot_config/nvim/lua/lsp/init.lua b/dot_config/nvim/lua/lsp/init.lua new file mode 100644 index 0000000..8819edb --- /dev/null +++ b/dot_config/nvim/lua/lsp/init.lua @@ -0,0 +1,54 @@ +local M = {} + +M.default_config = { + on_attach = function(client, bufnr) + require("lsp-format").on_attach(client) + + -- add lsp-only keybinds + local map = function(sequence, cmd, desc) + vim.keymap.set("n", sequence, cmd, { buffer = bufnr, desc = desc }) + end + + map("K", vim.lsp.buf.hover, "Hover") + map("]d", vim.diagnostic.goto_next, "Next diagnostic") + map("[d", vim.diagnostic.goto_prev, "Previous diagnostic") + + map("gs", vim.lsp.buf.signature_help, "LSP Signature Help") + map("gD", vim.lsp.buf.declaration, "LSP Declarations") + map("gd", function() + require("telescope.builtin").lsp_definitions() + end, "LSP Definitions") + map("gT", function() + require("telescope.builtin").lsp_type_definitions() + end, "LSP Type Definitions") + map("gr", function() + require("telescope.builtin").lsp_references() + end, "LSP References") + map("gI", function() + require("telescope.builtin").lsp_implementations() + end, "LSP Implementations") + map("gl", function() + vim.diagnostic.open_float(0, { + scope = "line", + }) + end) + + map("la", vim.lsp.buf.code_action, "Code Action") + map("lr", vim.lsp.buf.rename, "Rename") + map("lf", vim.lsp.buf.format, "Format") + map("ld", function() + require("telescope.builtin").diagnostics() + end, "LSP Workplace Diagnostics") + map("lD", function() + require("telescope.builtin").diagnostics({ bufnr = 0 }) + end, "LSP Buffer Diagnostics") + map("ls", function() + require("telescope.builtin").lsp_document_symbols() + end, "LSP Document Symbols") + map("lS", function() + require("telescope.builtin").lsp_workspace_symbols() + end, "LSP Workplace Symbols") + end, +} + +return M diff --git a/dot_config/nvim/lua/lsp/java.lua b/dot_config/nvim/lua/lsp/java.lua new file mode 100644 index 0000000..8643125 --- /dev/null +++ b/dot_config/nvim/lua/lsp/java.lua @@ -0,0 +1,190 @@ +local M = {} + +local HOME = os.getenv("HOME") +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_dir = require("jdtls.setup").find_root(root_markers) + +-- eclipse.jdt.ls stores project specific data within a folder. If you are working +-- with multiple different projects, each project must use a dedicated data directory. +-- This variable is used to configure eclipse to use the directory name of the +-- 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) + 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) + lsp.default_config.on_attach(client, bufnr) + + -- Regular Neovim LSP client keymappings + local bufopts = { noremap = true, silent = true, buffer = bufnr } + nnoremap("lwa", vim.lsp.buf.add_workspace_folder, bufopts, "Add workspace folder") + nnoremap("lwr", vim.lsp.buf.remove_workspace_folder, bufopts, "Remove workspace folder") + nnoremap("lwl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts, "List workspace folders") + + -- Java extensions provided by jdtls + nnoremap("lo", jdtls.organize_imports, bufopts, "Organize imports") + nnoremap("le", jdtls.extract_variable, bufopts, "Extract variable") + nnoremap("lc", jdtls.extract_constant, bufopts, "Extract constant") + vim.keymap.set( + "v", + "lm", + [[lua require('jdtls').extract_method(true)]], + { noremap = true, silent = true, buffer = bufnr, desc = "Extract method" } + ) +end + +local config = { + flags = { + debounce_text_changes = 80, + }, + 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 + 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 + 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, + postfix = { enabled = true }, + favoriteStaticMembers = { + "org.hamcrest.MatcherAssert.assertThat", + "org.hamcrest.Matchers.*", + "org.hamcrest.CoreMatchers.*", + "org.junit.jupiter.api.Assertions.*", + "java.util.Objects.requireNonNull", + "java.util.Objects.requireNonNullElse", + "org.mockito.Mockito.*", + }, + filteredTypes = { + "com.sun.*", + "io.micrometer.shaded.*", + "java.awt.*", + "jdk.*", + "sun.*", + }, + }, + -- Specify any options for organizing imports + sources = { + organizeImports = { + starThreshold = 9999, + staticStarThreshold = 9999, + }, + }, + -- On Save Cleanup + cleanup = { + actionsOnSave = { + "addOverride", + "qualifyStaticMembers", + }, + }, + -- How code generation should act + codeGeneration = { + toString = { + template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}", + }, + hashCodeEquals = { + useJava7Objects = true, + }, + 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 + configuration = { + maven = { + userSettings = HOME .. "/.m2/settings.xml", + }, + runtimes = { + { + name = "JavaSE-17", + path = SDKMAN_DIR .. "/candidates/java/17.0.5-amzn", + }, + { + name = "JavaSE-11", + path = SDKMAN_DIR .. "/candidates/java/11.0.18-amzn", + }, + { + name = "JavaSE-1.8", + path = SDKMAN_DIR .. "/candidates/java/8.0.362-amzn", + }, + }, + }, + }, + }, + -- 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", + "-Dosgi.bundles.defaultStartLevel=4", + "-Declipse.product=org.eclipse.jdt.ls.core.product", + "-Dlog.protocol=true", + "-Dlog.level=ALL", + "-Xmx4g", + "--add-modules=ALL-SYSTEM", + "--add-opens", + "java.base/java.util=ALL-UNNAMED", + "--add-opens", + "java.base/java.lang=ALL-UNNAMED", + -- If you use lombok, download the lombok jar and place it in ~/.local/share/eclipse + -- "-javaagent:" + -- .. 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, + }, +} + +function M.make_jdtls_config() + return config +end + +return M diff --git a/dot_config/nvim/lua/plugins/gitsigns.lua b/dot_config/nvim/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..e627208 --- /dev/null +++ b/dot_config/nvim/lua/plugins/gitsigns.lua @@ -0,0 +1,60 @@ +return { + { + "lewis6991/gitsigns.nvim", + config = function() + require("gitsigns").setup({ + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + + local function map(mode, l, r, opts, desc) + opts = opts or {} + opts.buffer = bufnr + opts.desc = desc + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map("n", "]c", function() + if vim.wo.diff then + return "]c" + end + vim.schedule(function() + gs.next_hunk() + end) + return "" + end, { expr = true }, "Next Hunk") + + map("n", "[c", function() + if vim.wo.diff then + return "[c" + end + vim.schedule(function() + gs.prev_hunk() + end) + return "" + end, { expr = true }, "Previous Hunk") + + -- Actions + map({ "n", "v" }, "gs", ":Gitsigns stage_hunk", {}, "Stage Hunk") + map({ "n", "v" }, "gr", ":Gitsigns reset_hunk", {}, "Reset Hunk") + map("n", "gS", gs.stage_buffer, {}, "Stage Buffer") + map("n", "gu", gs.undo_stage_hunk, {}, "Undo Stage Hunk") + map("n", "gR", gs.reset_buffer, {}, "Reset Buffer") + map("n", "gp", gs.preview_hunk, {}, "Preview Hunk") + map("n", "gb", function() + gs.blame_line({ full = true }) + end, {}, "Show Blame") + map("n", "gb", gs.toggle_current_line_blame, {}, "Current Line Blame") + map("n", "gd", gs.diffthis, {}, "Diff This") + map("n", "gD", function() + gs.diffthis("~") + end, {}, "") + map("n", "gd", gs.toggle_deleted, {}, "Show Deleted") + + -- Text object + map({ "o", "x" }, "ih", ":Gitsigns select_hunk") + end, + }) + end, + }, +} diff --git a/dot_config/nvim/lua/plugins/init.lua b/dot_config/nvim/lua/plugins/init.lua index feacb47..e8d16ab 100644 --- a/dot_config/nvim/lua/plugins/init.lua +++ b/dot_config/nvim/lua/plugins/init.lua @@ -5,4 +5,5 @@ 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 7738830..50235cc 100644 --- a/dot_config/nvim/lua/plugins/lsp.lua +++ b/dot_config/nvim/lua/plugins/lsp.lua @@ -1,3 +1,5 @@ +local lsp = require("lsp") + local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } for type, icon in pairs(signs) do local hl = "DiagnosticSign" .. type @@ -11,58 +13,8 @@ vim.diagnostic.config({ vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) -local default_config = { - on_attach = function(client, bufnr) - require("lsp-format").on_attach(client) - - -- add lsp-only keybinds - local map = function(sequence, cmd, desc) - vim.keymap.set("n", sequence, cmd, { buffer = bufnr, desc = desc }) - end - - map("K", vim.lsp.buf.hover, "Hover") - map("]d", vim.diagnostic.goto_next, "Next diagnostic") - map("[d", vim.diagnostic.goto_prev, "Previous diagnostic") - - map("gs", vim.lsp.buf.signature_help, "LSP Signature Help") - map("gD", vim.lsp.buf.declaration, "LSP Declarations") - map("gd", function() - require("telescope.builtin").lsp_definitions() - end, "LSP Definitions") - map("gr", function() - require("telescope.builtin").lsp_references() - end, "LSP References") - map("gI", function() - require("telescope.builtin").lsp_implementations() - end, "LSP Implementations") - map("gl", function() - vim.diagnostic.open_float(0, { - scope = "line", - }) - end) - - map("la", vim.lsp.buf.code_action, "Code Action") - map("lr", vim.lsp.buf.rename, "Rename") - map("lf", vim.lsp.buf.format, "Format") - map("li", "LspInfo", "LSP Info") - map("lI", "Mason", "Mason Info") - map("lw", function() - require("telescope.builtin").diagnostics() - end, "LSP Workplace Diagnostics") - map("ld", function() - require("telescope.builtin").diagnostics({ bufnr = 0 }) - end, "LSP Buffer Diagnostics") - map("ls", function() - require("telescope.builtin").lsp_document_symbols() - end, "LSP Document Symbols") - map("lS", function() - require("telescope.builtin").lsp_workspace_symbols() - end, "LSP Workplace Symbols") - end, -} - local custom_config = function(config) - local merged_config = vim.deepcopy(default_config) + local merged_config = vim.deepcopy(lsp.default_config) merged_config = vim.tbl_extend("force", merged_config, config) return merged_config end @@ -83,7 +35,7 @@ return { require("mason-lspconfig").setup_handlers({ -- default handler function(server_name) - require("lspconfig")[server_name].setup(default_config) + require("lspconfig")[server_name].setup(lsp.default_config) end, ["rust_analyzer"] = function() -- https://github.com/simrat39/rust-tools.nvim/issues/300 @@ -110,7 +62,7 @@ return { }) end, ["pyright"] = function() - require("py_lsp").setup(default_config) + require("py_lsp").setup(lsp.default_config) end, ["hls"] = function() local ht = require("haskell-tools") @@ -178,6 +130,10 @@ return { null_ls.builtins.formatting.stylua.with({ extra_args = { "--indent-type", "spaces" }, }), + null_ls.builtins.diagnostics.markdownlint, + null_ls.builtins.formatting.mdformat.with({ + extra_args = { "--wrap", "80", "--number" }, + }), -- null_ls.builtins.formatting.black, -- null_ls.builtins.formatting.isort.with({ -- extra_args = { "--profile", "black" }, diff --git a/dot_config/nvim/lua/plugins/nvimtree.lua b/dot_config/nvim/lua/plugins/nvimtree.lua new file mode 100644 index 0000000..d90a877 --- /dev/null +++ b/dot_config/nvim/lua/plugins/nvimtree.lua @@ -0,0 +1,26 @@ +return { + { + "nvim-tree/nvim-tree.lua", + dependencies = "nvim-tree/nvim-web-devicons", + config = function() + require("nvim-tree").setup({ + hijack_cursor = true, + sync_root_with_cwd = true, + respect_buf_cwd = true, + update_focused_file = { + enable = true, + update_root = false, + }, + view = { + centralize_selection = true, + }, + renderer = { + group_empty = true, + }, + }) + end, + keys = { + { "e", "NvimTreeToggle", "Open Explorer" }, + }, + }, +} diff --git a/dot_config/nvim/lua/plugins/project.lua b/dot_config/nvim/lua/plugins/project.lua new file mode 100644 index 0000000..9e563bf --- /dev/null +++ b/dot_config/nvim/lua/plugins/project.lua @@ -0,0 +1,20 @@ +return { + { + "ahmedkhalf/project.nvim", + config = function() + require("project_nvim").setup({ + patterns = { + ".git", + "_darcs", + ".hg", + ".bzr", + ".svn", + "Makefile", + "package.json", + "stylua.toml", + "wezterm.lua", + }, + }) + end, + }, +} diff --git a/dot_config/nvim/lua/plugins/rooter.lua b/dot_config/nvim/lua/plugins/rooter.lua new file mode 100644 index 0000000..bfe415d --- /dev/null +++ b/dot_config/nvim/lua/plugins/rooter.lua @@ -0,0 +1,17 @@ +return {} +-- return { +-- { +-- "notjedi/nvim-rooter.lua", +-- lazy = false, +-- priority = 1000, +-- config = function() +-- require("nvim-rooter").setup({ +-- update_cwd = true, +-- update_focused_file = { +-- enable = true, +-- update_cwd = true, +-- }, +-- }) +-- end, +-- }, +-- } diff --git a/private_dot_local/private_share/eclipse/eclipse-java-google-style.xml b/private_dot_local/private_share/eclipse/eclipse-java-google-style.xml new file mode 100644 index 0000000..1769362 --- /dev/null +++ b/private_dot_local/private_share/eclipse/eclipse-java-google-style.xml @@ -0,0 +1,714 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +