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

Create from inferred usage #711

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dillonkearns
Copy link
Contributor

For reference, here's the work-in-progress from our live stream today. I'll update this thread as I finish these todos.

Current State

Screen Recording 2020-09-07 at 04 55 48 PM

Todos

  • Don't suggest for unresolved type references - only for value functions (for this PR, revisit in the future)
  • Don't suggest fix for qualified references
  • Make sure cursor focus goes through argument names so you can tab through to change them
    • Make declaration fix does it
    • It's called a Template (see TemplateManager)
  • Add newline for proper formatting for creating function
  • Location - insert it right below call site function body, not at bottom

Maybe now, maybe defer?

  • Infer types based on values passed in?
  • Use argument template names based on types, like create from declaration?

@dillonkearns
Copy link
Contributor Author

A fun reference, Kolja shared this PR with me where he implements the same functionality for the Elm languages server:

elm-tooling/elm-language-server#319


val arity = (element.parent as? ElmFunctionCallExpr)?.arguments?.count() ?: 0

val argList: String = argListFromArity(arity)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can generate type-based parameter names like this:

val inference = element.findInference() ?: return
val callExpr = element.parent as? ElmFunctionCallExpr ?: return
val argsTys = callExpr.arguments.map { inference.elementType(it) }
val parameters = argsTys.joinToString(" ") { it.renderParam() }

And then, if argsTys isn't empty, you can generate a type annotation the way the MakeAnnotationIntention does.

"$s : ${TyFunction(args, TyUnknown()).renderedText(elmFile = element.elmFile).replace("", "->")}"

@klazuka
Copy link
Collaborator

klazuka commented Sep 13, 2020

This will fix #661

@cies cies added the feature label Apr 3, 2024
@cies
Copy link
Contributor

cies commented Apr 4, 2024

Hi @dillonkearns ! I took over the stewardship of this repo. I find this PR nice to merge. Do you want to address the point @ajalt made and extend on this feature before you take it out of "draft" and I merge it? Or would you also promote this PR in it's current shape from draft to ready-to-merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants