java, rebinds, other new LSPs

This commit is contained in:
douglascdev 2026-05-01 10:39:33 -03:00
parent c2b97192c5
commit 64f77367a9
6 changed files with 165 additions and 41 deletions

47
ftplugin/java.lua Normal file
View File

@ -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)

109
init.lua
View File

@ -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. -- NOTE: Plugins can specify dependencies.
-- --
-- The dependencies are proper plugin specifications as well - anything -- The dependencies are proper plugin specifications as well - anything
@ -413,7 +421,6 @@ require('lazy').setup({
-- i = { ['<c-enter>'] = 'to_fuzzy_refine' }, -- i = { ['<c-enter>'] = 'to_fuzzy_refine' },
-- }, -- },
-- }, -- },
-- pickers = {}
extensions = { extensions = {
['ui-select'] = { ['ui-select'] = {
require('telescope.themes').get_dropdown(), require('telescope.themes').get_dropdown(),
@ -427,17 +434,38 @@ require('lazy').setup({
-- See `:help telescope.builtin` -- See `:help telescope.builtin`
local builtin = require 'telescope.builtin' local builtin = require 'telescope.builtin'
vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) vim.keymap.set('n', '<leader>fh', builtin.help_tags, { desc = '[H]elp' })
vim.keymap.set('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) vim.keymap.set('n', '<leader>fk', builtin.keymaps, { desc = '[K]eymaps' })
vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = '[F]iles' })
vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) vim.keymap.set('n', '<leader>fs', builtin.builtin, { desc = '[S]elect Telescope' })
vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', '<leader>fw', builtin.grep_string, { desc = 'current [W]ord' })
vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = 'by [G]rep' })
vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', '<leader>fd', builtin.diagnostics, { desc = '[D]iagnostics' })
vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' }) vim.keymap.set('n', '<leader>fr', builtin.resume, { desc = '[R]esume' })
vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) vim.keymap.set('n', '<leader>f.', builtin.oldfiles, { desc = 'Recent Files ("." for repeat)' })
vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' }) vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
-- Session
-- load the session for the current directory
vim.keymap.set('n', '<leader>ss', function()
require('persistence').load()
end, { desc = '[s]ession for the current dir' })
-- select a session to load
vim.keymap.set('n', '<leader>sw', function()
require('persistence').select()
end, { desc = '[w]hich session to load' })
-- load the last session
vim.keymap.set('n', '<leader>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', '<leader>sd', function()
require('persistence').stop()
end, { desc = "[d]on't save this session" })
-- Slightly advanced example of overriding default behavior and theme -- Slightly advanced example of overriding default behavior and theme
vim.keymap.set('n', '<leader>/', function() vim.keymap.set('n', '<leader>/', function()
-- You can pass additional configuration to Telescope to change the theme, layout, etc. -- 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. -- It's also possible to pass additional configuration options.
-- See `:help telescope.builtin.live_grep()` for information about particular keys -- See `:help telescope.builtin.live_grep()` for information about particular keys
vim.keymap.set('n', '<leader>s/', function() vim.keymap.set('n', '<leader>f/', function()
builtin.live_grep { builtin.live_grep {
grep_open_files = true, grep_open_files = true,
prompt_title = 'Live Grep in Open Files', 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 -- Shortcut for searching your Neovim configuration files
vim.keymap.set('n', '<leader>sn', function() vim.keymap.set('n', '<leader>fn', function()
builtin.find_files { cwd = vim.fn.stdpath 'config' } builtin.find_files { cwd = vim.fn.stdpath 'config' }
end, { desc = '[S]earch [N]eovim files' }) end, { desc = '[N]eovim files' })
end, 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 -- Main LSP Configuration
'neovim/nvim-lspconfig', 'neovim/nvim-lspconfig',
@ -672,9 +686,11 @@ require('lazy').setup({
-- - settings (table): Override the default settings passed when initializing the server. -- - 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/ -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
local servers = { local servers = {
-- clangd = {}, clangd = {},
-- gopls = {}, gopls = {},
-- pyright = {}, pyright = {},
prettier = {},
tailwindcss = {},
-- rust_analyzer = {}, -- rust_analyzer = {},
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- ... 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 {}) local ensure_installed = vim.tbl_keys(servers or {})
vim.list_extend(ensure_installed, { vim.list_extend(ensure_installed, {
'stylua', -- Used to format Lua code 'stylua', -- Used to format Lua code
'markdownlint',
'hadolint',
'clangd',
}) })
require('mason-tool-installer').setup { ensure_installed = ensure_installed } require('mason-tool-installer').setup { ensure_installed = ensure_installed }
require('mason-lspconfig').setup { require('mason-lspconfig').setup {
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
automatic_installation = false, automatic_installation = false,
automatic_enable = {
exclude = {
'jdtls',
},
},
handlers = { handlers = {
function(server_name) function(server_name)
local server = servers[server_name] or {} local server = servers[server_name] or {}
@ -743,12 +767,12 @@ require('lazy').setup({
cmd = { 'ConformInfo' }, cmd = { 'ConformInfo' },
keys = { keys = {
{ {
'<leader>f', '<leader>o',
function() function()
require('conform').format { async = true, lsp_format = 'fallback' } require('conform').format { async = true, lsp_format = 'fallback' }
end, end,
mode = '', mode = '',
desc = '[F]ormat buffer', desc = 'F[o]rmat buffer',
}, },
}, },
opts = { opts = {
@ -770,7 +794,9 @@ require('lazy').setup({
formatters_by_ft = { formatters_by_ft = {
lua = { 'stylua' }, lua = { 'stylua' },
-- Conform can also run multiple formatters sequentially -- 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 -- You can use 'stop_after_first' to run the first available formatter from the list
-- javascript = { "prettierd", "prettier", stop_after_first = true }, -- javascript = { "prettierd", "prettier", stop_after_first = true },
@ -887,6 +913,7 @@ require('lazy').setup({
config = function() config = function()
---@diagnostic disable-next-line: missing-fields ---@diagnostic disable-next-line: missing-fields
require('tokyonight').setup { require('tokyonight').setup {
transparent = true,
styles = { styles = {
comments = { italic = false }, -- Disable italics in comments 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. -- 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). -- Uncomment any of the lines below to enable them (you will need to restart nvim).
-- --
-- require 'kickstart.plugins.debug', require 'kickstart.plugins.debug',
-- require 'kickstart.plugins.indent_line', require 'kickstart.plugins.indent_line',
-- require 'kickstart.plugins.lint', require 'kickstart.plugins.lint',
-- require 'kickstart.plugins.autopairs', require 'kickstart.plugins.autopairs',
-- require 'kickstart.plugins.neo-tree', require 'kickstart.plugins.neo-tree',
-- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps 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` -- 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. -- 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. -- 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` -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec`
-- Or use telescope! -- Or use telescope!

View File

@ -23,6 +23,9 @@ return {
-- Add your own debuggers here -- Add your own debuggers here
'leoluz/nvim-dap-go', 'leoluz/nvim-dap-go',
-- java
'mfussenegger/nvim-jdtls',
}, },
keys = { keys = {
-- Basic debugging keymaps, feel free to change to your liking! -- Basic debugging keymaps, feel free to change to your liking!
@ -95,6 +98,9 @@ return {
ensure_installed = { ensure_installed = {
-- Update this to ensure that you have the debuggers for the langs you want -- Update this to ensure that you have the debuggers for the langs you want
'delve', '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_terminated['dapui_config'] = dapui.close
dap.listeners.before.event_exited['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 -- Install golang specific config
require('dap-go').setup { require('dap-go').setup {
delve = { delve = {

View File

@ -7,6 +7,7 @@ return {
local lint = require 'lint' local lint = require 'lint'
lint.linters_by_ft = { lint.linters_by_ft = {
markdown = { 'markdownlint' }, markdown = { 'markdownlint' },
dockerfile = { 'hadolint' },
} }
-- To allow other plugins to add linters to require('lint').linters_by_ft, -- To allow other plugins to add linters to require('lint').linters_by_ft,

28
package-lock.json generated Normal file
View File

@ -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"
}
}
}
}

5
package.json Normal file
View File

@ -0,0 +1,5 @@
{
"devDependencies": {
"prettier": "3.7.4"
}
}