From d1a6798981418e3ae7ea629b3ed4946dd8036fb3 Mon Sep 17 00:00:00 2001 From: "gwendal.pineau" Date: Thu, 18 Sep 2025 22:23:54 -0400 Subject: [PATCH] Added jdtls config --- ftplugin/java.lua | 26 ++++++++++++++++++++++++++ init.lua | 6 +++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 ftplugin/java.lua diff --git a/ftplugin/java.lua b/ftplugin/java.lua new file mode 100644 index 00000000..450fe3ee --- /dev/null +++ b/ftplugin/java.lua @@ -0,0 +1,26 @@ +-- print 'Loaded ftplugin/java.lua' +local jdtls = require 'jdtls' + +local root_dir = require('jdtls.setup').find_root { '.git', 'mvnw', 'gradlew', 'pom.xml' } +if root_dir == '' then + root_dir = vim.fn.getcwd() +end + +print('JDTLS root_dir = ' .. root_dir) + +local workspace_dir = vim.fn.stdpath 'data' .. '/jdtls-workspace/' .. vim.fn.fnamemodify(root_dir, ':p:h:t') + +local config = { + cmd = { vim.fn.stdpath 'data' .. '/mason/packages/jdtls/bin/jdtls' }, -- 👈 absolute path + root_dir = root_dir, + workspace_folder = workspace_dir, + settings = { + java = { + project = { + sourcePaths = { 'src' }, -- 👈 tells jdtls where sources begin + }, + }, + }, +} + +jdtls.start_or_attach(config) diff --git a/init.lua b/init.lua index a0ae2cae..972da323 100644 --- a/init.lua +++ b/init.lua @@ -816,6 +816,10 @@ require('lazy').setup({ --- @type blink.cmp.Config opts = { keymap = { + -- This will expand snippets if the LSP sent a snippet. + -- Manually trigger a completion from nvim-cmp. + -- Generally you don't need this, because nvim-cmp will display + -- completions whenever it has completion options available. -- 'default' (recommended) for mappings similar to built-in completions -- to accept ([y]es) the completion. -- This will auto-import if your LSP supports it. @@ -838,7 +842,7 @@ require('lazy').setup({ -- -- See :h blink-cmp-config-keymap for defining your own keymap preset = 'default', - + [''] = { 'select_and_accept', 'fallback' }, -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps },