Configure jdtls properly
parent
14afde50ae
commit
9d0240d292
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
JAR="$HOME/lsp/java/jdtls/plugins/org.eclipse.equinox.launcher_*.jar"
|
||||||
|
UNAME=$(sh -c 'uname 2>/dev/null || echo Unknown')
|
||||||
|
CONFIGURATION="$HOME/lsp/java/jdtls/config_"
|
||||||
|
|
||||||
|
if [[ "$UNAME" == "Windows_NT" ]]; then
|
||||||
|
UNAME="Windows"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $UNAME in
|
||||||
|
Linux)
|
||||||
|
CONFIGURATION="${CONFIGURATION}linux"
|
||||||
|
;;
|
||||||
|
Windows)
|
||||||
|
CONFIGURATION="${CONFIGURATION}win"
|
||||||
|
;;
|
||||||
|
Darwin)
|
||||||
|
CONFIGURATION="${CONFIGURATION}mac"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
java \
|
||||||
|
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 \
|
||||||
|
-Declipse.application=org.eclipse.jdt.ls.core.id1 \
|
||||||
|
-Dosgi.bundles.defaultStartLevel=4 \
|
||||||
|
-Declipse.product=org.eclipse.jdt.ls.core.product \
|
||||||
|
-Dlog.protocol=true \
|
||||||
|
-Dlog.level=ALL \
|
||||||
|
-Xms1g \
|
||||||
|
-Xmx2G \
|
||||||
|
-jar $(echo "$JAR") \
|
||||||
|
-configuration $(echo "$CONFIGURATION") \
|
||||||
|
-data "$1" \
|
||||||
|
--add-modules=ALL-SYSTEM \
|
||||||
|
--add-opens java.base/java.util=ALL-UNNAMED \
|
||||||
|
--add-opens java.base/java.lang=ALL-UNNAMED
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
SERVER=$1
|
||||||
|
VERSION=$2
|
||||||
|
|
||||||
|
UNAME=$(sh -c 'uname 2>/dev/null || echo Unknown')
|
||||||
|
if [[ "$UNAME" == "Windows_NT" ]]; then
|
||||||
|
UNAME="Windows"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $SERVER in
|
||||||
|
jdtls)
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
VERSION="1.4.0"
|
||||||
|
fi
|
||||||
|
FILE_NAME=$(curl https://download.eclipse.org/jdtls/milestones/$VERSION/latest.txt)
|
||||||
|
wget -O - https://download.eclipse.org/jdtls/milestones/$VERSION/$FILE_NAME > /tmp/jdtls.tar.gz
|
||||||
|
mkdir -p $HOME/lsp/java/jdtls
|
||||||
|
tar -xf /tmp/jdtls.tar.gz -C $HOME/lsp/java/jdtls
|
||||||
|
;;
|
||||||
|
omnisharp)
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
VERSION="v1.37.16"
|
||||||
|
fi
|
||||||
|
case $UNAME in
|
||||||
|
Linux)
|
||||||
|
FILE_NAME="omnisharp-linux-x64.tar.gz"
|
||||||
|
;;
|
||||||
|
Darwin)
|
||||||
|
FILE_NAME="omnisharp-osx.tar.gz"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
wget -O - https://github.com/OmniSharp/omnisharp-roslyn/releases/download/$VERSION/$FILE_NAME > /tmp/omnisharp.tar.gz
|
||||||
|
mkdir -p $HOME/lsp/dotnet/omnisharp
|
||||||
|
tar -xf /tmp/omnisharp.tar.gz -C $HOME/lsp/dotnet/omnisharp
|
||||||
|
;;
|
||||||
|
esac
|
|
@ -1,4 +1 @@
|
||||||
require('jdtls').start_or_attach {
|
require('lsp.jdtls_setup').setup()
|
||||||
cmd = {'jdtls-startup.sh'};
|
|
||||||
on_attach = require'lsp.servers'.jdtls_on_attach;
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
-- - JDTLS server configuration -
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local common_config = require("lsp.server_config")
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.setup()
|
||||||
|
require'jdtls.setup'.add_commands()
|
||||||
|
require'jdtls'.setup_dap()
|
||||||
|
local 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}
|
||||||
|
|
||||||
|
common_config.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
|
||||||
|
|
||||||
|
local root_markers = {'gradlew', 'pom.xml'}
|
||||||
|
local root_dir = require('jdtls.setup').find_root(root_markers)
|
||||||
|
local home = os.getenv('HOME')
|
||||||
|
|
||||||
|
local capabilities = {
|
||||||
|
workspace = {
|
||||||
|
configuration = true
|
||||||
|
},
|
||||||
|
textDocument = {
|
||||||
|
completion = {
|
||||||
|
completionItem = {
|
||||||
|
snippetSupport = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
local workspace_folder = home .. "/.workspace" .. vim.fn.fnamemodify(root_dir, ":p:h:t")
|
||||||
|
local config = {
|
||||||
|
flags = {
|
||||||
|
allow_incremental_sync = true,
|
||||||
|
};
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
}
|
||||||
|
config.settings = {
|
||||||
|
java = {
|
||||||
|
signatureHelp = { enabled = true };
|
||||||
|
sources = {
|
||||||
|
organizeImports = {
|
||||||
|
starThreshold = 9999;
|
||||||
|
staticStarThreshold = 9999;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
config.cmd = {'jdtls-start.sh', workspace_folder}
|
||||||
|
config.on_init = function(client, _)
|
||||||
|
client.notify('workspace/didChangeConfiguration', { settings = config.settings })
|
||||||
|
end
|
||||||
|
|
||||||
|
local extendedClientCapabilities = require'jdtls'.extendedClientCapabilities
|
||||||
|
extendedClientCapabilities.resolveAdditionalTextEditsSupport = true
|
||||||
|
config.init_options = {
|
||||||
|
-- bundles = bundles;
|
||||||
|
extendedClientCapabilities = extendedClientCapabilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
-- UI
|
||||||
|
local finders = require'telescope.finders'
|
||||||
|
local sorters = require'telescope.sorters'
|
||||||
|
local actions = require'telescope.actions'
|
||||||
|
local pickers = require'telescope.pickers'
|
||||||
|
require('jdtls.ui').pick_one_async = function(items, prompt, label_fn, cb)
|
||||||
|
local opts = {}
|
||||||
|
pickers.new(opts, {
|
||||||
|
prompt_title = prompt,
|
||||||
|
finder = finders.new_table {
|
||||||
|
results = items,
|
||||||
|
entry_maker = function(entry)
|
||||||
|
return {
|
||||||
|
value = entry,
|
||||||
|
display = label_fn(entry),
|
||||||
|
ordinal = label_fn(entry),
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
sorter = sorters.get_generic_fuzzy_sorter(),
|
||||||
|
attach_mappings = function(prompt_bufnr)
|
||||||
|
actions.select_default:replace(function()
|
||||||
|
local selection = actions.get_selected_entry(prompt_bufnr)
|
||||||
|
actions.close(prompt_bufnr)
|
||||||
|
|
||||||
|
cb(selection.value)
|
||||||
|
end)
|
||||||
|
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
}):find()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Server
|
||||||
|
require('jdtls').start_or_attach(config)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
|
@ -0,0 +1,28 @@
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
-- - LSP servers common config -
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.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}
|
||||||
|
|
||||||
|
-- Lsp keymaps
|
||||||
|
buf_set_keymap('n', '<C-]>', '<cmd>lua vim.lsp.buf.definition()<CR>', default_opts)
|
||||||
|
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', default_opts)
|
||||||
|
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', default_opts)
|
||||||
|
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', default_opts)
|
||||||
|
buf_set_keymap('n', '<Leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', default_opts)
|
||||||
|
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', default_opts)
|
||||||
|
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', default_opts)
|
||||||
|
buf_set_keymap('n', '<A-CR>', '<cmd>lua vim.lsp.buf.code_action()<CR>', default_opts)
|
||||||
|
buf_set_keymap('n', '<Leader>ac', '<cmd>lua vim.lsp.buf.code_action()<CR>', default_opts)
|
||||||
|
buf_set_keymap('n', '<Leader>a', '<cmd>lua vim.lsp.buf.code_action_range()<CR>', default_opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M;
|
|
@ -3,37 +3,17 @@
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
local lspconfig = require("lspconfig")
|
local lspconfig = require("lspconfig")
|
||||||
|
local common_config = require("lsp.server_config")
|
||||||
local 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}
|
|
||||||
|
|
||||||
-- Lsp keymaps
|
|
||||||
buf_set_keymap('n', '<C-]>', '<cmd>lua vim.lsp.buf.definition()<CR>', default_opts)
|
|
||||||
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', default_opts)
|
|
||||||
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', default_opts)
|
|
||||||
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', default_opts)
|
|
||||||
buf_set_keymap('n', '<Leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', default_opts)
|
|
||||||
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', default_opts)
|
|
||||||
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', default_opts)
|
|
||||||
buf_set_keymap('n', '<A-CR>', '<cmd>lua vim.lsp.buf.code_action()<CR>', default_opts)
|
|
||||||
buf_set_keymap('n', '<Leader>ac', '<cmd>lua vim.lsp.buf.code_action()<CR>', default_opts)
|
|
||||||
buf_set_keymap('n', '<Leader>a', '<cmd>lua vim.lsp.buf.code_action_range()<CR>', default_opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Lsp default language servers
|
-- Lsp default language servers
|
||||||
local servers = { "bashls", "clangd", "cucumber_language_server", "crystalline", "dockerls", "jsonls", "pyright", "rust_analyzer", "kotlin_language_server", "mint", "vimls", "clojure_lsp", "gopls", "gdscript", "terraformls", "tsserver" }
|
local servers = { "bashls", "clangd", "cucumber_language_server", "crystalline", "dockerls", "jsonls", "pyright", "rust_analyzer", "kotlin_language_server", "mint", "vimls", "clojure_lsp", "gopls", "gdscript", "terraformls", "tsserver" }
|
||||||
for _, lsp in ipairs(servers) do
|
for _, lsp in ipairs(servers) do
|
||||||
lspconfig[lsp].setup { on_attach = on_attach }
|
lspconfig[lsp].setup { on_attach = common_config.on_attach }
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Lua bultin lsp
|
-- Lua bultin lsp
|
||||||
require('nlua.lsp.nvim').setup(lspconfig, {
|
require('nlua.lsp.nvim').setup(lspconfig, {
|
||||||
on_attach = on_attach,
|
on_attach = common_config.on_attach,
|
||||||
|
|
||||||
-- Include globals you want to tell the LSP are real :)
|
-- Include globals you want to tell the LSP are real :)
|
||||||
globals = {}
|
globals = {}
|
||||||
|
@ -42,7 +22,7 @@ require('nlua.lsp.nvim').setup(lspconfig, {
|
||||||
-- Flutter tools
|
-- Flutter tools
|
||||||
require('flutter-tools').setup {
|
require('flutter-tools').setup {
|
||||||
lsp = {
|
lsp = {
|
||||||
on_attach = on_attach
|
on_attach = common_config.on_attach
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,31 +31,11 @@ local pid = vim.fn.getpid()
|
||||||
local omnisharp_bin = vim.fn.glob('$HOME') .. "/lsp/dotnet/omnisharp/run"
|
local omnisharp_bin = vim.fn.glob('$HOME') .. "/lsp/dotnet/omnisharp/run"
|
||||||
lspconfig.omnisharp.setup {
|
lspconfig.omnisharp.setup {
|
||||||
cmd = { omnisharp_bin, "--languageserver" , "--hostPID", tostring(pid) };
|
cmd = { omnisharp_bin, "--languageserver" , "--hostPID", tostring(pid) };
|
||||||
on_attach = on_attach;
|
on_attach = common_config.on_attach;
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Leminx (XML Language server)
|
-- Leminx (XML Language server)
|
||||||
lspconfig.lemminx.setup {
|
lspconfig.lemminx.setup {
|
||||||
cmd = { "lemminx" };
|
cmd = { "lemminx" };
|
||||||
on_attach = on_attach;
|
on_attach = common_config.on_attach;
|
||||||
}
|
|
||||||
|
|
||||||
-- JDTLS (Java)
|
|
||||||
-- Can't be local currently, because autocommand has to be used
|
|
||||||
jdtls_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
|
|
||||||
|
|
||||||
return {
|
|
||||||
jdtls_on_attach = jdtls_on_attach
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue