Skip to content

Analyzer suggests auto-complete items that are not useful #35863

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

Closed
2 tasks
matanlurey opened this issue Feb 5, 2019 · 7 comments
Closed
2 tasks

Analyzer suggests auto-complete items that are not useful #35863

matanlurey opened this issue Feb 5, 2019 · 7 comments
Labels
devexp-completion Issues with the analysis server's code completion feature legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@matanlurey
Copy link
Contributor

matanlurey commented Feb 5, 2019

My file looks approximately like this:

import 'package:angular/angular.dart';
import 'package:swlegion/catalog.dart';
import 'package:swlegion/holodeck.dart';

class Simulator {
  static final _defendingWhiteSurgeTroopers = Defender.multipleUnits(
    [
      Units.$1dot4FDLaserCannonTeam,
      Units.$74ZSpeederBikes,
    ],
    const DefensePool(
      dice: Dice
      // ^^^^^^^
    ),
  );

I wanted a suggestion of package:swlegion/holodeck.dart, which includes a DefenseDice class.

I hit CTRL-SPACE, and got:

screen shot 2019-02-05 at 12 07 42 pm

A few comments/requests:

  • Can analyzer only suggest types that are valid, especially since Dart 2?

I was assigning to DefensePool.dice, which reads:

  /// What type of dice the defending units are using.
  final DefenseDice dice;

... so I think it would be ideal to only suggest types that are valid assignments to DefenseDice.

  • Can analyzer do full-string matches instead of partial?

I typed dice, assuming that it would auto-complete to DefenseDice but instead got:

  • Directive
  • Uri.directory(...)

... etc. Maybe this makes sense up to say, 2 characters, but clearly by typing dice I did not intend to write Uri.directory. In fact, DefenseDice does not show up at all in the list no matter what I type and try to complete, because it is not imported. But that's unfortunate, because it is one of my dependencies.

@matanlurey matanlurey added legacy-area-analyzer Use area-devexp instead. devexp-completion Issues with the analysis server's code completion feature type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Feb 5, 2019
@bwilkerson
Copy link
Member

I wanted a suggestion of package:swlegion/holodeck.dart, which includes a DefenseDice class.

In fact, DefenseDice does not show up at all in the list no matter what I type and try to complete, because it is not imported. But that's unfortunate, because it is one of my dependencies.

The source code appears to contradict the second statement, so I'm not sure I understand what the problem is. But if the issue is that server isn't suggesting names from libraries that are not imported but could be, then we're already working on fixing the issue.

Can analyzer only suggest types that are valid, especially since Dart 2?

I agree that it would be useful for server to prioritize suggestions that match the target type when such a type is known. I would love to see us add support for that.

Can analyzer do full-string matches instead of partial?

The filtering is actually being done by the client, not by the server. @jwren @alexander-doroshko for feedback on the filtering. It would be interesting to know where DefenseDice would have been in the list had it been imported (or where it will be once we start including non-imported names).

@matanlurey
Copy link
Contributor Author

@bwilkerson:

But if the issue is that server isn't suggesting names from libraries that are not imported but could be, then we're already working on fixing the issue.

Yes, is there a bug tracking this particular issue?

I agree that it would be useful for server to prioritize suggestions that match the target type

Is it worth filing a separate issue specifically for this?

Can analyzer do full-string matches instead of partial?

In this case it was actually VSCode, not IntelliJ (/cc @DanTup), fwiw.

@bwilkerson
Copy link
Member

is there a bug tracking this particular issue?

Yes, the issue is #25820.

Is it worth filing a separate issue specifically for this?

Given that using type information to prioritize suggestions is (I think) the only analyzer issue left that isn't being worked on elsewhere, I think it's fine if we use this issue to track it.

@alexander-doroshko
Copy link

Speaking of IntelliJ, it has 2 shortcuts for code completion: standard (Ctrl+Space) and Smart Completion (Ctrl+Shift+Space). Standard completion suggests everything available at the caret position. Smart Completion suggests only those items that match expected type. It even includes chained calls that result in expected type.

Unfortunately, Smart Completion is not yet supported in Dart but you may try it in Java and in some other languages to get the idea. If you like the idea we may think about implementing the feature on the Analysis Server end and integrating it in IDEs.

@alexander-doroshko
Copy link

And speaking of middle-matching and sorting, IntelliJ shows items with exact matches higher than items with fractional matches, so 'DefenseDice' would be close to top if it were in the list. Middle-matching, case-sensivity and other completion options are configurable in IntelliJ.

@DanTup
Copy link
Collaborator

DanTup commented Feb 6, 2019

Can analyzer only suggest types that are valid, especially since Dart 2?

This was raised in Dart Code previously too, but I think filtering out unrelated types may be bad because there could be static members on those types that you want. For example in flutter_gallery there's this:

MaterialDemoDocumentationButton(SnackBarDemo.routeName)

That constructor takes a String and if we filtered out SnackBarDemo you'd have to type it manually. Ranking them may be better, or maybe even including the static members directly in the list (I think we already do it with enum values).

I typed dice, assuming that it would auto-complete to DefenseDice but instead got:

  • Directive

The filtering is done client-side so this is VS Code behaviour. It seems like you might not be able to disable it though there is editor.suggest.filterGraceful which controls whether it matches what it thinks are typos. I wonder if they could only match on exact strings or by looking at the capital letters (looks like maybe it does that for quick open?).

@stereotype441 stereotype441 added the P2 A bug or feature request we're likely to work on label Feb 6, 2019
@bwilkerson
Copy link
Member

The available declarations support addressed at least one of the issues raised here. We're also now paying attention to the context type, so that ought to address at least one of the issues. I'm going to close this but please let me know if we've missed something important that isn't yet resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-completion Issues with the analysis server's code completion feature legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants