Add java config for nvim

pull/1/head
Ensar Sarajčić 2021-06-11 12:20:00 +02:00
parent e10a2325c4
commit ff9241b096
3 changed files with 52 additions and 1 deletions

View File

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

View File

@ -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', '<A-CR>', "<cmd>lua require('jdtls').code_action()<CR>", default_opts)
buf_set_keymap('n', '<Leader>ac', "<cmd>lua require('jdtls').code_action()<CR>", default_opts)
end
require('jdtls').start_or_attach {
cmd = {'jdtls-startup.sh'};
on_attach = jdstls_on_attach;
}

View File

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