eclipse-jdtls / eclipse.jdt.ls

Java language server
1.75k stars 391 forks source link

No completion on chain method invocations in if condition #2530

Open gayanper opened 1 year ago

gayanper commented 1 year ago
package com.example.demo;

import org.springframework.boot.context.event.ApplicationContextInitializedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextStoppedEvent;
import org.springframework.core.env.Profiles;

public class Listener implements ApplicationListener<ApplicationEvent> {

  @Override
  public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationContextInitializedEvent e) {
      if(e.getApplicationContext().) {

      }
    } else {

    }
  }

}

if I tried to invoke completions e.getApplicationContext(). I don't get any completions, but if I do try to complete at e.getApplicationContext().getBeanFactory(). I get completions. And also if I do e.getApplicationContext().getBean|Factory() at the | char location I get completions. And finally if I remove the if block like

 if(e.getApplicationContext().)

I get completions.

Also if I have something like follows

  @Override
  public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationContextInitializedEvent e) {
      if(e.getApplicationContext().) 

      if(e.getApplicationContext() != null) {

      } 

    } else {

    }
  }

I don't get completions.

I do see this error though

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    at com.microsoft.jdtls.intellicode.core.pythia.PythiaCompletionContext.getCandidatesFromModel(PythiaCompletionContext.java:226)
    at com.microsoft.jdtls.intellicode.core.pythia.PythiaCompetionRanker.getScores(PythiaCompetionRanker.java:74)
    at com.microsoft.jdtls.intellicode.core.pythia.PythiaCompetionRanker.getRankings(PythiaCompetionRanker.java:35)
    at com.microsoft.jdtls.intellicode.core.ModelBasedRankingProvider.rank(ModelBasedRankingProvider.java:54)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.getAggregatedRankingResult(CompletionProposalRequestor.java:304)

Disabling the IntelliCode extension works.

vscode-java: v1.15.0 and pre-relase Java Version: 17

Eskibear commented 1 year ago

Looks like the same issue as https://github.com/redhat-developer/vscode-java/issues/2966#issuecomment-1455524161

Eskibear commented 1 year ago

@gayanper The issue has been fixed in intellicode and will be included in their next release. Can you also help to verify it on your side?

gayanper commented 1 year ago

Don't we have a pre-release version of this extension so that I don't need to download files which i would like to avoid given todays internet and change extension descriptor ?

Eskibear commented 1 year ago

No, it's owned by another team and pre-release is not enabled for the extension. Never mind, it's a trivial fix and I already verified it.