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

When calling method with more than N arguments, prompt to complete with named arguments #389

Open
matthughes opened this issue Jun 24, 2024 · 4 comments

Comments

@matthughes
Copy link

Is your feature request related to a problem? Please describe.

When calling a method with a large number of arguments, it's sometimes hard to remember the names, types, and order of the arguments. Code completion works up to a point but 1) if you introduce a small error, you lose it and 2) the autocomplete tends to slow things down as it has to work after each argument.

Consider the following case class:

case class Foo(
  arg1: Int,
  arg2: String,
  arg3: Baz,
  // 12 more
  arg15: Bar
)

Describe the solution you'd like

If I invoke a method or case class with more than N arguments, I want a smart completion option ("complete with named arguments) that inserts this (using example from above):

case class Foo(
  arg1 = ???, // Int
  arg2 = ???, // String
  arg3 = ???, // Baz
  // 12 more
  arg15 = ??? // Bar
)

This gets me compiling code (in most cases) directly at the call site that I can now edit and fill in the holes as I'm ready to. For large methods like this, I often use the "use named arguments" function anyway but only after I've successfully gathered all the arguments.

Describe alternatives you've considered

I often will pull up a split pane in VsCode with the method I'm calling so I can see the arguments required without auto-complete coming up and disappearing.

Another option would be something like "show function in split pane". I guess the problem is the way auto-complete pop-overs work in VsCode. Because they are not sticky it's hard to see your place in a sea of more than a few method arguments.

Additional context

No response

Search terms

autocomplete arguments

@tgodzik
Copy link
Contributor

tgodzik commented Jun 24, 2024

Thanks for reporting! There is actually an existing completion, but it seems to be hidden now more than before

Screencast.from.24.06.2024.14.51.05.webm

I am not sure how to make it visible, but maybe we could make it a code action instead? Or optionally as suggested, show it more prominent when it's a lot of arguments 🤔

@tgodzik
Copy link
Contributor

tgodzik commented Jun 24, 2024

And it will try to input the values, so might not be perfect for your use case

@matthughes
Copy link
Author

omg that's awesome! So you just type the word auto? Is this documented somewhere? Definitely +100 for making it a code action or something cause I never would have discovered this.

@tgodzik
Copy link
Contributor

tgodzik commented Jun 24, 2024

I don't think that was ever properly documented, but also we weren't sure of the UX here, so we need to fix that.

https://scalameta.org/metals/blog/2019/09/12/thorium/#add-auto-fill-option-to-case-classes <- that's from release notes

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

No branches or pull requests

2 participants