mfussenegger / nvim-jdtls

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

Doesn't launch debug session #117

Closed Vliro closed 2 years ago

Vliro commented 3 years ago

LSP client configuration

My LSP config.

local lsp = require 'vim.lsp'
local jdtls = require 'jdtls'
local api = vim.api
local dap = require 'dap'
-- id is filetype│root_dir
local lsps = {}

dap.adapters.java = function(callback)
  -- here a function needs to trigger the `vscode.java.startDebugSession` LSP command
  -- The response to the command must be the `port` used below
local params = {
        command = "vscode.java.startDebugSession",
        arguments = {},
        title = ""
}
aport = vim.lsp.buf_request_sync(vim.api.nvim_get_current_buf(), "workspace/executeCommand", params, 500)
obj = aport[1].result

  callback({
    type = 'server';
    host = '127.0.0.1';
    port = obj;
  })
end

dap.configurations.java = {
    {
    projectName = "GregTech",
    javaExec = "/usr/lib/jvm/java-8-openjdk/bin/java",
    mainClass = "net.minecraftforge.userdev.LaunchTesting",
    -- If using the JDK9+ module system, this needs to be extended
    -- `nvim-jdtls` would automatically populate this property
    classPaths = {},
    name = "runClient",
    cwd = "${workspaceFolder}/run",
    args = {"-mixin.config=antimatter.mixins.json"},
    request = "launch",
    type = "java",
    vmArgs = "-Dforge.logging.console.level=debug -Dforge.logging.markers=DEBUG -Dmixin.env.remapRefMap=true -Dmixin.env.refMapRemappingFile=/home/abbe/Dev/GregTech/build/createSrgToMcp/output.srg",
    env = {
        MOD_CLASSES = "gti%%/home/abbe/Dev/GregTech/bin/main:gti%%/home/abbe/Dev/GregTech/bin/main:antimatter%%/home/abbe/Dev/GregTech/AntimatterAPI/bin/main:antimatter%%/home/abbe/Dev/GregTech/AntimatterAPI/bin/main:tesseract%%/home/abbe/Dev/GregTech/AntimatterAPI/TesseractAPI/bin/main:tesseract%%/home/abbe/Dev/GregTech/AntimatterAPI/TesseractAPI/bin/main",
        MCP_MAPPINGS = "snapshot_20210309-1.16.5",
        MCP_VERSION = "20210115.111550",
        FORGE_VERSION = "36.1.4",
        assetIndex = "1.16",
        assetDirectory = "/home/abbe/.gradle/caches/forge_gradle/assets",
        nativesDirectory = "${workspaceFolder}/build/natives",
        FORGE_GROUP = "net.minecraftforge",
        target = "fmluserdevclient",
        MC_VERSION = "1.16.5"
      }
    },
}

local function add_client_by_cfg(config, root_markers)
    local root_dir = require('jdtls.setup').find_root(root_markers)
    if not root_dir then return end

    local cmd = config.cmd[1]
    if tonumber(vim.fn.executable(cmd)) == 0 then
        api.nvim_command(string.format(
            ':echohl WarningMsg | redraw | echo "No LSP executable: %s" | echohl None', cmd))
        return
    end
    config['root_dir'] = root_dir
    local lsp_id = tostring(vim.bo.filetype) .. "│" .. root_dir
    local client_id = lsps[lsp_id]
    if not client_id then
        client_id = lsp.start_client(config)
        lsps[lsp_id] = client_id
    end
    local bufnr = api.nvim_get_current_buf()
    lsp.buf_attach_client(bufnr, client_id)
end

