Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I just cannot get this tool to work properly #3125

Open
Equiphract opened this issue Apr 3, 2024 · 5 comments
Open

I just cannot get this tool to work properly #3125

Equiphract opened this issue Apr 3, 2024 · 5 comments

Comments

@Equiphract
Copy link

I face the following issues when trying to get this language server up and running with Vim and vim-lsp:

  • No syntax errors are reported
  • Hover information works only the first time on a newly opened editor session
  • Go to definition does not work
  • Rename does not work
  • etc.

I have a test project set up with two simple classes:

package me.equiphract;

public class App {
    public static void main( String[] args ) {
        final var messageProvider = new MessageProvider();
        System.out.println( messageProvider.provideHello() );
    }
}
package me.equiphract;

final class MessageProvider {
    public String provideHello() {
        return "Hello, World!";
    }
}

The project's structure is as following:

.
├── pom.xml
└── src
    ├── main
    │   └── java
    │       └── me
    │           └── equiphract
    │               ├── App.java
    │               └── MessageProvider.java
    └── test
        └── java
            └── me
                └── equiphract
                    └── AppTest.java

Looking into the logs provided by vim-lsp I see quite a few weird things, such as MessageProvider is not on the classpath of project , only syntax errors are reported or the message server already started that is repeated multiple times. I am attaching a copy of a log file that was recorded while performing the following actions:

  1. Start a new Vim instance from the project's root directory
  2. Open App.java within a Vim buffer
  3. Wait for the language server to start, which is indicated to me by some of the code highlights changing
  4. Move cursor over the variable name messageProvider at its declaration and issue a rename
  5. Vim shows the following message: Failed to retrieve rename_prepare for eclipse.jdt.ls: j
  6. Move cursor over the method name println and issue a hover request to display some documentation for this symbol
  7. The method's signature is displayed in a pop up
  8. Move the cursor one line up and then down again to println and issue the same request as in step 6
  9. This time nothing happens and Vim displays the following message: *Retrieving hover...`
  10. Close Vim instance with :q!

I have been trying to get this language server to work for the last 4 days or so and I am starting contemplate to just use an IDE again... I am also attaching the portion of my .vimrc where I register the language server as there may be a configuration error. I am experiencing this behaviour on a 64-bit Gentoo Linux system.

    var equinox_launcher =
        '~/repos/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_1.6.800.v20240304-1850.jar'
    if executable('java') && filereadable(expand(equinox_launcher))
        autocmd User lsp_setup call lsp#register_server({
        \   'name': 'eclipse.jdt.ls',
        \   'cmd': [
        \       'java',
        \       '-Declipse.application=org.eclipse.jdt.ls.core.id1',
        \       '-Dosgi.bundles.defaultStartLevel=4',
        \       '-Declipse.product=org.eclipse.jdt.ls.core.product',
        \       '-Dlog.level=ALL',
        #\       '-noverify', <- deprecated
        \       '-Dfile.encoding=UTF-8',
        \       '-Xmx1G',
        \       '-jar',
        \       expand(equinox_launcher),
        \       '-configuration',
        \       expand('~/repos/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/config_linux'),
        \       '-data',
        \       getcwd()
        \   ],
        \   'whitelist': ['java'],
        \ })
    endif

vim_lsp_eclipsejdtls.log

@fbricon
Copy link
Contributor

fbricon commented Apr 3, 2024

I don't know anything about vim, but seems like there's a vim-lsp plugin that should do all the config for you https://github.com/mattn/vim-lsp-settings

@Equiphract
Copy link
Author

Equiphract commented Apr 4, 2024

I tried to stay away from that plugin since the idea of having a plugin to handle another plugin's configuration seemed odd to me. Nevertheless, I now installed it and tried it out - and disabled all my handwritten configuration - and still experience more or less the same behaviour which almost seems like a freezing of the language server's functionality after one request (one request sometimes works but after that none work). One major difference now is that I now get an App.java is a non-project file, only syntax errors are reported warning at the top of my file. That is something I have seen in the logs before and was wondering why. I was of the impression that this language server is able to recognise Maven projects,

@mfussenegger
Copy link
Contributor

Judging from the logs it can't load the problem properly:

jdt.ls-java-project does not exist\nJava Model Exception: Error in Java Model (code 969): jdt.ls-java-project does not exist\n\tat org.eclipse.jdt.internal.core.JavaElement.newJavaModelException(JavaElement.java:572)\n\tat org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:233)\n\tat org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:585)\n\tat org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:308)\n\tat org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:294)\n\tat org.eclipse.jdt.internal.core.JavaElement.getChildren(JavaElement.java:249)\n\tat org.eclipse.jdt.internal.core.JavaProject.getPackageFragmentRoots(JavaProject.java:2294)\n\tat org.eclipse.jdt.internal.core.JavaProject.getPackageFragments(JavaProject.java:2318)\n\tat org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.cleanupResources(ProjectsManager.java:345)\n\tat org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.initializeProjects(ProjectsManager.java:120)\n\tat org.eclipse.jdt.ls.core.internal.handlers.InitHandler$1.runInWorkspace(InitHandler.java:263)\n\tat org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)\n\tat org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)\n","type":1}}}]
Wed 03 Apr 2024 07:36:02 PM CEST:["<---",1,"eclipse.jdt.ls",{"response":{"method":"language/status","jsonrpc":"2.0","params":{"message":"jdt.ls-java-project does not exist","type":"Error"}}}]

I think this might be caused by setting -data to the project repository:

       \       '-data',
        \       getcwd()

Can you try using a location that's outside of it?

There should also be a .metadata/.log file within the data folder, which might give you additional pointers on what's wrong.

@Equiphract
Copy link
Author

Equiphract commented May 1, 2024

When using the vim-lsp-settings plugin, -data is set to /home/me/.local/share/vim-lsp-settings/servers/eclipse-jdt-ls/data and there is also a .metadata/.log present. However, I do not see anything interesting in there, but I will attach it here anyways:

metadata_log.txt

Maybe, grasping at straws here, the structure of the data directory gives you insight on what is happening, so I will attach it here too:

data_structure.txt

@allainpascal
Copy link

Hi there.

I've spent most of my morning configuring eclipse JDTLS with...

  • VIM 9.1
  • vim_lsp (latest at this date)

I had similar problems, but not quite the same though. The LSP was loading properly, I had my syntax highlight and the inline documentation, but most commands was throwing an error “no delegate command”. While looking for an explanation I found your post.

I’m not sure if this going to help in your particular case, but that’s, with my best intentions, an exhaustive steps I’ve taken to setup VIM, vim_lsp and JDTLS.

  • Get the latest JDTLS (https://download.eclipse.org/jdtls/milestones/1.40.0/)
  • Unzip it in a folder (let’s call it jdtls)
  • Put this directory somewhere accessible by the user(s) (~/Applications/jdtls)
  • Put the bin in your path (.bash_profile, .bashrc, whatever)
    • Test if it can run with $ jdtls

The magic sauce is in the lsp-java.vim, you have to "register" the JDTLS commands to send them properly to the lsp. Thanks to lsp-vim-settings there!

I hope this post will help you or anyone having this problem in the future.

That’s my lsp-java.vim to link everything together, change the paths for yours. I put my Java projects under ~/Projects/java_workspace. $JDT_HOME is where my jdtls folder is located.

I put the ‘data’ (.metadata) in that java_workspace folder too; since it’s the JDTLS metadata.

lsp-java.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants