Dart code suggestions do not show until typing is stopped

I noticed that code suggestions for Flutter / Dart show only when I stop typing for a while. I also tried VSCode with the Dart plugin, which feels way quicker (see the attached video - VSCode is on the right side).

As seen from the screenshot of the Dart Analysis Server, the VSCode Dart plugin has a completely different approach to loading suggestions.

VSCode approach has unarguably some drawbacks, but current Dart plugin behavior on JetBrains platform is pretty much unusable. It's usually quicker to type everything than waiting for suggestions to show up finally. Judging from the debug log, suggestions are actually returned to the plugin in 332ms, but for some reason, they don't show until I stop typing.

It also seems to me that there are some misformatted queries, where no results are returned. Is this maybe preventing the suggestions dialog from showing as I type?

Please, let me know if I can do anything to help debug this issue further. I really don't want to be forced to switch to VSCode, but this is really a productivity killer.

2
3 comments
Official comment

Thank you for the feedback and sorry for the negative experience.

You are right, code completion engine seems to work differently in different IDEs. In IntelliJ IDEA, code completion is restarted if you type one more character before previously requested completion results get calculated.

I guess this can be improved but not sure about internal technical details yet. In general, it sounds like we don't need to restart code completion while typing within an identifier.

I think that different people have different coding habits. The problem that seems like a productivity killer making the IDE unusable may stay not noticed by other people at all.

For example, if I want to write `ChangeNotifierProvider`, I'll type `CNP` or `Cnp`. I won't notice any problems with code completion delay.

Some people prefer disabling case-sensitive completion (which is 'First letter' by default) and they will type just `cnp` to get this item.

When you quickly type the whole identifier manually expecting that code completion overtakes you, you'll notice some delay, unfortunately.

Avatar
Permanently deleted user

Thank you for the suggestion - indeed, the delay is less noticeable using your method.

However, I wouldn't say that current behavior should be considered working as expected, considering that valid suggestions from the dart server do not get shown to the user until he stops typing and waits for the last request to finish. I would say that writing CNP... and immediately continuing with ...rovider is objectively better, as the loading time is used to pre-type a more fine-grained filter, increasing the chance that the top result will be the one you want. Most of my colleagues who work on Flutter are also quite frustrated by current behavior.

I looked at the Dart plugin source, and as I understand, the behavior is:

  1. user types a character
  2. completion.getSuggestions request is sent to the dart server
  3. computedCompletionId is returned from the dart server, suggestions with received computedCompletionId are awaited and displayed to the user

The problem is that ProgressManager.checkCanceled(); stops the current flow of fetching suggestions, and what happens is:

  1. dart analysis server returns suggestions requested by the already aborted DartServerCompletionContributor { ...addCompletion... } call. Therefore the suggestions are ignored.
  2. before the previous request is completed, the dart server is spammed with a new request every time a user types a new character, which wastes a lot of resources and, at worst, overwhelms the server resulting in an even slower response time

I believe that the desired behavior should be to wait until the last request is resolved (as long as the context where a user is typing stays the same.), display the suggestions (with local filtering) to the user, and only then initiate a new request to the dart server.

Additionally, context-aware caching of suggestions would dramatically improve response time for 90% of the cases (e.g., old suggestions would appear instantly and, if necessary, refreshing as soon as possible.)

I made a few simple changes to the Dart plugin, and it's already much more enjoyable to program:

Of course, it is only a hack, so I would be very happy to see some effort to improve the default behavior.

Considering the rising popularity of Flutter, I would say these improvements would have quite a large impact. Please, let me know if your team will consider taking some time for this (otherwise we might decide to do it ourselves, but we'd prefer if someone who knows the internals of JB IDEs does it :)).

2

Thank you for the investigation. It's impressive!

I hope we'll find time to improve it in a non-hacky way. Please file an issue in https://youtrack.jetbrains.com/issues/WEB to track progress (Project: WebStorm, Subsystem: Dart ).

0

Please sign in to leave a comment.