Flow: Interactive mode for getting proposals of types to apply

Created on 25 Aug 2019  路  6Comments  路  Source: facebook/flow

Proposal

As you might use Flow to monitor your files using command _flow status_, I was wondering why not to add an interactive option to Flow which might propose a fix on the fly to a given issue using available options defined in source code already. Flow's Getting Started guide uses the example of a function called square. This function has two issues around the function parameter and returned value.
The interactive mode might propose to

  • function parameter applying number (as multiplication operator was used against variable x) OR string as function was triggered using string "2"
  • function return type applying number (as multiplication operator was used against variable x). No other proposals might be suggested as function's returned value was not assigned to any value.

Use case

See above.

LSP discussion

Most helpful comment

hopefully tons of them. they'd depend on the error. for bad addition, it could suggest explicit casting. for missing properties, it could suggest adding the property to the literal, or making it optional in the type, etc. for missing annotations, it should suggest one. for unused suppressions, it should let you remove the comment. for any error, it should suggest a suppression (as a last resort). the last two would replace ./tool add-comment.

All 6 comments

This is Quick Fix code actions in LSP?

This is Quick Fix code actions in LSP?

yes, and we have experimental support for it coming soon!

@mroch would there be more than one action?

yep! if you return multiple codeActions, VSCode presents you a list. it's a bit tough because you don't get much space in the UI to explain the difference, but doable.

cc @akuhlens, who worked on this stuff as an intern this summer!

I mean more like what kind of fixes Flow would have

hopefully tons of them. they'd depend on the error. for bad addition, it could suggest explicit casting. for missing properties, it could suggest adding the property to the literal, or making it optional in the type, etc. for missing annotations, it should suggest one. for unused suppressions, it should let you remove the comment. for any error, it should suggest a suppression (as a last resort). the last two would replace ./tool add-comment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cubika picture cubika  路  3Comments

davidpelaez picture davidpelaez  路  3Comments

Beingbook picture Beingbook  路  3Comments

philikon picture philikon  路  3Comments

mmollaverdi picture mmollaverdi  路  3Comments