-
Notifications
You must be signed in to change notification settings - Fork 134
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
Faulty/Undesired CodeCompletion behaviour #2620
Comments
@stephan-herrmann can you take a look please ?? Thanks |
@angelickite thanks for narrowing it down so far! What is the most recent version of Eclipse that you tested? @gayanper this smells a bit like work were we let |
@stephan-herrmann I am usually and currently running on the latest publicly available version of eclipse. Also just grabbed a fresh copy from https://www.eclipse.org/downloads/ with
The situation with that version is exactly as described so far. As I didn't figure out yet how to fully build eclipse from source I can not test any farther. |
Thanks, @angelickite So my hopes this might have been fixed in the meanwhile are void :)
Many thanks for this pointer! Unfortunately, it points to a major refactoring, which at that time fixed many bugs at once, but apparently, there are negative effects as well :( This implies there will be little use in delta-debugging before and after states. There won't be a short cut around debugging the "new strategy" in detail. |
I did some more digging. Here is where the completion gets recognized in the "bad" case: Lines 5873 to 5875 in a62c379
Here is why the source gets overwriten: Lines 3397 to 3398 in a62c379
Please note that I did all the debugging around eclipse 2021-06 so far, though the findings should be applicable for the current codebase. Hope this helps! |
It looks like the new strategy introduced with e3517dd is potentially more "potent" overall but lost some of its previous cursor awareness. Here is another example that got broken with the new strategy that has been bugging me daily over the years: public class Demo2 {
public static void main(String[] args) {
Test test;
if (true) {
test.|cursor|.test;
}
}
public static class Test {
public Test test;
}
} Triggering autocomplete at the given cursor location by typing "tes" and then confirming with enter leads to the following result:
The completion engine correctly triggers a Line 3714 in a62c379
In this case the cursor is located on the second qualified name at sourcePosition[1], so I would expect that one to be the source boundary. Not sure what the correct way forward is, be it changing the overall strategy or bringing back cursor awareness to the new strategy, but I would love for the autocomplete to be an enhancer again, not a continuous struggle during development. |
@angelickite I'm amazed by the depth of your analysis :) While currently I can't make this issue my main focus, I'd be more than happy to help you getting even closer to the root of the matter. Some general links you may or may not have seen yet:
|
Here's a concrete thing you could try:
|
Thank you for your pointers. I gave the whole contribution thing a quick shot but quickly came up against walls that I am currently not willing to put up with. I know eclipse project is at a high level of complexity, however from my point of view enabling contributing is the number one priority for a project of its kind, so anything beyond a "git clone, checkout, run tests, build" (each a single action) is just very off putting. Please don't take the nagging in a bad taste, just a personal pet peeve I needed to get out. Here is an attempt of mine in case someone else is able to pick it up from here:
CompletionOnMessageSendName completion = new CompletionOnMessageSendName(null, 0, 0, nextIsCast); // positions will be set in consumeMethodInvocationName(), if that's who called us
completion.cursorIsToTheLeftOfTheLParen = true;
m = completion;
if (messageSend.cursorIsToTheLeftOfTheLParen) {
// take into consideration the cursor location, i.e. it being to the left of lParen. (GH-2620 @https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2620)
setSourceAndTokenRange(messageSend.sourceStart, messageSend.sourceEnd);
} else {
setTokenRange(messageSend.sourceStart, messageSend.sourceEnd);
if (messageSend.statementEnd > messageSend.sourceStart)
setSourceRange(messageSend.sourceStart, messageSend.statementEnd);
}
// take into consideration the cursor location. (GH-2620 @https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2620)
// void x(LinkedListNode n) {
// LinkedListNode other = n.ch|cursor|.child.child.parent;
// // ...
// }
// in the above example, bestPosition will match against the cursor with "ch", i.e. sourcePositions[1].
// (sourcePositions[0] points to 'n', sourcePositions[4] to 'parent')
long bestPosition;
{
bestPosition = -1L;
for (int i = 0; i < sourcePositions.length; i++) {
long p = sourcePositions[i];
int start = (int) (p >>> 32);
int end = (int) (p);
if (start >= this.actualCompletionPosition && end <= this.actualCompletionPosition) {
bestPosition = p;
// we take the matching position that is the "farthest to the right".
// whether that is correct in all future cases remains to be seen.
// for the time of this writing the last match suffices.
// (if for example the first match is desired, we could "break;" here)
}
}
}
if (bestPosition == -1L) {
// fallback to the previous behaviour, just in case.
bestPosition = sourcePositions[sourcePositions.length - 1];
}
long completionPosition = bestPosition; |
Please don't tell this to people like Ed Merks, who have been working very, very hard to make workspace setup as simple as possible (but not simpler than that ;-P ). Have you tried the eclipse installer? It performs all necessary steps with just a few clicks: select your eclipse version, select the eclipse projects you want to work on, select an installation folder, and swooop, after a coffee break your shiny new workspace should be waiting for you :) And if something goes wrong during setup, there are friendly folks who will be happy to accept your report (knowing that your reports will show enough details work investigation). |
I have observed that in some cases the sourcePositions of a completion behave oddly:
With the cursor at '|' the parser packs the sourcePosition at the cursor location such that start > end, e.g. if start is 89, then end is 88. Seems to happen only specifically in a dot-cursor-dot situation. Is this an known/accepted oddity of the parser or a new issue by itself? I have encountered this behaviour during my work on this issue. For now I will proceed by locally swapping start and end in such an edge-case as to not blow up this whole issue into a full rework of the underlying system. |
Completions for CompletionOnMessageSendName as well as for QualifiedNameReference did not take the cursor position into consideration, leading to various downstream issues like failing to complete at all, not properly overwriting a source range or overwriting too eagerly. fixes eclipse-jdt#2620
Hello. This situation has been driving me (and others) crazy every minute(!) I am coding with eclipse since forever, so I finally took some time out to at least pinpoint the offending plugin and commit. Hope this helps!
This behaviour started back with eclipe 2021-06 while 2021-03 still behaved "well".
Code completion is behaving in an undesired manner in the following situation:
Triggering code completion (ctrl+space) while the cursor is located as indicated gives a list of proposals, so far so good.
Now, after selecting the first proposal (in my case the "print" method), the code gets transformed as follows:
The expected behaviour would be that the existing parameter "world" remains in place and only the "ln" part of "println" gets removed, i.e. the method call is updated from "println" to "print", like so:
Note that I have enclosed the second println statement in an if block (the true doesnt matter). An empty block does not show the bad behaviour. Here is an (incomplete) overview:
My content assist settings:
I was able to pinpoint the issue to the jdt.core, specifically the following commit: e3517dd
To arrive at this commit I used a git bisect:
Due to the complexity of that specific commit, me looking into the eclipse source code for the first time, and my lack of time, I was hoping someone more experienced could pick it up from here.
There are some other completion issues I have been encountering which are possibly related to this, so looking into it is hopefully time well spent.
Additionally possibly related:
#1770
#1016
Thank you!
The text was updated successfully, but these errors were encountered: