Bug 574215 - [content assist] Content assist doesn't work after else without semicolon on line
Summary: [content assist] Content assist doesn't work after else without semicolon on ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.20   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.21 M1   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks: 574913
  Show dependency tree
 
Reported: 2021-06-15 14:05 EDT by Snjezana Peco CLA
Modified: 2021-10-21 15:18 EDT (History)
13 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Snjezana Peco CLA 2021-06-15 14:05:25 EDT
Steps to reproduce:

- call CA at

private void test(String s, int i) {
  if (i > 2) {
    System.out.println("a");
  } else {
    s.| // <--
    System.out.println("b");
}

Eclispe returns "No Default Proposals".
The issue can't be reproduced in Eclipse <= 4.20M1.
Original issue: https://github.com/eclipse/eclipse.jdt.ls/issues/1800
Comment 1 Andrey Loskutov CLA 2021-06-15 14:08:20 EDT
Which exact Eclipse build was used? Can it be a duplicate of bug 573632?
Comment 2 Roland Grunberg CLA 2021-06-15 14:11:59 EDT
I was able to reproduce this issue since Eclipse 2021-06 M3 (I20210519-1800) but not with M1. Reproduces even with RC2a though.
Comment 3 Snjezana Peco CLA 2021-06-15 14:12:42 EDT
(In reply to Andrey Loskutov from comment #1)
> Which exact Eclipse build was used? Can it be a duplicate of bug 573632?

- https://download.eclipse.org/eclipse/updates/4.20-I-builds/I20210611-1600/
- Eclipse 4.20.RC2
- Eclipse 4.20RC1
- Eclipse 4.20M3

Eclipse 4.20M1 works fine.
Comment 4 Andrey Loskutov CLA 2021-06-15 14:16:33 EDT
Thanks, I see it on 4.21 master too :-(

The problem disappears if the line is terminated with semicolon - but of course this is not a valid workaround :-)

public class Snippet {
	private void test(String s, int i) {
		if (i > 2) {
			System.out.println("a");
		} else {
			s.| ; // <-- with semicolon works, without: nada!
			System.out.println("b");
		}
	}
}

Stephan: could you please check?
Comment 5 Kalyan Prasad Tatavarthi CLA 2021-06-16 04:52:31 EDT
(In reply to Andrey Loskutov from comment #4)
> Thanks, I see it on 4.21 master too :-(
> 
> The problem disappears if the line is terminated with semicolon - but of
> course this is not a valid workaround :-)
> 
> public class Snippet {
> 	private void test(String s, int i) {
> 		if (i > 2) {
> 			System.out.println("a");
> 		} else {
> 			s.| ; // <-- with semicolon works, without: nada!
> 			System.out.println("b");
> 		}
> 	}
> }
> 
> Stephan: could you please check?

This seems to be happening as a result of commit https://bugs.eclipse.org/bugs/show_bug.cgi?id=539685#c41

Stephan, can you please look at this?
Comment 6 Stephan Herrmann CLA 2021-06-16 17:28:59 EDT
Similar to bug 573632 indeed.

The fix from bug 573632 does not trigger, because the connection between the element on the expression stack ("i > 2") and the if-else statement can no longer be established. The 'if' statement is removed from the element stack as soon as '}' terminates the then-block.

I could try to add sophistication to the fix of bug 573632, but that would introduce some complexity while fixing issues only if no lambda is "in sight".

As long as there is no help along the lines of bug 573632 we don't set a synthetic EOF, hence the code is parsed as:

private void test(String s, int i) {
  {
    <CompleteOnType:s.> System;
  }
}

There is a strange bias towards interpreting a "stray" identifier as the beginning of a variable declaration. I believe this is where the parser needs more smarts.
Comment 7 Eclipse Genie CLA 2021-06-16 17:33:09 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/182070
Comment 8 Sravan Kumar Lakkimsetti CLA 2021-06-17 00:11:38 EDT
Stephan,

Assigning this to you as you are working on this one.
Comment 9 Stephan Herrmann CLA 2021-06-17 04:47:42 EDT
(In reply to Sravan Kumar Lakkimsetti from comment #8)
> Stephan,
> 
> Assigning this to you as you are working on this one.

Sure.

(In reply to Eclipse Genie from comment #7)
> New Gerrit change created:
> https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/182070

I decided that the parser is already jumping through hoops more than desirable, it doesn't really have the means to decide if "s." should refer to a type or a variable.

Ergo I moved on to letting the CompletionEngine try more things: If "s" actually resolves to a variable, offer all available members of the variable's type.
But don't try this within method signatures (see testBug574215_type_not_field()). There may be more situations that I haven't checked for the theoretical chance to propose things of the wrong kind, but I doubt that those cases - if existent - would be relevant in practice.

As an advantage of moving this work into the engine (at a point where the AST is already resolved) we are now able to support this kind of completion even inside lambdas (as opposed to the emergency fix in bug 573632 that only restored old, pre-lambda behavior).
Comment 11 Stephan Herrmann CLA 2021-06-17 06:06:42 EDT
(In reply to Eclipse Genie from comment #10)
> Gerrit change https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/182070 was
> merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=dcdb41213d2a0c255037b790a64514a84fade08e

Released for 4.21 M1
Comment 12 Julian Honnen CLA 2021-06-18 04:39:13 EDT
I still see missing content assist with the following snippet in 
Version: 2021-09 (4.21)
Build id: I20210617-1800

public class Snippet {
	private boolean flag;

	private void test(List<String> c) {
		if (flag) {
                        | // content assist here
			List<String> scs = c.subList(0, 1);
		}
	}

	String test() {
		return null;
	}
}

Content assist only offers the type Snippet, not test() or c.

Is that related to this issue or separate?
Comment 13 Julian Honnen CLA 2021-06-18 04:48:57 EDT
reopening to be sure, I think the mailing failed for my previous comment
Comment 14 Fred Bricon CLA 2021-06-19 05:21:12 EDT
Yeah I confirmed this is still borked (we picked the latest I-Build in jdt.ls)

public void name(String fooo) {
    if (fooo != null) {
      fo| <-fooo is not proposed here
      System.err.println("Done");
    }
}
Comment 15 Stephan Herrmann CLA 2021-06-19 09:08:19 EDT
I don't see an 'else' in either comment 12 nor comment 14, so it definitely is not the same bug :)

Also this bug and it's predecessor bug 573632 were about completing after a dot. Since no dot is in the picture in your examples either, please file a new bug.
Comment 16 Jay Arthanareeswaran CLA 2021-07-07 04:42:50 EDT
Verified for 4.21 M1 using build  I20210706-1800
Comment 17 Stephan Herrmann CLA 2021-10-21 15:18:17 EDT
For posterity: this fix was superseded by part of the fix in bug 575631 (4.22 M2).