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

Code completion order arbitrary #51762

Closed
dcharkes opened this issue Mar 17, 2023 · 7 comments
Closed

Code completion order arbitrary #51762

dcharkes opened this issue Mar 17, 2023 · 7 comments
Assignees
Labels
analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on

Comments

@dcharkes
Copy link
Contributor

The order of class and constructor definitions is undefined:

https://dart-review.googlesource.com/c/sdk/+/283341/2/pkg/analysis_server/test/services/completion/dart/location/relational_pattern_test.dart#113

I'm getting class/constructor reorderings on an unrelated CL.

cc @bwilkerson @scheglov

@dcharkes dcharkes added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-server labels Mar 17, 2023
@bwilkerson
Copy link
Member

I'm surprised. I would have expected the order to be stable. We certainly haven't seen any flakiness on the bots.

Can you point me to the unrelated CL? I'll probably need to step through the debugger to understand where the change in the order is occurring.

@dcharkes
Copy link
Contributor Author

dcharkes commented Mar 17, 2023

Before my change:

  A01
    kind: constructorInvocation
  A01
    kind: class
  A02
    kind: constructorInvocation
  A02
    kind: class
  B01
    kind: class
  B01
    kind: constructorInvocation

Why does B01 have the class kind first, and the others have the constructorInvocation kind first?

@bwilkerson
Copy link
Member

It isn't a very satisfying answer, but the truth it that the completion support was organically grown, so some of the code is duplicated in ways that introduce inconsistencies like that. It's something I hope to be able to address next quarter.

@scheglov
Copy link
Contributor

I think we probably cannot expect that the server returns completion suggestions in any particular order.
But we can expect that it has relevance set, so that the client can sort it.

We try to sort suggestions in our tests, specifically to prevent such random order changes.
By default we sort by relevance, and then by the completion string.
Unfortunately, these are probably the same in this case.
The solution is probably to sort also by kind.

@bwilkerson
Copy link
Member

I think we probably cannot expect that the server returns completion suggestions in any particular order.

Why? Is there some non-determinism that I'm forgetting about?

The solution is probably to sort also by kind.

That seems reasonable to me, at least for these tests. The purpose of these tests is not to test the order of the suggestions, just the presence or absence.

But I'd suggest that we stop sorting by relevance. I don't want to have to re-write the expectations every time the relevance changes. We have separate tests for relevance and shouldn't be testing that here, especially since the fact that it's being tested for is hidden.

@srawlins srawlins added the P2 A bug or feature request we're likely to work on label Mar 19, 2023
@scheglov scheglov self-assigned this Apr 2, 2023
@scheglov
Copy link
Contributor

scheglov commented Apr 2, 2023

copybara-service bot pushed a commit that referenced this issue Apr 3, 2023
Bug: #51762
Change-Id: I46019bea72ac1656c97acb9da88da7dc577d8ef5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292640
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
@scheglov scheglov closed this as completed Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

4 participants