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

main, pscm, ctor and method snippets not working #3466

Closed
viljanvr opened this issue Jan 16, 2024 · 9 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#3026
Closed

main, pscm, ctor and method snippets not working #3466

viljanvr opened this issue Jan 16, 2024 · 9 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#3026
Assignees

Comments

@viljanvr
Copy link

viljanvr commented Jan 16, 2024

The following snippets are not working: main, pscm, ctor and method. In other words, when writing the prefixes nothing appears. These are all snippets used outside method bodies, so maybe it has something to do with that. The rest of the snippets (such as if, new, etc.) work without a problem.

The problem persists after all other extensions except Language Support for Java have been disabled.

Environment
  • Operating System: macOS 14.0
  • JDK version: 21.0.1
  • Visual Studio Code version: 1.85.1
  • Java extension version: 1.26.0
@rgrunber
Copy link
Member

Do you have an example of a piece of code where the snippets don't work ? Those snippets are context aware, so they would not appear if used outside of a type declaration. (eg. #3422 (comment) )

@viljanvr
Copy link
Author

viljanvr commented Jan 17, 2024

Example where the ctor, main and method-snippets doesn't work, but the different if-snippets work:

example1


I also discovered that the snippets work for a brief second while reloading the project using "Clean Java Language Server Workspace" from the command palette. First time writing ctor the snippet appears (this is while it's still loading), however when the reloading finishes it stops working again (second time writing ctor):

example2

I can also add that out of every person I asked, all 5 or 6 had the exact same problem on their own computers.

@rgrunber
Copy link
Member

Would you be able to share the project ? It definitely looks like a bug, but nothing from the gif immediately stands out as odd.

You might see the snippets briefly at the beginning because they're coming from https://github.com/redhat-developer/vscode-java/blob/master/snippets/server.json . However, once the language server is fully loaded we disable those because the language server should provide context information to enable them more selectively (ie. not when creating them would clearly be invalid).

@rgrunber rgrunber added the bug label Jan 17, 2024
@viljanvr
Copy link
Author

Here is a stripped down version of the project where the issue still persists: https://github.com/viljanvr/Java-Example-Project

@rgrunber
Copy link
Member

Thanks. I can reproduce. Can you confirm that it works if you remove the module-info.java file ?

completionToken evalutes to null within the "member" area of a type declaration, but it works just fine outsie of the type declaration, or even within a a statement block. Unfortunately the place it fails is the only place those snippets are meant to show up 😛 .

https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/8f0f822a89bf1f6109a9d95d048e7b53110df19f/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/SnippetCompletionProposal.java#L290-L293

This is looking like an upstream bug. Similar to https://bugs.eclipse.org/bugs/show_bug.cgi?id=242286 but I haven't been able to find anything more recent.

@viljanvr
Copy link
Author

Yes, can confirm it works after module-info.java file is removed.

@rgrunber
Copy link
Member

We spent so much time wondering what the completion context was doing we never asked ourselves how the completion context was doing. 😜

I kept thinking about needing to fix the fact that the completion context lacked the necessary token data, but looking at the actual code, I don't think the data is used at all, which means we should be able to supply some empty value, and allow the generic snippets to be computed without returning an empty list.

rgrunber added a commit to rgrunber/eclipse.jdt.ls that referenced this issue Jan 22, 2024
rgrunber added a commit to eclipse-jdtls/eclipse.jdt.ls that referenced this issue Jan 23, 2024
@rgrunber
Copy link
Member

@viljanvr the newest pre-release (v1.27.2024012308) should resolve this issue. Can you confirm that's the case ?

@rgrunber rgrunber added this to the End January 2024 milestone Jan 23, 2024
@rgrunber rgrunber self-assigned this Jan 23, 2024
@viljanvr
Copy link
Author

Can confirm the pre-release fixes the bug. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants