redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 440 forks source link

Autocompletion doesn't work well within lambda expressions #2324

Open bitray opened 2 years ago

bitray commented 2 years ago

Issue Type: Bug

[Error - 7:12:19 PM] Feb 17, 2022, 7:12:19 PM Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".

java.lang.IllegalArgumentException: at org.eclipse.core.runtime.Assert.isLegal(Assert.java:66) at org.eclipse.core.runtime.Assert.isLegal(Assert.java:50) at org.eclipse.core.internal.jobs.JobManager.setRule(JobManager.java:1400) at org.eclipse.core.internal.jobs.InternalJob.setRule(InternalJob.java:486) at org.eclipse.core.runtime.jobs.Job.setRule(Job.java:771) at org.eclipse.jdt.ls.core.internal.handlers.BaseDocumentLifeCycleHandler.triggerValidation(BaseDocumentLifeCycleHandler.java:154) at org.eclipse.jdt.ls.core.internal.handlers.BaseDocumentLifeCycleHandler.triggerValidation(BaseDocumentLifeCycleHandler.java:138) at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceDiagnosticsHandler.visit(WorkspaceDiagnosticsHandler.java:180) at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:67) at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77) at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77) at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77) at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77) at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77) at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77) at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77) at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77) at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:77) at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:51) at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceDiagnosticsHandler.resourceChanged(WorkspaceDiagnosticsHandler.java:103) at org.eclipse.core.internal.events.NotificationManager$1.run(NotificationManager.java:305) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45) at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:295) at org.eclipse.core.internal.events.NotificationManager.broadcastChanges(NotificationManager.java:158) at org.eclipse.core.internal.resources.Workspace.broadcastPostChange(Workspace.java:381) at org.eclipse.core.internal.resources.Workspace.endOperation(Workspace.java:1503) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2327) at org.eclipse.core.internal.events.NotificationManager$NotifyJob.run(NotificationManager.java:44) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

Extension version: 1.3.0 VS Code version: Code 1.64.2 (f80445acd5a3dadef24aa209168452a3d97cc326, 2022-02-09T22:02:28.252Z) OS version: Windows_NT x64 10.0.19042 Restricted Mode: No

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz (8 x 2304)| |GPU Status|2d_canvas: unavailable_software
gpu_compositing: disabled_software
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: disabled_off
rasterization: disabled_software
skia_renderer: enabled_on
video_decode: disabled_software
vulkan: disabled_off
webgl: unavailable_software
webgl2: unavailable_software| |Load (avg)|undefined| |Memory (System)|31.73GB (16.09GB free)| |Process Argv|--disable-gpu --disable-gpu-compositing --log error| |Screen Reader|no| |VM|0%|
rgrunber commented 2 years ago

Are you able to provide a sample snippet of code (or even the project & file) on which the issue is reproducible ?

bitray commented 2 years ago

@rgrunber Hello, Rgrunber. seems the issue is no more coming up. At that time , all the auto completion operations are invalid . Hence I finished the code by feature of VScode editor. After that , seems everything recovers...

Hence , i can not provide sample snippet .. Sorry for that ...

But I found something about stream api. Auto-completion works fine when i type map() method. But it doesn't work if I didn't finish the code in {}.. It means I can not use . to complete collect(Collectors.toList()); section.. Errors can block auto-completion...Probably it is not issue , but a little strange, because it can work fine by using IDEA. List<XxDTO> returnList = data.stream().map(x -> { ResposeDTO element = new ResposeDTO (); return BeanUtil.fillBeanWithMap(x, element, false); }).collect(Collectors.toList());

rgrunber commented 2 years ago

I'm able to reproduce as well, even on upstream Eclipse, so this is a JDT Core problem. Completions dealing with lambdas not working under certain conditions are a known issue.

(cursor at | and error meant to be a non-existent token)

List<Integer> returnList = Arrays.asList(1, 2, 3, 4, 5)
                .stream().map(t -> {
                    return error;
                }).|

Completion fails to be triggered.

My guess is the completion relies on being able to resolve the signature of the lambda, which likely breaks completion when the body has compilation errors.

rgrunber commented 2 years ago

Looking through :

https://stackoverflow.com/questions/33305414/eclipse-java-8-auto-completion-for-lambda-expressions https://bugs.eclipse.org/bugs/show_bug.cgi?id=460921 https://bugs.eclipse.org/bugs/show_bug.cgi?id=551391 https://bugs.eclipse.org/bugs/show_bug.cgi?id=561100

this appears to be a common issue with lambdas.

juhaku commented 1 year ago

I can also confirm the issue arises within lambda bodies that cannot match to the required method signature immediately. Like Java Consumer does work ok, however Supplier or Function at the other hand does not. See the details here: https://github.com/eclipse/eclipse.jdt.ls/issues/2237#issuecomment-1438751532