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

Content assist does not activate, inside if() within a switch #1953

Merged
merged 3 commits into from
Mar 14, 2024

Conversation

stephan-herrmann
Copy link
Contributor

fixes #1561

Simpler approach, using new tests from #1625

@gayanper I tried to explain with minimal code comments. LMK if this is sufficient to understand the approach.

This change is not quite complete yet:

  • no explanation for changed relevance in three tests
  • may need to cover more control statements: only implemented for those that are covered by tests from #1625

@gayanper
Copy link
Contributor

gayanper commented Feb 7, 2024

@stephan-herrmann This approach is much elegant. I think we should go ahead with this.

@stephan-herrmann
Copy link
Contributor Author

@stephan-herrmann This approach is much elegant. I think we should go ahead with this.

Thanks.

Would you care to resolve the TODOs mentioned above?

@@ -5951,7 +5951,7 @@ public void testBug574823_completeOn_methodInvocationWithParams_inIfConidtion_in

String result = requestor.getResults();
assertTrue(String.format("Result doesn't contain method forEach (%s)", result),
result.contains("forEach[METHOD_REF]{forEach(), Ljava.lang.Iterable<Ljava.lang.String;>;, (Ljava.util.function.Consumer<-Ljava.lang.String;>;)V, null, null, forEach, (arg0), replace[149, 149], token[149, 149], 60}"));
result.contains("forEach[METHOD_REF]{forEach(), Ljava.lang.Iterable<Ljava.lang.String;>;, (Ljava.util.function.Consumer<-Ljava.lang.String;>;)V, null, null, forEach, (arg0), replace[149, 149], token[149, 149], 55}"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephan-herrmann Could this be due to poping out the interestingEnclosings ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephan-herrmann Could this be due to poping out the interestingEnclosings ?

To assess the change in relevance I'd first check which ingredient to this number got lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To answer my own question: with this change R_VOID is "added" to the relevance, which in fact is the penalty -5.

This happens during computeRelevanceForExpectingType(), where previously no expected types were known, but now we recognize that in this condition position type boolean should be expected. This lets us detect that the method return type void is a bad match.

I confirmed, that without the current change, no expected types were available, and R_VOID was never raised.

@gayanper
Copy link
Contributor

gayanper commented Feb 9, 2024

I tried to see if we are missing any control conditions, I see we don't have a endVisit for ForStatement, But even without it our unit test pass with following test snippet

switch (input) {
case A:
	for (int i = 0; i < nam)
	break;
}

Do you think we are missing any ?

@stephan-herrmann
Copy link
Contributor Author

I tried to see if we are missing any control conditions, I see we don't have a endVisit for ForStatement, But even without it our unit test pass with following test snippet

switch (input) {
case A:
	for (int i = 0; i < nam)
	break;
}

Do you think we are missing any ?

To parallel the original test case I'd try smth like this:

case A:
	for (int i = 0; nam|)
	    break;
}

i.e., completion on a direct child in the ForStatement.condition location (currently you have an intermediate binary expression).

Another check for completeness: if we have a method in scope that returns boolean and has a name starting with 'nam': do we propose it with relevance R_EXACT_EXPECTED_TYPE? I.e. is completion correctly leveraging the information from the .condition location? I'm not sure though, if CompletionEngine is complete in this regard, yet.

@gayanper
Copy link
Contributor

@stephan-herrmann I added a additional test for testing the scenarios you mentioned in above comment #1953 (comment)

@stephan-herrmann stephan-herrmann added this to the 4.32 M1 milestone Feb 22, 2024
@mpalat mpalat modified the milestones: 4.32 M1, MilestoneNxt Mar 1, 2024
@mpalat mpalat modified the milestones: MilestoneNxt, 4.32 M1 Mar 8, 2024
@stephan-herrmann stephan-herrmann merged commit 75b9df3 into eclipse-jdt:master Mar 14, 2024
9 checks passed
@stephan-herrmann stephan-herrmann deleted the issue1561 branch March 14, 2024 15:06
robstryker pushed a commit to robstryker/eclipse.jdt.core that referenced this pull request Jul 18, 2024
gayanper added a commit to gayanper/eclipse.jdt.core that referenced this pull request Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content assist does not activate, inside if() within a switch
3 participants