-
Notifications
You must be signed in to change notification settings - Fork 853
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
Fix java completion sort for not-imported items. #7631
Fix java completion sort for not-imported items. #7631
Conversation
i checked if I could add a test but couldn't find existing tests which verify full completion results. They seem to typically implement one result only. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this need review from @dbalek. Looking at the charAt
method I have to conclude, that string concatenation was deemed expensive, else this whole class makes no sense and that raises the question how often the new codepath is actually hit.
If I see this correctly this codepath will be hit by FieldItem
and MethodItem
, which both modify the sortText with the enclosing element, while ClassItem
, LazyJavaCompletionItem
and StaticMemberItem
.
Looking at LazySortText further I see enclName
as parameter. It is unclear ,why it FieldItem
and MethodItem
don't use that.
In general I see why this change is done, I can reproduce the problem and verified it fixes the problem, so I'm leaning to a +1.
I believe it is safe to say (given the name) that the purpose of the class is delayed evaluation of the full char sequence. My hypothesis is that I could be wrong but my guess is that regarding performance, netbeans/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java Line 1899 in 03aa32d
toString should only be called once per item - i am pretty sure I checked this by setting a breakpoint.
yes I did wonder about this too |
but this shows again that impls need documentation, a single comment on top of that class would have made this much easier! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - lets get this in - it fixes a real problem.
9d7183d
to
4b9ac49
Compare
made a small change since the I did also take another look at this and Now its called while |
LazySortText implements CharSequence but missed a toString() method. It would use Object#toString() and since it is used as comparator input, it lead to undesired results. This was the case with 'List.of' for example. ('List' must not have an import yet) This commit introduces utility methods which allow the linking of CharSequences like LazySortText without toString() concatenation.
4b9ac49
to
08d86f1
Compare
I implemented it properly with a utility class which can link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sane to me and the new solution looks elegant.
LazySortText
implementsCharSequence
but misses atoString()
method.Without it, it would use
Object#toString()
, and since it is used as comparator input, it would lead to undesired results.This was the case with 'List.of' for example. ('List' must not have an import yet)
before
after
test
assignment (
enclSortText
can be of typeString
orLazySortText
):netbeans/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java
Lines 1564 to 1568 in 03aa32d
search token:
netbeans/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java
Line 1913 in 03aa32d
comparator:
netbeans/ide/editor.completion/src/org/netbeans/modules/editor/completion/CompletionItemComparator.java
Lines 59 to 60 in 03aa32d