From 64f77367a90d17d7001b148f6b75880b6e62e2b6 Mon Sep 17 00:00:00 2001 From: douglascdev Date: Fri, 1 May 2026 10:39:33 -0300 Subject: [PATCH] java, rebinds, other new LSPs --- ftplugin/java.lua | 47 ++++++++++++++ init.lua | 109 ++++++++++++++++++++------------ lua/kickstart/plugins/debug.lua | 16 +++++ lua/kickstart/plugins/lint.lua | 1 + package-lock.json | 28 ++++++++ package.json | 5 ++ 6 files changed, 165 insertions(+), 41 deletions(-) create mode 100644 ftplugin/java.lua create mode 100644 package-lock.json create mode 100644 package.json diff --git a/ftplugin/java.lua b/ftplugin/java.lua new file mode 100644 index 00000000..b530f6fd --- /dev/null +++ b/ftplugin/java.lua @@ -0,0 +1,47 @@ +local jdtls = require 'jdtls' + +-- 1. Root and Workspace +local root_markers = { '.git', 'mvnw', 'gradlew', 'pom.xml', 'build.gradle' } +local root_dir = require('jdtls.setup').find_root(root_markers) +local project_name = vim.fn.fnamemodify(root_dir, ':p:h:t') +local workspace_dir = vim.fn.stdpath 'data' .. '/jdtls-workspace/' .. project_name + +-- 2. Direct path to Mason packages (Avoids the 'nil' API error) +local mason_path = vim.fn.stdpath 'data' .. '/mason/packages/' +local bundles = { + vim.fn.glob(mason_path .. 'java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar', true), +} + +-- Add Java Test bundles +local test_jars = vim.fn.glob(mason_path .. 'java-test/extension/server/*.jar', true) +if test_jars ~= '' then + vim.list_extend(bundles, vim.split(test_jars, '\n')) +end + +-- 3. Configuration +local config = { + cmd = { + 'jdtls', + '-data', + workspace_dir, + -- Ensure jdtls is in your PATH. If not, use the full path to the executable: + -- vim.fn.stdpath("data") .. "/mason/bin/jdtls" + }, + root_dir = root_dir, + init_options = { + bundles = bundles, + }, + on_attach = function(client, bufnr) + -- This links the Debugger to the LSP session + jdtls.setup_dap { hotcodereplace = 'auto' } + require('jdtls.dap').setup_dap_main_class_configs() + + -- Sync Kickstart highlighting + if client.server_capabilities.semanticTokensProvider then + vim.lsp.semantic_tokens.start(bufnr, client.id) + end + end, +} + +-- 4. Start +jdtls.start_or_attach(config) diff --git a/init.lua b/init.lua index 317b235a..ee0d24cf 100644 --- a/init.lua +++ b/init.lua @@ -352,6 +352,14 @@ require('lazy').setup({ }, }, + { + 'folke/persistence.nvim', + event = 'BufReadPre', -- this will only start session saving when an actual file was opened + opts = { + -- add any custom options here + }, + }, + -- NOTE: Plugins can specify dependencies. -- -- The dependencies are proper plugin specifications as well - anything @@ -413,7 +421,6 @@ require('lazy').setup({ -- i = { [''] = 'to_fuzzy_refine' }, -- }, -- }, - -- pickers = {} extensions = { ['ui-select'] = { require('telescope.themes').get_dropdown(), @@ -427,17 +434,38 @@ require('lazy').setup({ -- See `:help telescope.builtin` local builtin = require 'telescope.builtin' - vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) - vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) - vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) - vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) + vim.keymap.set('n', 'fh', builtin.help_tags, { desc = '[H]elp' }) + vim.keymap.set('n', 'fk', builtin.keymaps, { desc = '[K]eymaps' }) + vim.keymap.set('n', 'ff', builtin.find_files, { desc = '[F]iles' }) + vim.keymap.set('n', 'fs', builtin.builtin, { desc = '[S]elect Telescope' }) + vim.keymap.set('n', 'fw', builtin.grep_string, { desc = 'current [W]ord' }) + vim.keymap.set('n', 'fg', builtin.live_grep, { desc = 'by [G]rep' }) + vim.keymap.set('n', 'fd', builtin.diagnostics, { desc = '[D]iagnostics' }) + vim.keymap.set('n', 'fr', builtin.resume, { desc = '[R]esume' }) + vim.keymap.set('n', 'f.', builtin.oldfiles, { desc = 'Recent Files ("." for repeat)' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + -- Session + -- load the session for the current directory + vim.keymap.set('n', 'ss', function() + require('persistence').load() + end, { desc = '[s]ession for the current dir' }) + + -- select a session to load + vim.keymap.set('n', 'sw', function() + require('persistence').select() + end, { desc = '[w]hich session to load' }) + + -- load the last session + vim.keymap.set('n', 'sl', function() + require('persistence').load { last = true } + end, { desc = '[l]ast session' }) + + -- stop Persistence => session won't be saved on exit + vim.keymap.set('n', 'sd', function() + require('persistence').stop() + end, { desc = "[d]on't save this session" }) + -- Slightly advanced example of overriding default behavior and theme vim.keymap.set('n', '/', function() -- You can pass additional configuration to Telescope to change the theme, layout, etc. @@ -449,33 +477,19 @@ require('lazy').setup({ -- It's also possible to pass additional configuration options. -- See `:help telescope.builtin.live_grep()` for information about particular keys - vim.keymap.set('n', 's/', function() + vim.keymap.set('n', 'f/', function() builtin.live_grep { grep_open_files = true, prompt_title = 'Live Grep in Open Files', } - end, { desc = '[S]earch [/] in Open Files' }) + end, { desc = '[/] in Open Files' }) -- Shortcut for searching your Neovim configuration files - vim.keymap.set('n', 'sn', function() + vim.keymap.set('n', 'fn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } - end, { desc = '[S]earch [N]eovim files' }) + end, { desc = '[N]eovim files' }) end, }, - - -- LSP Plugins - { - -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins - -- used for completion, annotations and signatures of Neovim apis - 'folke/lazydev.nvim', - ft = 'lua', - opts = { - library = { - -- Load luvit types when the `vim.uv` word is found - { path = '${3rd}/luv/library', words = { 'vim%.uv' } }, - }, - }, - }, { -- Main LSP Configuration 'neovim/nvim-lspconfig', @@ -672,9 +686,11 @@ require('lazy').setup({ -- - settings (table): Override the default settings passed when initializing the server. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { - -- clangd = {}, - -- gopls = {}, - -- pyright = {}, + clangd = {}, + gopls = {}, + pyright = {}, + prettier = {}, + tailwindcss = {}, -- rust_analyzer = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- @@ -717,12 +733,20 @@ require('lazy').setup({ local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { 'stylua', -- Used to format Lua code + 'markdownlint', + 'hadolint', + 'clangd', }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } require('mason-lspconfig').setup { ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) automatic_installation = false, + automatic_enable = { + exclude = { + 'jdtls', + }, + }, handlers = { function(server_name) local server = servers[server_name] or {} @@ -743,12 +767,12 @@ require('lazy').setup({ cmd = { 'ConformInfo' }, keys = { { - 'f', + 'o', function() require('conform').format { async = true, lsp_format = 'fallback' } end, mode = '', - desc = '[F]ormat buffer', + desc = 'F[o]rmat buffer', }, }, opts = { @@ -770,7 +794,9 @@ require('lazy').setup({ formatters_by_ft = { lua = { 'stylua' }, -- Conform can also run multiple formatters sequentially - -- python = { "isort", "black" }, + python = { 'isort', 'black' }, + go = { 'goimports', 'gofmt' }, + css = { 'prettier' }, -- -- You can use 'stop_after_first' to run the first available formatter from the list -- javascript = { "prettierd", "prettier", stop_after_first = true }, @@ -887,6 +913,7 @@ require('lazy').setup({ config = function() ---@diagnostic disable-next-line: missing-fields require('tokyonight').setup { + transparent = true, styles = { comments = { italic = false }, -- Disable italics in comments }, @@ -974,18 +1001,18 @@ require('lazy').setup({ -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - -- require 'kickstart.plugins.debug', - -- require 'kickstart.plugins.indent_line', - -- require 'kickstart.plugins.lint', - -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', - -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps + require 'kickstart.plugins.debug', + require 'kickstart.plugins.indent_line', + require 'kickstart.plugins.lint', + require 'kickstart.plugins.autopairs', + require 'kickstart.plugins.neo-tree', + require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 8e332bf2..211fdb07 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -23,6 +23,9 @@ return { -- Add your own debuggers here 'leoluz/nvim-dap-go', + + -- java + 'mfussenegger/nvim-jdtls', }, keys = { -- Basic debugging keymaps, feel free to change to your liking! @@ -95,6 +98,9 @@ return { ensure_installed = { -- Update this to ensure that you have the debuggers for the langs you want 'delve', + 'cpptools', + 'java-debug-adapter', + 'java-test', }, } @@ -136,6 +142,16 @@ return { dap.listeners.before.event_terminated['dapui_config'] = dapui.close dap.listeners.before.event_exited['dapui_config'] = dapui.close + dap.configurations.java = { + { + type = 'java', + request = 'launch', + name = 'Debug (Launch) - Current File', + mainClass = '${file}', -- This tells it to just try the current file + projectName = 'temp-project', + }, + } + -- Install golang specific config require('dap-go').setup { delve = { diff --git a/lua/kickstart/plugins/lint.lua b/lua/kickstart/plugins/lint.lua index dec42f09..219b1e60 100644 --- a/lua/kickstart/plugins/lint.lua +++ b/lua/kickstart/plugins/lint.lua @@ -7,6 +7,7 @@ return { local lint = require 'lint' lint.linters_by_ft = { markdown = { 'markdownlint' }, + dockerfile = { 'hadolint' }, } -- To allow other plugins to add linters to require('lint').linters_by_ft, diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..0e961e54 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,28 @@ +{ + "name": "nvim", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "devDependencies": { + "prettier": "3.7.4" + } + }, + "node_modules/prettier": { + "version": "3.7.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.7.4.tgz", + "integrity": "sha512-v6UNi1+3hSlVvv8fSaoUbggEM5VErKmmpGA7Pl3HF8V6uKY7rvClBOJlH6yNwQtfTueNkGVpOv/mtWL9L4bgRA==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..a63f0e59 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "prettier": "3.7.4" + } +}