-
-
Notifications
You must be signed in to change notification settings - Fork 961
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
eclipse.jdt.ls support #112
Comments
I've added the support for send request to custom language client, it could be done by something like: au BufReadCmd,FileReadCmd,SourceCmd jdt://* call LoadJavaContent(expand("<amatch>"))
function! LoadJavaContent(uri)
setfiletype java
let content = CocRequest('java', 'java/classFileContents', {'uri': a:uri})
call setline(1, split(content, "\n"))
setl nomod
setl readonly
endfunction |
You can create a
I've looked at the code of vscode-java, it should be easy to convert it to coc extension. |
I wasn't able to get the snippet running, but I have an idea why it isn't working. It seems, that coc.nvim removes the protocol and the query string from the URI. So instead of:
The buffer opens with:
I tried to account for the missing protocol prefix by slightly modifying the snippet: function! LoadJavaContent(uri)
setfiletype java
let content = CocRequest('java', 'java/classFileContents', {'uri': 'jdt:/' . a:uri})
call setline(1, split(content, "\n"))
setl nomod
setl readonly
endfunction
autocmd! BufReadPre,BufReadCmd,FileReadCmd,SourceCmd *.class call LoadJavaContent(expand("<amatch>"))<CR> But all this did, was open a buffer, that only contained |
It's a bug with jump to location which has custom shcema. |
You mean |
Yes, it should works, you need to rebuild coc.nvim by |
That did it. I did some testing and everything looks fine. Your original snippet works without any additional changes now. Thanks! |
I found another java related issue. I get the following error message after selecting a code action ("coc-codeaction"):
|
I've looked at the code of vsocde-java, that command have to be registered on client side. |
It seems, that coc.nvim is in good company: eclipse-jdtls/eclipse.jdt.ls#376. LanguageClient-neovim had to implement a workaround as well. |
There is https://github.com/neoclide/coc-java extension now, which support configuration, commands and snippets. |
Awesome work! I did some initial testing and noticed two issues:
|
|
I've improved the root logic to support root patterns same as vim rooter. |
I can confirm, that jdt-URIs now work. Will you include the snippet in coc.nvim? I deactivated
|
No, but I will make coc expose API for extension to handle custom schema of uri just like VSCode.
No need to deactivated vim-rooter, it looks like you're using binary version of coc, to make sure use the javascript code build by |
I rechecked everything. I'm pretty sure, that I'm using the source version. I can create a minimal nvim config and a java test project, if you want? |
I think I've got the reason that the rootPath could be wrong, the extension could be activited on filetype change when the buffer is not loaded, so root can't be resolved from current buffer. I don't get the problem because my java home is resolved from system and it takes more time. |
Is there anything I can help with? |
I've fixed the issue, it should works now. |
I can confirm that. I went ahead and tested the example vim config from top to bottom. I found only one remaining issue. It seems I also checked the
I don't know if this issue is actually related to the |
It's a internal command, so it should not invoked directly.
For the same file and same location? I've checked goto implementation and the server returns empty location list. |
The argument for goto implementations send to server is wrong, I just fixed that, I've tested it working now. |
Ok, that now works as well. I continued testing and noticed, that Code Actions sometimes throw errors: Example: Executing an "import" code action on import java.util.ArrayList;
import java.util.List;
@Entity
public class TestClass { to this: import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity
@Entity
public class TestClass { But instead the error message is being displayed. |
There's a bug with |
Fixed in 0.0.28. Latest coc-java could handle jdt uri itself, the autocmd for FileReadCmd no longer required. |
Possible caused by slow of content synchronize, Try change
Looks like that VSCode is giving higher priority to variable items, but coc simply use fuzzaldrin for sort items. It could be improved. |
I tried it with four different values: 180, 300, 600, 1000. Up to 300 the issue persisted and after 600 I got no completions at all.
It would already help, if fuzzaldrin would favour case sensitive matches. There already is an issue for this, but nobody touched it for over three years. Is it actually necessary to sort the completion list? Could it be, that the extension already returns a properly sorted list? It seems, that vscode also includes the proximity of all symbols into the scoring. Otherwise |
Indeed, it is much better now.
It didn't fix the issue for me. I did some further testing and noticed, that I get different results for different variable names: I used the official aws java sample for this test. |
I've changed the completion to trigger rather than filter the text on increment filter, it should works as expected now. |
I found another issue. The package name completion creates invalid values: I guess this is actually an issue in eclipse.jdt.ls, since LanguageClient-neovim has the same problems. I think jdt should only return partial results. @chemzqm can you confirm this? Other than that everything works very well! |
There's a trick on VSCode, it won't trigger completion if it found strict match on first complete item. Coc could do the same. |
I've implemented that on master branch. |
I checked out master, but it didn't fix the issue for me.
I don't think, that this explains the issue. Every item on the completion list shows the same erroneous behavior. They always show the complete package path and should completely replace the first symbol:
Possible solutions:
|
It fixed the issue when you type I've got the reason, the language server return textEdit and change the complete item to snippet kind on complete resolve, so VSCode just use the textEdit, you can do the same in coc by just confirm the completion with |
I've fixed the position of module import at neoclide/coc-java@8ce7341. Master of coc.nvim and latest coc-java required. |
That works! I've got no more complaints. |
Thanks a lot for this feature, it's exactly what I've been looking for for ages! Also loving coc.nvim so far. I've been playing around with this and have a dumb question: how do you add on import to a class? I typed:
Then I should do something on top of After code completion, this is the second most used thing in Java development so surely there must be a way to do this with eclipse.jdt.ls? Came up pretty much empty when googling as there's only "Organize imports" (What exactly do I need to do to call that via coc.nvim?), which to me seems like it does stuff for the whole file and can't possibly select the right |
@ttiurani I think you are searching for Excerpt: " Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
vmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap for do codeAction of current line
nmap <leader>ac <Plug>(coc-codeaction) |
@tbo thanks! I got the bottom one, I'm just so very bad with vimscript that I can't figure out what exactly I'm suppossed to press to invoke those upper ones for a single word. If I have the cursor on top that |
You can't invoke
to your In normal mode, select the word by |
Thanks, now it works! My problem was that I thought about being clever and using |
|
@tbo @chemzqm First of all - thank you for working so hard on this, it is the easiest and most performant solution for java in nvim. Second - I am having trouble with the language server finding generated sources. Previously I compiled eclipse.jdt.ls myself and used the standard set-up with LanguageServer-neovim. When set up that way, it discovered generated sources in my project just fine. I don't have any configurations set in my CoCConfig right now, is there something I am missing that is needed for generated sources to be found in my multi-module maven project? |
I have done further debugging and thinking on this issue. I don't believe it is a generated sources problem since the sources that are not being found are compiled into a JAR and placed in my local .m2 directory. I am then referencing that dependency in my other module. It is almost like the Language server can't see my local .m2 repo - but then all of my other dependencies should be failing too. I'm not sure at this point what's happening. I have set the configuration to use my local maven settings.xml. Perhaps does the Eclipse language server use it's own .m2 location? |
I think eclipse.jdt.ls use |
It it possible to add those source code folders as params of command that start eclipse.jdt.ls? |
@danmikita The support for eclipse-jdtls/eclipse.jdt.ls#849 Maybe it is working with LanguageServer-neovim, because you used the latest development version? A recent comment from one of the core developers indicates, that |
@tbo Sure enough! I checked out master 12 days ago which had the commit for that feature. So - it looks like that feature was released in version 0.28.0 just a few days ago. Is there a way to point coc-java to use that new tag? |
No, coc-java bundled with release of eclipse.jdt.ls. I can add an option to coc-java for custom server home. |
coc-java 1.1.6 added |
Wow - you work fast! I tried to get it working, but am getting an error while trying to start the server. These are the steps I took:
I haven't dug into your code at all - so I admit this is the lazy approach... But when using LanguageClient-neovim I needed to use a small bash script to start the server.
Here I had to set several arguments and even reference a specific configuration file. My open questions:
Thank you guys again for helping! This is already amazing! This is the only missing piece for me. |
If you can add
The directory should be correct, it contains |
Okay - I'm about to leave for the day, so this is my last update. I tried various permutations and couldn't get my locally compiled server to start up with your change. So I decided to revert back to no settings at all so I could get some work done. :) Unfortunately, the default server will no longer start. I am now getting a Not sure what to do at this point - if I don't hear back, I'll poke around again for a bit tomorrow. Thanks again for your help! |
Quick update: https://github.com/eclipse/eclipse.jdt.ls/blame/master/README.md#L29 Unfortunately, the maven settings is still not working...but I'm sure we'll get there. Thanks again for your help! |
I've been testing eclipse.jdt.ls to add support for Java. Most things work pretty well. The only major feature, that doesn't work is the resolution of external dependencies. eclipse.jdt.ls represents external resources by prefixing them with
jdt://
. Example:In order to resolve those URIs, eclipse.jdt.ls provides an additional LSP-Method:
java/classFileContents
. See here to get a complete list of eclipse.jdt.ls' LSP extensions.Possible Solutions
Add a handler for
jdt://
-URIs, that passes them tojava/classFileContents
and show the response in a new readonly buffer. It could look like this:Keep in mind, that jdt buffers are still valid java files, which can contain additional references.
Most LSP-Clients use this approach:
jdt://...
not supported autozimu/LanguageClient-neovim#392- OR -
Integrate vscode-java.
My Configuration
coc-settings.json:
Without declaring the
classFileContentsSupport
eclipse.jdt.ls won't send jdt references.My launcher (
javalsp
):You'll have to update the settings depending on your own system. I would have put everything into the
coc-settings.file
, but I didn't know how to change into the directory of the language server before the command execution.BTW: vscode-java already includes the installation of the LSP server.
The text was updated successfully, but these errors were encountered: