Dart-code: Import quick-fix appears for `foo()` but not `foo`

Created on 31 Jul 2019  路  7Comments  路  Source: Dart-Code/Dart-Code

Dart Code 3.2.1
Mac OS

Hi, when I use quick fix on a function that doesn't have it's parentheses (or arguments, ie I'm specifying the function type rather making a call to a function), quick fix doesn't suggest the function import statement for me. When the parentheses are added quick fix suggests the import.

Sometimes I pass functions around so the quick fix without the parentheses would be really useful.

doStuff(anotherFunction); // quick fix doesn't work
doStuff(anotherFunction()); // quick fix works

Would it be possible for the quick fix to work on the function without the parentheses?

Thank you

fixed in dart / flutter

Most helpful comment

Fix is in https://github.com/dart-lang/sdk/commit/3011ca2da76d3dd0a6abed74750fe93d95bae17b. It may take a little time to make it to a Dart (or Flutter) stable release though.

All 7 comments

@bwilkerson @scheglov do you know if there's a reason the import quickfix doesn't appear here, or is it just an oversight and could be added?

@twistedinferno another quick way to import in the meantime is using the code completion - it should list functions even if they're not imported and automatically import them when selected. You can invoke completion with Cmd+Space/Ctrl+Space even if you've typed the full function name and it'll add the import:

Screenshot 2019-08-01 at 18 21 32

It will also add parens on the end though unless you disable dart.insertArgumentPlaceholders, so it may be just as annoying depending on whether you're happy to disable that or not.

Thanks Danny, for some reason the code completion doesn't always suggest the function (I'm unsure why or in which situations but I will keep an eye out, maybe I wasn't always using the correct shortcut though). When it doesn't suggest it I put the parens at the end just so I can get the import so I have a work around.

Yes. Those two diagnostics have different codes associated with them, and the code for the top line doesn't have that fix associated with it. We should be able to fix that, but I can't give you a timeline for such a fix.

for some reason the code completion doesn't always suggest the function

If you've only recently opened the project, there might be a delay before the completions for unimported symbols show up - but if you're not seeing them at all even after a while, it's worth opening another issue for.

Yes. Those two diagnostics have different codes associated with them

Aha - one is undefined_function and the other undefined_identifier. I don't mind taking a look - I'm not very familiar with how the fixes work so it's an opportunity to look through them even if it's relatively straight forward.

Fix is in https://github.com/dart-lang/sdk/commit/3011ca2da76d3dd0a6abed74750fe93d95bae17b. It may take a little time to make it to a Dart (or Flutter) stable release though.

for some reason the code completion doesn't always suggest the function

...the reason why it didn't always suggest the import is because one small project was in my workspace but not referenced in my .yaml file! (I think it just gave me the impression that it was included because the folder was in my Workspace...silly mistake by me but just in case someone else has the same problem! (a 'nice to have' feature request could be a suggestion to import the reference into the .yaml file; perhaps if it belongs in the Workspace but not in the .yaml?)

I'm confused - if the project wasn't referenced, wouldn't it not show up either with or without parens?

a 'nice to have' feature request could be a suggestion to import the reference into the .yaml file; perhaps if it belongs in the Workspace but not in the .yaml?

That does sound like it could be useful, but would also need implementing in the server so maybe worth opening an issue in the SDK repo. I don't think the server currently manipulates the pubspec though so I'm not sure how involved it'd be (or how common multi-project workspaces are).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mayorbyrne picture mayorbyrne  路  5Comments

rgb1380 picture rgb1380  路  3Comments

ifredom picture ifredom  路  3Comments

DanTup picture DanTup  路  4Comments

DanTup picture DanTup  路  3Comments