feat(java): Replace the current custom installation of java, with lspinstall (#517)

This commit is contained in:
Marek Filipowicz 2021-06-26 19:15:02 +02:00 committed by GitHub
parent 19003f7577
commit a9e9047118
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 27 deletions

View file

@ -296,6 +296,8 @@ To install a supported language server:
See [LspInstall](https://github.com/kabouzeid/nvim-lspinstall) for more
info.
In order for Java LSP to work, edit `~/.local/share/nvim/lspinstall/java/jdtls.sh` and replace `WORKSPACE="$1"` with `WORKSPACE="$HOME/workspace"`
Most common languages should be supported out of the box, if yours is
not I would welcome a PR

View file

@ -40,6 +40,7 @@ vim.cmd('source '..CONFIG_PATH..'/vimscript/functions.vim')
-- LSP
require('lsp')
require('lsp.java-ls')
require('lsp.angular-ls')
require('lsp.bash-ls')
require('lsp.clangd')

View file

@ -1,3 +1,4 @@
local util = require 'lspconfig/util'
-- In Vimscript
-- augroup lsp
-- au!
@ -5,27 +6,36 @@
-- augroup end
-- find_root looks for parent directories relative to the current buffer containing one of the given arguments.
-- require'lspconfig'.jdtls.setup {cmd = {'java-linux-ls'}}
if vim.fn.has("mac") == 1 then
JAVA_LS_EXECUTABLE = 'java-mac-ls'
elseif vim.fn.has("unix") == 1 then
JAVA_LS_EXECUTABLE = 'java-linux-ls'
else
print("Unsupported system")
end
-- if vim.fn.has("mac") == 1 then
-- JAVA_LS_EXECUTABLE = 'java-mac-ls'
-- elseif vim.fn.has("unix") == 1 then
-- JAVA_LS_EXECUTABLE = 'java-linux-ls'
-- else
-- print("Unsupported system")
-- end
local bundles = {
vim.fn.glob(
CONFIG_PATH.."/.debuggers/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar")
};
-- local bundles = {
-- vim.fn.glob(
-- CONFIG_PATH.."/.debuggers/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar")
-- };
local on_attach = function(client, bufr)
require('jdtls').setup_dap()
-- require('jdtls').setup_dap()
require'lsp'.common_on_attach(client, bufr)
end
require('jdtls').start_or_attach({
require'lspconfig'.jdtls.setup {
on_attach = on_attach,
cmd = {JAVA_LS_EXECUTABLE},
root_dir = require('jdtls.setup').find_root({'build.gradle', 'pom.xml', '.git'}),
init_options = {bundles = bundles}
})
cmd = {DATA_PATH .. "/lspinstall/java/jdtls.sh"},
filetypes = { "java" },
root_dir = util.root_pattern({'.git', 'build.gradle', 'pom.xml'}),
-- init_options = {bundles = bundles}
-- on_attach = require'lsp'.common_on_attach
}
-- require('jdtls').start_or_attach({
-- on_attach = on_attach,
-- cmd = {DATA_PATH .. "/lspinstall/java/jdtls.sh"},
-- root_dir = require('jdtls.setup').find_root({'build.gradle', 'pom.xml', '.git'}),
-- init_options = {bundles = bundles}
-- })

View file

@ -41,7 +41,7 @@ utils.define_augroups({
-- {'User', 'GoyoEnter', 'lua require(\'galaxyline\').galaxyline_augroup()'},
},
_java = {
{'FileType', 'java', 'luafile '..CONFIG_PATH..'/lua/lsp/java-ls.lua'},
-- {'FileType', 'java', 'luafile '..CONFIG_PATH..'/lua/lsp/java-ls.lua'},
{'FileType', 'java', 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>'}
},
_go = {

View file

@ -5,15 +5,15 @@ require'lspconfig/configs'.jdtls = nil -- important, unset the loaded config aga
-- config.default_config.cmd[1] = "./node_modules/.bin/bash-language-server"
-- 2. extend the config with an install_script and (optionally) uninstall_script
require'lspinstall/servers'.jdtls = vim.tbl_extend('error', config, {
-- lspinstall will automatically create/delete the install directory for every server
install_script = [[
git clone https://github.com/eclipse/eclipse.jdt.ls.git
cd eclipse.jdt.ls
./mvnw clean verify
]],
uninstall_script = nil -- can be omitted
})
-- require'lspinstall/servers'.jdtls = vim.tbl_extend('error', config, {
-- -- lspinstall will automatically create/delete the install directory for every server
-- install_script = [[
-- git clone https://github.com/eclipse/eclipse.jdt.ls.git
-- cd eclipse.jdt.ls
-- ./mvnw clean verify
-- ]],
-- uninstall_script = nil -- can be omitted
-- })
require'lspinstall/servers'.kotlin = vim.tbl_extend('error', config, {
install_script = [[