-- array of mappings to setup; {<capability_name>, <mode>, <lhs>, <rhs>}
local key_mappings = {
    {"code_action", "n", "<a-CR>", "<Cmd>lua require'jdtls'.code_action()<CR>"},
    {"code_action", "n", "<leader>r", "<Cmd>lua require'jdtls'.code_action(false, 'refactor')<CR>"},
    {"code_action", "v", "<a-CR>", "<Esc><Cmd>lua require'jdtls'.code_action(true)<CR>"},
    {"code_action", "v", "<leader>r", "<Esc><Cmd>lua require'jdtls'.code_action(true, 'refactor')<CR>"},

    {"document_formatting", "n", "gq", "<Cmd>lua vim.lsp.buf.formatting()<CR>"},
    {"document_range_formatting", "v", "gq", "<Esc><Cmd>lua vim.lsp.buf.range_formatting()<CR>"},
    {"find_references", "n", "gr", "<Cmd>lua vim.lsp.buf.references()<CR>"},
    {"hover", "n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>"},
    {"implementation", "n", "gD",  "<Cmd>lua vim.lsp.buf.implementation()<CR>"},
    {"signature_help", "i", "<c-space>",  "<Cmd>lua vim.lsp.buf.signature_help()<CR>"},
    {"workspace_symbol", "n", "gW", "<Cmd>lua vim.lsp.buf.workspace_symbol()<CR>"}
}

local function on_attach(client, bufnr)
    api.nvim_buf_set_var(bufnr, "lsp_client_id", client.id)
    api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
    api.nvim_buf_set_option(bufnr, "bufhidden", "hide")
    api.nvim_set_current_dir(client.config.root_dir)
    api.nvim_command("setlocal signcolumn=yes")

    if client.resolved_capabilities.goto_definition then
      api.nvim_buf_set_option(bufnr, 'tagfunc', "v:lua.lsp_ext.tagfunc")
    end
    local opts = { silent = true; }
    for _, mappings in pairs(key_mappings) do
        local capability, mode, lhs, rhs = unpack(mappings)
        if client.resolved_capabilities[capability] then
            api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts)
        end
    end
    api.nvim_buf_set_keymap(bufnr, "n", "<space>", "<Cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts)
    api.nvim_buf_set_keymap(bufnr, "n", "crr", "<Cmd>lua vim.lsp.buf.rename(vim.fn.input('New Name: '))<CR>", opts)
    api.nvim_buf_set_keymap(bufnr, "n", "]w", "<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
    api.nvim_buf_set_keymap(bufnr, "n", "[w", "<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)
    api.nvim_buf_set_keymap(bufnr, "i", "<c-n>", "<Cmd>lua require('lsp-ext').trigger_completion()<CR>", opts)
    if client.resolved_capabilities['document_highlight'] then
      api.nvim_command [[autocmd CursorHold  <buffer> lua vim.lsp.buf.document_highlight()]]
      api.nvim_command [[autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()]]
      api.nvim_command [[autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()]]
    end
end

local function jdtls_on_attach(client, bufnr)
    on_attach(client, bufnr)
    local opts = { silent = true; }
    jdtls.setup.add_commands()
    jdtls.setup_dap({ hotcodereplace = 'auto' }) 
    api.nvim_buf_set_keymap(bufnr, "n", "<A-o>", "<Cmd>lua require'jdtls'.organize_imports()<CR>", opts)
    api.nvim_buf_set_keymap(bufnr, "n", "<leader>df", "<Cmd>lua require'jdtls'.test_class()<CR>", opts)
    api.nvim_buf_set_keymap(bufnr, "n", "<leader>dn", "<Cmd>lua require'jdtls'.test_nearest_method()<CR>", opts)
    api.nvim_buf_set_keymap(bufnr, "v", "crv", "<Esc><Cmd>lua require('jdtls').extract_variable(true)<CR>", opts)
    api.nvim_buf_set_keymap(bufnr, "n", "crv", "<Cmd>lua require('jdtls').extract_variable()<CR>", opts)
    api.nvim_buf_set_keymap(bufnr, "v", "crm", "<Esc><Cmd>lua require('jdtls').extract_method(true)<CR>", opts)

end

local function mk_config()
  local capabilities = lsp.protocol.make_client_capabilities()
  capabilities.workspace.configuration = true
  capabilities.textDocument.completion.completionItem.snippetSupport = true
  return {
    flags = {
      allow_incremental_sync = true,
    };

    capabilities = capabilities;
    on_attach = on_attach;
  }
end

local M = {}
function M.add_client(cmd, opts)
  local config = mk_config()
  config['name'] = opts and opts.name or cmd[1]
  config['cmd'] = cmd
  add_client_by_cfg(config, opts and opts.root or {'.git'})
end

function M.start_jdt()
  local root_markers = {'gradlew', '.git'}
  local root_dir = require('jdtls.setup').find_root(root_markers)
  local home = os.getenv('HOME')
  local workspace_folder = home .. "/.local/share/eclipse/" .. vim.fn.fnamemodify(root_dir, ":p:h:t")
  local config = mk_config()
  config.flags.server_side_fuzzy_completion = true
  config.settings = {
    java = {
      signatureHelp = { enabled = true };
      contentProvider = { preferred = 'fernflower' };
      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.*"
        }
      };
      sources = {
        organizeImports = {
          starThreshold = 9999;
          staticStarThreshold = 9999;
        };
      };
      codeGeneration = {
        toString = {
          template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}"
        }
      };
      configuration = {
        runtimes = {
          {
            name = "JavaSE-11",
            path = "/usr/lib/jvm/java-11-openjdk/",
          },
          {
            name = "JavaSE-16",
            path = "/usr/lib/jvm/java-16-openjdk/",
          },
        }
      };
    };
  }
  config.cmd = {'java-lsp.sh', workspace_folder}
  config.on_attach = jdtls_on_attach

  local jar_patterns = {
    '/dev/microsoft/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar',
    '/dev/dgileadi/vscode-java-decompiler/server/*.jar',
    '/dev/microsoft/vscode-java-test/server/*.jar',
  }
  local bundles = {}
  for _, jar_pattern in ipairs(jar_patterns) do
    for _, bundle in ipairs(vim.split(vim.fn.glob(home .. jar_pattern), '\n')) do
      if not vim.endswith(bundle, 'com.microsoft.java.test.runner.jar') then
        table.insert(bundles, bundle)
      end
    end
  end
  --print(vim.inspect(bundles))
  local extendedClientCapabilities = jdtls.extendedClientCapabilities;
  extendedClientCapabilities.resolveAdditionalTextEditsSupport = true;
  config.init_options = {
    bundles = {
    vim.fn.glob("/home/abbe/dev/microsoft/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-0.32.0.jar")
   };
    extendedClientCapabilities = extendedClientCapabilities;
  }
  jdtls.start_or_attach(config)
