Skip to content

feat: add inlay hints for byname parameters #7404

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

Merged
merged 1 commit into from
Apr 17, 2025

Conversation

harpocrates
Copy link
Contributor

@harpocrates harpocrates commented Apr 15, 2025

This adds => hints for function parameters that are passed by name.
The common case of block by-name arguments moves the => to occur right
after the opening brace instead of before the entire argument.

Implements scalameta/metals-feature-requests#377

@harpocrates
Copy link
Contributor Author

I'm still not happy with the position of the =>. I'd like it to go on the opening line of a block for a block arg. ie.

Future {/* =>*/
  val x = 1
  x + x
}

It is not yet reliably doing that

@kasiaMarek
Copy link
Member

I see that mima fails. You need to add a default to byNameParameters in InlayHintsParams.java. Basically all things in mtags-interfaces need to be backwards compatible, because Metals will use old mtags (presentation compiler) for old Scala versions.

@harpocrates harpocrates force-pushed the by-name-parameter-hints branch 2 times, most recently from 0acd7bd to 7820a09 Compare April 16, 2025 01:41
@harpocrates harpocrates marked this pull request as ready for review April 16, 2025 01:57
This adds `=>` hints for function parameters that are passed by name.
The common case of block by-name arguments moves the `=>` to occur right
after the opening brace instead of before the entire argument.

Implements <scalameta/metals-feature-requests#377>
@harpocrates harpocrates force-pushed the by-name-parameter-hints branch from 7820a09 to 23ecb50 Compare April 16, 2025 11:37
Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

LGTM!

@tgodzik tgodzik merged commit 96c4b40 into scalameta:main Apr 17, 2025
24 of 25 checks passed
@harpocrates harpocrates deleted the by-name-parameter-hints branch April 17, 2025 10:09
@harpocrates
Copy link
Contributor Author

@tgodzik what's the next sequence of steps I should follow here? Presumably

  1. port the change to the scala 3 repo (so it'll work for recent Scala versions)
  2. add the knob to the various frontends (so like scalameta/metals-vscode@main...harpocrates:metals-vscode:byname-inlay-hints, but also for nvim-metals and the others)

How do we make sure that everything merged here also makes it to Scala 3? Is it basically up to contributors to be vigilant? Drift seems like it might be annoying. And if that's the process, I should probably also port 7d68a12, right?

@tgodzik
Copy link
Contributor

tgodzik commented Apr 17, 2025

port the change to the scala 3 repo (so it'll work for recent Scala versions)

We would need to first release the interfaces, I plan to port both this and the other PR for named parameters at the same time most likely.

add the knob to the various frontends (so like scalameta/metals-vscode@main...harpocrates:metals-vscode:byname-inlay-hints, but also for nvim-metals and the others

We usually just port for VS Code relying on other contributors for other repositories. I most cases the settings do not have to be declared in plugins to be used.

How do we make sure that everything merged here also makes it to Scala 3? Is it basically up to contributors to be vigilant? Drift seems like it might be annoying. And if that's the process, I should probably also port 7d68a12, right?

We usually mark it with the backport-scala3-pc label, but I might have missed some recently

@harpocrates
Copy link
Contributor Author

Thank you, totally makes sense!

@ckipp01
Copy link
Member

ckipp01 commented Apr 18, 2025

By the way I'd recommend also making sure this is added to UserConfiguration.scala show it shows up in this page in the docs to help people know it exists if they are setting up a new editor.

@tgodzik
Copy link
Contributor

tgodzik commented Apr 18, 2025

By the way I'd recommend also making sure this is added to UserConfiguration.scala show it shows up in this page in the docs to help people know it exists if they are setting up a new editor.

Sure! I will add it together with #7400

tgodzik pushed a commit to scala/scala3 that referenced this pull request May 30, 2025
Add `=>` hints for function parameters that are passed by name.

Porting scalameta/metals#7404
tgodzik pushed a commit to scala/scala3-lts that referenced this pull request Jun 2, 2025
Add `=>` hints for function parameters that are passed by name.

Porting scalameta/metals#7404
tgodzik added a commit to scala/scala3-lts that referenced this pull request Jun 2, 2025
Add `=>` hints for function parameters that are passed by name.

Porting scalameta/metals#7404
[Cherry-picked fd72f1a][modified]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants