coc-java icon indicating copy to clipboard operation
coc-java copied to clipboard

Language server autocompletion doesn't appear to be working in new files

Open cpolish opened this issue 4 years ago • 5 comments

Hi there,

At the moment I am looking to learn Java soon and hence trying to set up a Java autocomplete/suggestion setup in Vim with coc.nvim/coc-java in macOS Big Sur with openjdk16 installed through MacPorts. I have been encountering a slight issue in regards to autocompletion triggering for new files through vim, i.e. executing vim test.java, where it seems that autcompletion doesn't work.

What is odd is that there doesn't seem to be any errors shown by Vim when this is happening, it seems that the language server is running, yet the autocomplete doesn't kick in when I begin typing, as it would if i was to do so in something like vim test.c or vim test.py. With "java.trace.server": "verbose" being set in my coc-settings.json file, doing :CocCommand workspace.showOutput java appears to show that when I create and open a new file in Vim, it gets stuck on Building when doing a 'language/progressReport, which is referenced numerous times within the log. I haven't been able to notice any explicit errors when doing :CocCommand java.open.serverLog (there was one time where it did show a FileNotFoundException, but I haven't been able to replicate this.

Other things I've tried to do:

  • Place "java.home": "/Library/Java/JavaVirtualMachines/openjdk16/Contents/Home", "java.enabled": true, "java.completion.enabled": true in my coc-settings.json file
  • Download and manually place the compiled jdt.ls files from Eclipse's website into ~/.config/coc/extensions/coc-java-data/server
  • Run:CocCommand java.clean.workspace

All the above don't appear to change the behaviour I am experiencing, with the exception of the java.clean.workspace command - when this is run, it seems to get stuck on 'starting coc.nvim service'.

I'm sorry if I've potentially overlooked anything, I'm still rather new to Java and coc.nvim! Would love to hear if anyone else has similar behaviour or might now a solution.

Thanks so much!

cpolish avatar Jun 30 '21 14:06 cpolish

Hello @cpolish! I'm experiencing the same problem with coc-java. Just configured my neovim with it in Manjaro Linux and when I open a new .java file the autocompletion simply doesn't work, but when I save it and open it again it suddenly starts working haha. By any chances, have you found any solution for this? It isn't a big problem but I'd like to have the convinience to have autocompletion when I open a file in nvim.

Best regards!

PS: I've found a similar issue that says something about setting a PATH variable. Going to test this as soon as I understand what is this problem lol

pserey avatar Jul 11 '21 01:07 pserey

It's language server issue since VSCode create new file on the disk before open it, but vim create a buffer only.

chemzqm avatar Jul 13 '21 12:07 chemzqm

Ohh, I get that. So, for now the only solution is to create the file first, right?

pserey avatar Jul 15 '21 12:07 pserey

You can restart coc.nvim by :CocRestart after save the file.

chemzqm avatar Jul 15 '21 12:07 chemzqm

Nice, I'll make it an autocommand for every .java file. Thanks!

pserey avatar Jul 15 '21 13:07 pserey

Simply use :e to reload the buffer after saved to file.

chemzqm avatar Jan 29 '23 07:01 chemzqm