end

--- @export
return M

Eclipse.jdt.ls version

1.2.3

Steps to Reproduce

I have a project https://github.com/GregTech-Intergalactical/GregTech/ with subproject https://github.com/GregTech-Intergalactical/AntimatterAPI and https://github.com/GregTech-Intergalactical/TesseractAPI .It works in VS code. running ./gradlew runClient will start the program as usual, outside of nvim.

Expected Result

It should start a debug session. Instead complains that the adapter doesn't respond.

Actual Result

[ WARN ] 2021-08-17T13:20:44+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/handlers.lua:108 ]  "The language server jdt.ls triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[ ERROR ] 2021-08-17T13:20:49+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/handlers.lua:402 ] "17 Aug 2021, 13:20:49 Dispatch debug protocol error: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected STRING but was BEGIN_ARRAY at path $.args
java.lang.IllegalStateException: Expected STRING but was BEGIN_ARRAY at path $.args
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected STRING but was BEGIN_ARRAY at path $.args
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
    at com.google.gson.Gson.fromJson(Gson.java:932)
    at com.google.gson.Gson.fromJson(Gson.java:1003)
    at com.google.gson.Gson.fromJson(Gson.java:975)
    at com.microsoft.java.debug.core.protocol.JsonUtils.fromJson(JsonUtils.java:34)
    at com.microsoft.java.debug.core.adapter.DebugAdapter.dispatchRequest(DebugAdapter.java:78)
    at com.microsoft.java.debug.core.adapter.ProtocolServer.dispatchRequest(ProtocolServer.java:118)
    at com.microsoft.java.debug.core.protocol.AbstractProtocolServer.lambda$new$0(AbstractProtocolServer.java:78)
    at io.reactivex.internal.observers.LambdaObserver.onNext(LambdaObserver.java:60)
    at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:200)
    at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:252)
    at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
    at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.IllegalStateException: Expected STRING but was BEGIN_ARRAY at path $.args
    at com.google.gson.internal.bind.JsonTreeReader.nextString(JsonTreeReader.java:181)
    at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:402)
    at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:390)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
    ... 17 more
"
mfussenegger commented 3 years ago
  1. Given that you're calling jdtls.setup_dap({ hotcodereplace = 'auto' }) you can remove the dap.adapter.java definition. setup_dap adds it.

  2. The error indicates that you're sending an array for a property that is supposed to be a string.

