-- Change jdtls_path to wherever you have your Eclipse Java development tools (JDT) Language Server downloaded to.
local jdtls_path = vim.fn.stdpath('data') .. '/mason/packages/jdtls'
local launcher_jar = vim.fn.glob(jdtlspath .. '/plugins/org.eclipse.equinox.launcher*.jar')
local workspace_dir = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t')
local path_to_lombok = jdtls_path .. '/lombok.jar'
vim.o.tabstop = 4
vim.o.shiftwidth = 0
-- for completions
local client_capabilities = vim.lsp.protocol.make_client_capabilities()
local capabilities = cmp_nvim_lsp.default_capabilities(client_capabilities)
local function get_config_dir()
-- Unlike some other programming languages (e.g. JavaScript)
-- lua considers 0 truthy!
if vim.fn.has('linux') == 1 then
return 'config_linux'
elseif vim.fn.has('mac') == 1 then
return 'config_mac'
else
return 'config_win'
end
end
-- See :help vim.lsp.start_client for an overview of the supported config options.
local config = {
capabilities = capabilities,
cmd = {
-- This sample path was tested on Cygwin, a "unix-like" Windows environment.
-- Please contribute to this Wiki if this doesn't work for another Windows
-- environment like Git for Windows or PowerShell.
-- JDTLS currently needs Java 17 to work, but you can replace this line with "java"
-- if Java 17 is on your PATH.
"java",
"-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",
"-javaagent:" .. path_to_lombok,
"-Xmx1G",
"--add-modules=ALL-SYSTEM",
"--add-opens", "java.base/java.util=ALL-UNNAMED",
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"-jar", launcher_jar,
"-configuration", vim.fs.normalize(jdtls_path .. '/' .. get_config_dir()),
"-data", vim.fn.expand('~/.cache/jdtls-workspace/') .. workspace_dir
},
settings = {
['java.format.settings.url'] = vim.fn.expand("~/formatter.xml")
},
root_dir = vim.fs.dirname(vim.fs.find({ 'pom.xml', '.git' }, { upward = true })[1]),
init_options = {
-- https://github.com/eclipse/eclipse.jdt.ls/wiki/Language-Server-Settings-&-Capabilities#extended-client-capabilities
extendedClientCapabilities = jdtls.extendedClientCapabilities,
},
on_attach = function(client, bufnr)
-- https://github.com/mfussenegger/dotfiles/blob/833d634251ebf3bf7e9899ed06ac710735d392da/vim/.config/nvim/ftplugin/java.lua#L88-L94
local opts = { silent = true, buffer = bufnr }
vim.keymap.set('n', "lo", jdtls.organize_imports, { desc = 'Organize imports', buffer = bufnr })
-- Should 'd' be reserved for debug?
vim.keymap.set('n', "df", jdtls.test_class, opts)
vim.keymap.set('n', "dn", jdtls.test_nearest_method, opts)
vim.keymap.set('n', 'rv', jdtls.extract_variable_all, { desc = 'Extract variable', buffer = bufnr })
vim.keymap.set('v', 'rm', [[lua require('jdtls').extract_method(true)]],
{ desc = 'Extract method', buffer = bufnr })
vim.keymap.set('n', 'rc', jdtls.extract_constant, { desc = 'Extract constant', buffer = bufnr })
end
}
jdtls.start_or_attach(config)
Eclipse.jdt.ls version
1.6.4
Steps to Reproduce
JdtCompile
JdtBytecode
Expected Result
I was expecting to see the compiled files after I run jdtcompile
I was also expecting to see the code result when i run the jdtbytecode but it shows a weird byte code
Actual Result
Result JdtCompile Compiletaion Successuful -> But I don't see any of those compiled files
Result JdtBytecode is in the image below, it just shows a byte file I was expecting it would run and show the result.
As the name implies JdtBytecode shows the java bytecode. That's working as expected.
JdtCompile builds the workspace and shows errors if there are any. Also working as expected
LSP client configuration
-- Eclipse Java development tools (JDT) Language Server downloaded from: -- https://www.eclipse.org/downloads/download.php?file=/jdtls/milestones/1.21.0/jdt-language-server-1.21.0-202303161431.tar.gz local jdtls = require('jdtls') -- Change or delete this if you don't depend on nvim-cmp for completions. local cmp_nvim_lsp = require('cmp_nvim_lsp')
-- Change jdtls_path to wherever you have your Eclipse Java development tools (JDT) Language Server downloaded to. local jdtls_path = vim.fn.stdpath('data') .. '/mason/packages/jdtls' local launcher_jar = vim.fn.glob(jdtlspath .. '/plugins/org.eclipse.equinox.launcher*.jar') local workspace_dir = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t') local path_to_lombok = jdtls_path .. '/lombok.jar' vim.o.tabstop = 4 vim.o.shiftwidth = 0
-- for completions local client_capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = cmp_nvim_lsp.default_capabilities(client_capabilities)
local function get_config_dir() -- Unlike some other programming languages (e.g. JavaScript) -- lua considers 0 truthy! if vim.fn.has('linux') == 1 then return 'config_linux' elseif vim.fn.has('mac') == 1 then return 'config_mac' else return 'config_win' end end
-- Seelo", jdtls.organize_imports, { desc = 'Organize imports', buffer = bufnr })
-- Should 'd' be reserved for debug?
vim.keymap.set('n', "df", jdtls.test_class, opts)
vim.keymap.set('n', "dn", jdtls.test_nearest_method, opts)
vim.keymap.set('n', 'rv', jdtls.extract_variable_all, { desc = 'Extract variable', buffer = bufnr })
vim.keymap.set('v', 'rm', [[lua require('jdtls').extract_method(true)]],
{ desc = 'Extract method', buffer = bufnr })
vim.keymap.set('n', 'rc', jdtls.extract_constant, { desc = 'Extract constant', buffer = bufnr })
end
}
:help vim.lsp.start_client
for an overview of the supportedconfig
options. local config = { capabilities = capabilities, cmd = { -- This sample path was tested on Cygwin, a "unix-like" Windows environment. -- Please contribute to this Wiki if this doesn't work for another Windows -- environment like Git for Windows or PowerShell. -- JDTLS currently needs Java 17 to work, but you can replace this line with "java" -- if Java 17 is on your PATH. "java", "-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", "-javaagent:" .. path_to_lombok, "-Xmx1G", "--add-modules=ALL-SYSTEM", "--add-opens", "java.base/java.util=ALL-UNNAMED", "--add-opens", "java.base/java.lang=ALL-UNNAMED", "-jar", launcher_jar, "-configuration", vim.fs.normalize(jdtls_path .. '/' .. get_config_dir()), "-data", vim.fn.expand('~/.cache/jdtls-workspace/') .. workspace_dir }, settings = { ['java.format.settings.url'] = vim.fn.expand("~/formatter.xml") }, root_dir = vim.fs.dirname(vim.fs.find({ 'pom.xml', '.git' }, { upward = true })[1]), init_options = { -- https://github.com/eclipse/eclipse.jdt.ls/wiki/Language-Server-Settings-&-Capabilities#extended-client-capabilities extendedClientCapabilities = jdtls.extendedClientCapabilities, }, on_attach = function(client, bufnr) -- https://github.com/mfussenegger/dotfiles/blob/833d634251ebf3bf7e9899ed06ac710735d392da/vim/.config/nvim/ftplugin/java.lua#L88-L94 local opts = { silent = true, buffer = bufnr } vim.keymap.set('n', "jdtls.start_or_attach(config)
Eclipse.jdt.ls version
1.6.4
Steps to Reproduce
JdtCompile JdtBytecode
Expected Result
Actual Result
Result![image](https://github.com/mfussenegger/nvim-jdtls/assets/68199580/bc89569f-bd6c-4a44-bc5e-5ac3bbda93b2)
JdtCompile
Compiletaion Successuful -> But I don't see any of those compiled files ResultJdtBytecode
is in the image below, it just shows a byte file I was expecting it would run and show the result.