0

I'm working up a Neovim-based IDE for Java anchored around a SpaceVim installation. It's taken quite a journey to get everything configured appropriately but I'm almost there. The JDTLS language server is configured and working. When I open a java file, I get all the expected goodies including live autocomplete and syntax checking.

My current problem has to do with the debugger. SpaceVim has the "debug" layer enabled and I'd like to use "vimspector" as the debug plugin so that's been configured in ~/.SpaceVim.d/init.toml. I've run :VimspectorInstall vscode-java-debug from within Neovim and it appears to have installed the specified gadget correctly. I have a Java application I'm using for testing created with Apache Maven as follows:

mvn archetype:generate  -DgroupId=my.test.app \
 -DartifactId=hello \
 -DarchetypeArtifactId=maven-archetype-quickstart \
 -DinteractiveMode=false

In the root of that application directory I have the following .vimspector.json file:

{
  "configurations": {
    "Java Attach": {
      "adapter": "vscode-java",
      "filetypes": [ "java" ],
      "configuration": {
        "request": "attach",
        "hostName": "localhost",
        "port": "${port}",
        "sourcePaths": [
          "${workspaceRoot}/src/main/java",
          "${workspaceRoot}/src/test/java"
        ]
      }
    }
  }
}

With a java source file open, trying to launch the debugger ([SPC] d c), I'm prompted for a port number. This is logical since I didn't specify one in the config file above. And here is where I'm stuck. Somehow, based on my configuration, nvim "knows" how to communicate with the jdtls server whenever a java file is loaded, for the purposes of syntax and formatting. I know that's working because if it weren't I wouldn't get the live syntax checking etc. But Vimspector doesn't seem to be able to do the same natively. I suspect it has something to do with the .vimspector.json file above, which is probably not quite right for my installation. Assuming it's a port issue, I can see what port it's listening on with a netstat -lnt. But the port number changes every time. Furthermore, while looking it up and keying it in does allow the debugger to launch, there are errors. So I'm missing something somewhere. Any direction toward a working solution is much appreciated.

1
  • JDTLS supports specifying a port via a command-line option (-DCLIENT_PORT=...), or by setting an environment variable of the same name. If I do that, jdtls throws errors. I've tried both an environment variable and command line options via the ~/.SpaceVim.d/init.toml file. My thought was specifying a fixed port and adding it to the config file above might do the trick. Commented Oct 22, 2024 at 20:08

1 Answer 1

2

Well I finally figured it out. Here's what I was missing:

Here's what my Init.toml file looks like:

# All SpaceVim option below [option] section
[options]
    # set spacevim theme. by default colorscheme layer is not loaded,
    # if you want to use more colorscheme, please load the colorscheme
    # layer
    colorscheme = "gruvbox"
    colorscheme_bg = "dark"
    # Disable guicolors in basic mode, many terminal do not support 24bit
    # true colors
    enable_guicolors = true
    # Disable statusline separator, if you want to use other value, please
    # install nerd fonts
    statusline_separator = "arrow"
    statusline_iseparator = "arrow"
    buffer_index_type = 4
    enable_tabline_filetype_icon = true
    enable_statusline_mode = false
    bootstrap_before = 'myspacevim#before'
    bootstrap_after = 'myspacevim#after'
    filetree_direction = "left"

# Enable autocomplete layer
[[layers]]
    name = 'autocomplete'
    auto_completion_return_key_behavior = "complete"
    auto_completion_tab_key_behavior = "smart"

[[layers]]
    name = 'shell'
    default_position = 'top'
    default_height = 30

[[layers]]
    name = "telescope"

[[layers]]
    name = 'git'

[[layers]]
    name = 'VersionControl'

[[layers]]
    name = "lang#java"
    format_on_save = true
    java_formatter_jar = '/home/user/downloads/google-java-format/core/target/google-java-format-HEAD-SNAPSHOT-all-deps.jar'

[[layers]]
    name = 'lsp'
    enable_clients = ['jdtls', 'clangd']
    [layers.override_client_cmds]
        # jdtls = ["jdtls", "-configuration", "/home/user/.cache/jdtls/config", "-data", "/home/user/.cache/jdtls/workspace", "-D", "CLIENT_PORT=50000"]
        jdtls = ["jdtls", "-configuration", "/home/user/.cache/jdtls/config", "-data", "/home/user/.cache/jdtls/workspace"]

[[layers]]
    name = 'debug'
    debugger_plugin = "vimspector"

###########################################################
# Custom Plugins
###########################################################
[[custom_plugins]]
    repo = "https://github.com/microsoft/java-debug.git"
    merged = 0

[[custom_plugins]]
    repo = "https://github.com/neoclide/coc.nvim"
    merged = 0

Additionally, I needed to install two extensions for coc.nvim:

  • coc-java
  • coc-java-debug

Once I'd done that, it basically just worked. I've glossed over a lot of little details, but they're in the documentation. If this is immediately useful to anyone, and you'd like those details here. Ask for them in a comment and I'll add the specific steps to this answer next week.

Sign up to request clarification or add additional context in comments.

1 Comment

In the interest of documentation, here's a video/tutorial of someone who accomplished all of this from scratch without leveraging SpaceVim. It represents an order of magnitude more work, but is a useful reference nonetheless. youtube.com/watch?v=zbpF3te0M3g

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.