mfussenegger / nvim-jdtls

Extensions for the built-in LSP support in Neovim for eclipse.jdt.ls
GNU General Public License v3.0
1.05k stars 61 forks source link

Jdtls autostart return false #498

Closed bonzonkim closed 1 year ago

bonzonkim commented 1 year ago

LSP client configuration

local jdtls = require('jdtls')

local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t')

local home = os.getenv('HOME') local java_home = '/Users/b9/.asdf/installs/java/adoptopenjdk-17.0.6+10' -- Workspace 위치 바꾸는 곳 -- local workspace_dir = home .. '/bonzonkim/github.com/' .. project_name local workspace_dir = home .. '/bonzonkim/github.com'

local root_markers = {'gradlew', 'mvnw', '.git'} local root_dir = require('jdtls.setup').find_root(root_markers)

local language_server_dir = '/opt/homebrew/Cellar/jdtls/1.22.0/libexec'

-- Helper function for creating keymaps function nnoremap(rhs, lhs, bufopts, desc) bufopts.desc = desc vim.keymap.set("n", rhs, lhs, bufopts) end

local on_attach = function(client, bufnr) -- Regular Neovim LSP client keymappings local bufopts = { noremap=true, silent=true, buffer=bufnr } -- Java extensions provided by jdtls nnoremap("", jdtls.organize_imports, bufopts, "Organize imports") nnoremap("ev", jdtls.extract_variable, bufopts, "Extract variable") nnoremap("ec", jdtls.extract_constant, bufopts, "Extract constant") vim.keymap.set('v', "em", [[lua require('jdtls').extract_method(true)]], { noremap=true, silent=true, buffer=bufnr, desc = "Extract method" }) end

-- See :help vim.lsp.start_client for an overview of the supported config options. local config = { flags = { debounce_text_changes = 80, }, -- The command that starts the language server -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line on_attach = on_attach, root_dir = root_dir, cmd = { -- 💀 java_home .. '/bin/java', -- or '/path/to/java17_or_newer/bin/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', '-Xmx4g', '--add-modules=ALL-SYSTEM', '--add-opens', 'java.base/java.util=ALL-UNNAMED', '--add-opens', 'java.base/java.lang=ALL-UNNAMED',

-- 💀
'-jar', language_server_dir .. '/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar',
     -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                       ^^^^^^^^^^^^^^
     -- Must point to the                                                     Change this to
     -- eclipse.jdt.ls installation                                           the actual version

-- lombok 쓰려면 해당 라인 수정
-- https://bit.ly/3MJ78PQ
 '-javaagent:' .. home .. '/.local/share/eclipse/lombok.jar',

-- 💀
'-configuration', language_server_dir .. '/config_mac',
                -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        ^^^^^^
                -- Must point to the                      Change to one of `linux`, `win` or `mac`
                -- eclipse.jdt.ls installation            Depending on your system.

-- 💀
-- See `data directory configuration` section in the README
'-data', workspace_dir,

},

-- Here you can configure eclipse.jdt.ls specific settings -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request -- for a list of options settings = { java = { format = { settings = { -- Use Google Java style guidelines for formatting -- To use, make sure to download the file from https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml -- and place it in the ~/.local/share/eclipse directory url = home .. "/.local/share/eclipse/eclipse-java-google-style.xml", profile = "GoogleStyle", }, }, signatureHelp = { enabled = true }, contentProvider = { preferred = 'fernflower' }, -- Use fernflower to decompile library code -- Specify any completion options completion = { favoriteStaticMembers = { "org.hamcrest.MatcherAssert.assertThat", "org.hamcrest.Matchers.", "org.hamcrest.CoreMatchers.", "org.junit.jupiter.api.Assertions.", "java.util.Objects.requireNonNull", "java.util.Objects.requireNonNullElse", "org.mockito.Mockito." }, filteredTypes = { "com.sun.", "io.micrometer.shaded.", "java.awt.", "jdk.", "sun.*", }, }, -- Specify any options for organizing imports sources = { organizeImports = { starThreshold = 9999; staticStarThreshold = 9999; }, }, -- How code generation should act codeGeneration = { toString = { template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}" }, hashCodeEquals = { useJava7Objects = true, }, useBlocks = true, }, -- If you are developing in projects with different Java versions, you need -- to tell eclipse.jdt.ls to use the location of the JDK for your Java version -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request -- And search for interface RuntimeOption -- The name is NOT arbitrary, but must match one of the elements from enum ExecutionEnvironment in the link above configuration = { runtimes = { { name = "JavaSE-17", path = home .. "/.asdf/installs/java/adoptopenjdk-17.0.6+10", }, { name = "JavaSE-11", path = home .. "/.asdf/installs/java/zulu-11.62.17", }, } } } },

-- Language server initializationOptions -- You need to extend the bundles with paths to jar files -- if you want to use additional eclipse.jdt.ls plugins.

-- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation

-- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this init_options = { bundles = {} }, } -- This starts a new client & server, -- or attaches to an existing client & server depending on the root_dir. -- require('jdtls').start_or_attach(config)

jdtls.start_or_attach(config)

Eclipse.jdt.ls version

1.22.0

Steps to Reproduce

in a project using maven and it was works well, but it suddenly refuses to work. I didn't make any change to my java.lua config file.

Expected Result

I have no idea none about this...

Actual Result

./local/state/nvim/lsp.log

[ERROR][2023-05-30 12:44:18] ...lsp/handlers.lua:535    "May 30, 2023, 12:44:18 p.m. Command _java.reloadBundles.command not supported on client"

LspInfo

 Press q or <Esc> to close this window. Press <Tab> to view server doc.

 Language client log: /Users/b9/.local/state/nvim/lsp.log
 Detected filetype:   java

 1 client(s) attached to this buffer: 

 Client: jdtls (id: 1, bufnr: [14])
    filetypes:       java
    autostart:       false
    root directory:  /Users/b9/bonzonkim/github.com/LIVELY
    cmd:             /Users/b9/.asdf/installs/java/adoptopenjdk-17.0.6+10/bin/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 -Xmx4g --add-modules=ALL-SYSTEM --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED -jar /opt/homebrew/Cellar/jdtls/1.22.0/libexec/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar -javaagent:/Users/b9/.local/share/eclipse/lombok.jar -configuration /opt/homebrew/Cellar/jdtls/1.22.0/libexec/config_mac -data /Users/b9/bonzonkim/github.com
mfussenegger commented 1 year ago

That autostart returns false is expected given that it's not registered with lspconfig.

As for the stopped working part: Try deleting the -data / workspace folder and read the troubleshooting section.