diff --git a/symlinks/config/nvim/lua/init/plugins.lua b/symlinks/config/nvim/lua/init/plugins.lua index 7a983d7..46765e9 100644 --- a/symlinks/config/nvim/lua/init/plugins.lua +++ b/symlinks/config/nvim/lua/init/plugins.lua @@ -82,6 +82,7 @@ return require('packer').startup { -- LSP language specific use 'tjdevries/nlua.nvim' -- Built-in Lua integration with LSP use 'akinsho/flutter-tools.nvim' -- Additional flutter integrations + use 'mfussenegger/nvim-jdtls' -- Additional java integrations -- Lua support -- use 'tjdevries/astronauta.nvim' -- Support for lua ftplugins and plugins diff --git a/symlinks/config/nvim/lua/lsp/servers.lua b/symlinks/config/nvim/lua/lsp/servers.lua index f7947b5..1ca0fd5 100644 --- a/symlinks/config/nvim/lua/lsp/servers.lua +++ b/symlinks/config/nvim/lua/lsp/servers.lua @@ -52,3 +52,23 @@ lspconfig.omnisharp.setup { cmd = { omnisharp_bin, "--languageserver" , "--hostPID", tostring(pid) }; on_attach = on_attach; } + +-- JDTLS (Java) +local jdstls_on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + local default_opts = {noremap = true, silent = true} + + on_attach(client, bufnr) + + buf_set_keymap('n', '', "lua require('jdtls').code_action()", default_opts) + buf_set_keymap('n', 'ac', "lua require('jdtls').code_action()", default_opts) +end + +require('jdtls').start_or_attach { + cmd = {'jdtls-startup.sh'}; + on_attach = jdstls_on_attach; +} diff --git a/symlinks/config/nvim/lua/plugin/projectionist.lua b/symlinks/config/nvim/lua/plugin/projectionist.lua index 0518c10..379cc3f 100644 --- a/symlinks/config/nvim/lua/plugin/projectionist.lua +++ b/symlinks/config/nvim/lua/plugin/projectionist.lua @@ -290,6 +290,35 @@ local csharp_project_config = { } } +local java_project_config = { + ["src/main/java/*.java"] = { + type = "source", + template = { + "package {dirname|dot};", + "", + "public class {basename} {open}", + "{close}" + }, + alternate = "src/test/java/{}Test.java" + }, + ["src/test/java/*Test.java"] = { + type = "test", + template = { + "package {dirname|dot};", + "", + "public class {basename}Test {open}", + "{close}" + }, + alternate = "src/main/java/{}.java" + }, + ["src/main/java/module-info.java"] = { + type = "moduleinfo", + }, + ["src/main/java/**/package-info.java"] = { + type = "packageinfo", + } +} + local function c_project_config(source_extension, header_extension) return { ["*"] = { @@ -332,5 +361,6 @@ vim.g.projectionist_heuristics = { ["plugin/|autoload/"] = vim_plugin_config, ["src/*.cpp|test/*.cpp"] = c_project_config("cpp", "hpp"), ["src/*.c|test/*.c"] = c_project_config("c", "h"), - ["lua/"] = lua_vim_plugin_config + ["lua/"] = lua_vim_plugin_config, + ["build.gradle|pom.xml"] = java_project_config }