You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Code completion shortcut not working in if statement nested in for loop #2672
Well how would you describe the situation I posted? Looks like a nested foreach loop to me. Please edit the title to what you believe it should be called.
@hasen6 The exact project would be ideal. If not, would it be possible to activate the command palette (eg. ctrl+shift+p) and launch the Java: Open All Log Files command after you have reproduced the problem. I would post the .log file or at least any errors you see in there.
The exact project would be ideal. If not, would it be possible to activate the command palette (eg. ctrl+shift+p) and launch the Java: Open All Log Files command after you have reproduced the problem. I would post the .log file or at least any errors you see in there.
I can't share the project unfortunately since it's a large multiple file game engine. I've actually since changed that method and the error no longer reproduces anywhere in the new version of that method. However I have a backup of how the code was previously and the error reproduces just as before inside that code, it seems the circumstances have to be quite specific for the error to occur. It's not as simple as an 'if statement in a for loop', but I don't know how else to describe it. Unfortunately the log files have nothing. I don't think vscode considers it to be an error but it reproduces every time in those conditions, it's not something failing as a one off.
I'm trying to put together some kind of simple project that would reproduce the error.
I think the moment you're able to reproduce, check the .log file as I described above. If there's a stacktrace, then maybe we can address it without a code snippet, or even work backwards to figure out what kind of snippets trigger this.
I think the moment you're able to reproduce, check the .log file as I described above. If there's a stacktrace, then maybe we can address it without a code snippet, or even work backwards to figure out what kind of snippets trigger this.
I opened vscode in terminal with code --log trace and after typing sout and seeing the error, as far as I can see there was nothing written to the main.log, it's really just not seeing it as any kind of error. But I do have a minimal project where I can recreate the error every single time. Let me know where I can send that to.
I opened vscode in terminal with code --log trace and after typing sout and seeing the error, as far as I can see there was nothing written to the main.log, it's really just not seeing it as any kind of error. But I do have a minimal project where I can recreate the error every single time. Let me know where I can send that to.
Not sure if the main.log would show these errors. They would only be logged to the language server's logs (The .log file from Java : Open All Log Files command). The Language Server For Java tab within the Output View might also have any errors.
Are you able to attach the project to a comment (drag & drop into reply box) ?
Not sure if the main.log would show these errors. They would only be logged to the language server's logs (The .log file from Java : Open All Log Files command). The Language Server For Java tab within the Output View might also have any errors.
Ok I thought you were referring to the main.log when you said .log file. Anyway you can check the project yourself, it will be simpler.
Are you able to attach the project to a comment (drag & drop into reply box) ?
Ok I'll try, I thought it was only images that could be dropped but it looks like it's added. The project will show up with a lot of red underlined errors because everything is missing but I noticed it doesn't matter, you should be able to still run shortcut snippets like 'sout' for the System.out.println(); though. Check the TileDB.java file and type a snippet exactly where I was typing it in the screenshots.
Thanks for the project. I'm able to reproduce with a much simpler example now :
Test.java
package org.example;
public class Test {
private boolean removed;
public void test(Object input) {
if (true) {
sout|
((Test)input).removed = true;
}
}
}
Thanks for the project. I'm able to reproduce with a much simpler example now
I'm glad you were able to reproduce it, it's certainly an elusive bug, if you change almost anything to my example project's function, the bug no longer occurs, it was quite a miracle I even came across it in the first place. I've been working on projects in java every day since I reported the bug and literally never came across it again even once. I guess it has to be fixed nonetheless though.
I don't think there's a bug for this upstream, but this seems to be in the category of the parser recovering tokens in an unexpected way. I think I see what's happening, and it makes this bug look not entirely wrong.
sout|
((Test)input).removed = true;
is parsed (recovered) as
sout((Test)input).removed = true;
In other words, sout : Test -> Test, so it could be interpreted as completion being triggered within a statement, and not at the start. I could still file this upstream and see if anything could be done.
Activity
Eskibear commentedon Sep 13, 2022
At least not due to this,
hasen6 commentedon Sep 14, 2022
Well how would you describe the situation I posted? Looks like a nested foreach loop to me. Please edit the title to what you believe it should be called.
snjeza commentedon Sep 16, 2022
@hasen6 Could you provide a project example reproducing the error?
rgrunber commentedon Sep 16, 2022
@hasen6 The exact project would be ideal. If not, would it be possible to activate the command palette (eg.
ctrl+shift+p) and launch theJava: Open All Log Filescommand after you have reproduced the problem. I would post the.logfile or at least any errors you see in there.Snippet completions are one of the last collected so maybe something failed before and they never got collected ? Looking at https://github.com/eclipse/eclipse.jdt.ls/blob/dbd035c6aa036b6ee7dd7ea503de548f33fe641c/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CompletionHandler.java#L162-L175 nothing stands out as obvious since I wouldn't think this is a cancellation issue.
hasen6 commentedon Sep 17, 2022
@rgrunber
I can't share the project unfortunately since it's a large multiple file game engine. I've actually since changed that method and the error no longer reproduces anywhere in the new version of that method. However I have a backup of how the code was previously and the error reproduces just as before inside that code, it seems the circumstances have to be quite specific for the error to occur. It's not as simple as an 'if statement in a for loop', but I don't know how else to describe it. Unfortunately the log files have nothing. I don't think vscode considers it to be an error but it reproduces every time in those conditions, it's not something failing as a one off.
I'm trying to put together some kind of simple project that would reproduce the error.
hasen6 commentedon Sep 17, 2022
This is weird too, it's successful if there's an error above it:
Fails:
Succeeds
rgrunber commentedon Sep 19, 2022
I think the moment you're able to reproduce, check the
.logfile as I described above. If there's a stacktrace, then maybe we can address it without a code snippet, or even work backwards to figure out what kind of snippets trigger this.Another possibility is that something in here is just failing : https://github.com/eclipse/eclipse.jdt.ls/blob/dbd035c6aa036b6ee7dd7ea503de548f33fe641c/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/SnippetCompletionProposal.java#L218-L239 .
hasen6 commentedon Sep 20, 2022
I opened vscode in terminal with
code --log traceand after typingsoutand seeing the error, as far as I can see there was nothing written to themain.log, it's really just not seeing it as any kind of error. But I do have a minimal project where I can recreate the error every single time. Let me know where I can send that to.rgrunber commentedon Sep 20, 2022
Not sure if the
main.logwould show these errors. They would only be logged to the language server's logs (The.logfile fromJava : Open All Log Filescommand). TheLanguage Server For Javatab within the Output View might also have any errors.Are you able to attach the project to a comment (drag & drop into reply box) ?
hasen6 commentedon Sep 20, 2022
Ok I thought you were referring to the main.log when you said .log file. Anyway you can check the project yourself, it will be simpler.
Ok I'll try, I thought it was only images that could be dropped but it looks like it's added. The project will show up with a lot of red underlined errors because everything is missing but I noticed it doesn't matter, you should be able to still run shortcut snippets like 'sout' for the
System.out.println();though. Check theTileDB.javafile and type a snippet exactly where I was typing it in the screenshots.spacerogue 2.zip
rgrunber commentedon Sep 20, 2022
Thanks for the project. I'm able to reproduce with a much simpler example now :
Test.java
The problem happens at https://github.com/eclipse/eclipse.jdt.ls/blob/dbd035c6aa036b6ee7dd7ea503de548f33fe641c/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/SnippetCompletionProposal.java#L231 . The
tokenLocationis not recognized as aTL_STATEMENT_START(used to avoid suggesting snippets everywhere) but aTOKEN_KIND_UNKNOWNSeems to me like a fix would belong in https://github.com/eclipse-jdt/eclipse.jdt.core/blob/fa7970e436a20d3526755326eafdb8bb6b8c6e01/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java#L1897
fbricon commentedon Sep 21, 2022
@rgrunber indeed the bug can be reproduced in upstream Eclipse. Is there a bug report to point to?
hasen6 commentedon Sep 21, 2022
I'm glad you were able to reproduce it, it's certainly an elusive bug, if you change almost anything to my example project's function, the bug no longer occurs, it was quite a miracle I even came across it in the first place. I've been working on projects in java every day since I reported the bug and literally never came across it again even once. I guess it has to be fixed nonetheless though.
rgrunber commentedon Sep 22, 2022
I don't think there's a bug for this upstream, but this seems to be in the category of the parser recovering tokens in an unexpected way. I think I see what's happening, and it makes this bug look not entirely wrong.
is parsed (recovered) as
sout((Test)input).removed = true;In other words,
sout : Test -> Test, so it could be interpreted as completion being triggered within a statement, and not at the start. I could still file this upstream and see if anything could be done.hasen6 commentedon Oct 11, 2022
@rgrunber It's pretty rare to come across but I just came across it again in another situation so I guess it wasn't fixed.
fbricon commentedon Feb 11, 2026
I found a similar bug report upstream: eclipse-jdt/eclipse.jdt.core#2692