aused by: java.lang.IllegalStateException: Expected STRING but was BEGIN_ARRAY at path $.args
    at com.google.gson.internal.bind.JsonTreeReader.nextString(JsonTreeReader.java:181)
    at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:402)
  1. How does the launch.json configuration that you use for vscode look like? If that configuration works, you could re-use it. See :help dap-launch.json

  2. Are you sure you understand what half of your configuration is doing? Looks like you copied pieces from my dotfiles that make little sense for most people.

Vliro commented 3 years ago

Ok thanks, I will.

I understood the reason, it was hard to understand as to why it did that. It seems that the args should be a string but not an array. However, setting it as a string gives me the following error:

[ ERROR ] 2021-08-17T19:13:45+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/handlers.lua:402 ] "17 Aug 2021, 19:13:45 [error response][launch]: Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.\nFailed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.\ncom.microsoft.java.debug.core.DebugException: Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.\n\tat com.microsoft.java.debug.core.adapter.AdapterUtils.createCompletionException(AdapterUtils.java:250)\n\tat com.microsoft.java.debug.core.adapter.handler.LaunchRequestHandler.handleLaunchCommand(LaunchRequestHandler.java:89)\n\tat com.microsoft.java.debug.core.adapter.handler.LaunchRequestHandler.handle(LaunchRequestHandler.java:81)\n\tat com.microsoft.java.debug.core.adapter.DebugAdapter.lambda$dispatchRequest$0(DebugAdapter.java:89)\n\tat java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1106)\n\tat java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2235)\n\tat com.microsoft.java.debug.core.adapter.DebugAdapter.dispatchRequest(DebugAdapter.java:88)\n\tat com.microsoft.java.debug.core.adapter.ProtocolServer.dispatchRequest(ProtocolServer.java:118)\n\tat com.microsoft.java.debug.core.protocol.AbstractProtocolServer.lambda$new$0(AbstractProtocolServer.java:78)\n\tat io.reactivex.internal.observers.LambdaObserver.onNext(LambdaObserver.java:60)\n\tat io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:200)\n\tat io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:252)\n\tat io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)\n\tat io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)\n\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\n\tat java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base/java.lang.Thread.run(Thread.java:829)\n"

{ "type": "java", "name": "runClient", "request": "launch", "mainClass": "net.minecraftforge.userdev.LaunchTesting", "projectName": "GregTech", "cwd": "${workspaceFolder}/run", "vmArgs": "-Dforge.logging.console.level=debug -Dforge.logging.markers=DEBUG -Dmixin.env.remapRefMap=true -Dmixin.env.refMapRemappingFile=/home/abbe/Dev/GregTech/build/createSrgToMcp/output.srg", "args": "-mixin.config=antimatter.mixins.json", "env": { "MOD_CLASSES": "gti%%/home/abbe/Dev/GregTech/bin/main:gti%%/home/abbe/Dev/GregTech/bin/main:antimatter%%/home/abbe/Dev/GregTech/AntimatterAPI/bin/main:antimatter%%/home/abbe/Dev/GregTech/AntimatterAPI/bin/main:tesseract%%/home/abbe/Dev/GregTech/AntimatterAPI/TesseractAPI/bin/main:tesseract%%/home/abbe/Dev/GregTech/AntimatterAPI/TesseractAPI/bin/main", "MCP_MAPPINGS": "snapshot_20210309-1.16.5", "MCP_VERSION": "20210115.111550", "FORGE_VERSION": "36.1.4", "assetIndex": "1.16", "assetDirectory": "/home/abbe/.gradle/caches/forge_gradle/assets", "nativesDirectory": "${workspaceFolder}/build/natives", "FORGE_GROUP": "net.minecraftforge", "target": "fmluserdevclient", "MC_VERSION": "1.16.5" } }

I mostly copied the launch config from vs code! It works just fine in VS code with jdtls.

Yes, I understand I copied most of it. I am simply trying to get it to work, and then simplify and remove unnecessary things or just rewrite completely!

mfussenegger commented 3 years ago
Missing mainClass or modulePaths/classPaths options in launch configuration

Looks like now the module paths / class paths are missing. If you remove dap.adapters.java from your configuration and instead rely on jdtls.setup_dap({ hotcodereplace = 'auto' }) it should setup an adapter definition that should be able to resolve these automatically.

Vliro commented 3 years ago

Thank you, that was indeed the issue! It now launches the program. Next up is breakpoints!

Vliro commented 3 years ago

Hi, I started using Java debug again and ran into some new issues. The base is Lunarvim with reconfigured java. Java ftplugin

-- if require("utils").check_lsp_client_active "jdt.ls" then
--   return
-- end
local status, jdtls = pcall(require,"jdtls")
if not status then
  return
end
local home = os.getenv('HOME')
local debug_path = "/Documents/Code/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar"
-- find_root looks for parent directories relative to the current buffer containing one of the given arguments.
if vim.fn.has "mac" == 1 then
  WORKSPACE_PATH = home .. "/workspace/"
elseif vim.fn.has "unix" == 1 then
  WORKSPACE_PATH = home .. "/workspace/"
else
  print "Unsupported system"
end

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

JAVA_LS_EXECUTABLE = home .. "/.local/share/lunarvim/lvim/utils/bin/jdtls"
require("jdtls").start_or_attach {
  on_attach = function (client, bufnr)
    require("lsp").common_on_attach(client, bufnr)
    jdtls.setup.add_commands()
    jdtls.setup_dap({ hotcodereplace = 'auto' })
  end,
  init_options = {
    bundles = {
      vim.fn.glob(home .. debug_path)
    };
  },
  flags = {
      allow_incremental_sync = true,
  };
  cmd = { JAVA_LS_EXECUTABLE, WORKSPACE_PATH .. vim.fn.fnamemodify(root_dir, ":p:h:t") },
  settings = {
    java = {
      signatureHelp = { enabled = true };
      contentProvider = { preferred = 'fernflower' };
      codeGeneration = {
              toString = {
                template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}"
              }
            };
    },
      configuration = {
        runtimes = {
          {
            name = "JavaSE-11",
            path = "/usr/lib/jvm/java-11-openjdk/",
          },
          {
            name = "JavaSE-15",
            path = "/usr/lib/jvm/java-15-openjdk/",
          },
        }
      };
  }
}

vim.api.nvim_set_keymap("n", "<leader>la", ":lua require('jdtls').code_action()<CR>", { noremap = true, silent = true })

vim.cmd "command! -buffer JdtCompile lua require('jdtls').compile()"
vim.cmd "command! -buffer JdtUpdateConfig lua require('jdtls').update_project_config()"
-- vim.cmd "command! -buffer JdtJol lua require('jdtls').jol()"
vim.cmd "command! -buffer JdtBytecode lua require('jdtls').javap()"
-- vim.cmd "command! -buffer JdtJshell lua require('jdtls').jshell()"

I use the provided vs code extension in nvim dap to load java launch configurations.


{
      "type": "java",
      "name": "runClient",
      "request": "launch",
      "mainClass": "net.minecraftforge.userdev.LaunchTesting",
      "projectName": "GT-4-Reimagined",
      "cwd": "${workspaceFolder}/run",
      "vmArgs": "-Dforge.logging.console.level\u003ddebug -Dforge.logging.markers\u003dDEBUG -Dmixin.env.remapRefMap\u003dtrue -Dmixin.env.refMapRemappingFile\u003d/home/albert/Documents/Code/GT-4-Reimagined/build/createSrgToMcp/output.srg",
      "args": "-mixin.config\u003dgt4r.mixins.json -mixin.config\u003dantimatter.mixins.json",
      "env": {
        "MOD_CLASSES": "gt4r%%/home/albert/Documents/Code/GT-4-Reimagined/bin/main:gt4r%%/home/albert/Documents/Code/GT-4-Reimagined/bin/main:antimatter%%/home/albert/Documents/Code/GT-4-Reimagined/AntimatterAPI/bin/main:antimatter%%/home/albert/Documents/Code/GT-4-Reimagined/AntimatterAPI/bin/main",
        "MCP_MAPPINGS": "snapshot_20210309-1.16.5",
        "MCP_VERSION": "20210115.111550",
        "FORGE_VERSION": "36.2.2",
        "assetIndex": "1.16",
        "assetDirectory": "/home/albert/.gradle/caches/forge_gradle/assets",
        "nativesDirectory": "${workspaceFolder}/build/natives",
        "FORGE_GROUP": "net.minecraftforge",
        "target": "fmluserdevclient",
        "MC_VERSION": "1.16.5"
      }
    },

Loaded with

  require('dap.ext.vscode').load_launchjs()

Also loaded manually rewriting JSON to lua. It launches occasionally but most of time it does not work.

Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-jdtls/lua/jdtls/dap.lua:42: attempt to index local 'paths' (a nil value)
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-jdtls/lua/jdtls/dap.lua:42: attempt to index local 'paths' (a nil value)
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-jdtls/lua/jdtls/dap.lua:42: attempt to index local 'paths' (a nil value)
Error executing vim.schedule lua callback: ...are/lunarvim/site/pack/packer/start/nvim-dap/lua/dap.lua:656: Adapter used with attach must have a port property
Error executing vim.schedule lua callback: ...are/lunarvim/site/pack/packer/start/nvim-dap/lua/dap.lua:656: Adapter used with attach must have a port property
Error executing vim.schedule lua callback: ...are/lunarvim/site/pack/packer/start/nvim-dap/lua/dap.lua:656: Adapter used with attach must have a port property
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:599: handle 0x560908df4470 is already closing
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:599: handle 0x560908df4470 is already closing
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:599: handle 0x560908df4470 is already closing
Debug adapter didn't respond. Either the adapter is slow (then wait and ignore this) or there is a problem with your adapter or `java` configuration. Check the logs for errors (:help dap.set_log_level)
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:599: handle 0x560908df4470 is already closing
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:599: handle 0x560908df4470 is already closing
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:599: handle 0x560908df4470 is already closing
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:599: handle 0x560908df4470 is already closing

This time it did launch but most of the time it doesn't work. Also the session cannot be closed in any way and nvim has to be restarted. Also, when it launches like this it doesn't properly close the session (callbacks for e.g. gui are not called). What could be the reason? The LSP itself works great. I recall mentioning the classpaths which are not set afaik in this case. If there is more information needed I will happily provide.

mfussenegger commented 3 years ago
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-jdtls/lua/jdtls/dap.lua:42: attempt to index local 'paths' (a nil value)
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-jdtls/lua/jdtls/dap.lua:42: attempt to index local 'paths' (a nil value)
Error executing vim.schedule lua callback: ...rvim/site/pack/packer/start/nvim-jdtls/lua/jdtls/dap.lua:42: attempt to index local 'paths' (a nil value)

The error here sounds like there is a problem with the debug adapter installation?

As far as I can tell, there shouldn't be a case where paths is nil, the server component always returns a result:

https://github.com/microsoft/java-debug/blob/66feca936e8dd0bfbb7f6af3c3f4c4ce9833a95e/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveClasspathsHandler.java#L198-L225

The issue with the handle 0x... is already closing should be fixed with https://github.com/mfussenegger/nvim-dap/pull/304 - I had this locally already for a while but had forgotten to push it.

Vliro commented 3 years ago

Hello again!

I'm using the on_attach callback, jdtls.setup_dap function. Which should setup the proper adapters. The bundled added to java debug is /home/albert/Documents/Code/java-debug/com.microsoft.java.debug.plugin/t arget/com.microsoft.java.debug.plugin-0.32.0.jar

which should be enough to enable debug. Other than this I am not sure what is required to setup the debug. Is the load_launchjs supported for java configs?

I'd bet the other errors(handle is already closing) etc. stems from the initial error which breaks the debug session, the "attempt to index local paths." My run configurations do not have classPath or modulePath in it as a table value.

mfussenegger commented 3 years ago

Do you have a branch in the project with the launch.json or so, so that I could try to reproduce it?

Vliro commented 3 years ago

Hi,

There is a Gradle task, ./gradlew genVSCodeRuns. The project can be cloned with its submodules, which should be enough.

https://github.com/Trinsdar/GT-4-Reimagined is the repo I was using at the time of testing.

mfussenegger commented 3 years ago

I get a build.gradle|1 col 1| Unresolved dependency: project AntimatterAPI error in that project. Looks like the dependencies are not setup correctly?

Vliro commented 2 years ago

Now it works for some reason, not changing anything. Thank you for your help.