Skip to content

Port Inlay hints for name parameters #23375

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zielinsky
Copy link
Contributor

@zielinsky zielinsky commented Jun 16, 2025

Add inlay hints for name parameters.

Porting scalameta/metals#7400

@zielinsky zielinsky force-pushed the name-parameters branch 2 times, most recently from 971cee4 to d41d2a3 Compare June 20, 2025 10:09
@zielinsky zielinsky requested review from tgodzik and Florian3k June 20, 2025 10:13
@zielinsky zielinsky marked this pull request as ready for review June 20, 2025 10:13
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.

Great work! I think we can improve it a bit though.

@@ -611,17 +611,17 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
|class DemoSpec {
| import ScalatestMock._
|
| /*StringTestOps<<(6:17)>>(*/"foo"/*)*/ should {/*=> */
Copy link
Contributor

Choose a reason for hiding this comment

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

These are byName parameters being tested here, we should probably not change this test case, no?

@@ -29,6 +30,7 @@ import dotty.tools.dotc.util.Spans.Span
import org.eclipse.lsp4j.InlayHint
import org.eclipse.lsp4j.InlayHintKind
import org.eclipse.{lsp4j as l}
import dotty.tools.dotc.core.NameOps.fieldName
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import dotty.tools.dotc.core.NameOps.fieldName
import dotty.tools.dotc.core.NameOps.fieldName

I would try and keep the imports sorted

adjusted
None

def adjustParameterPos(pos: SourcePosition): SourcePosition =
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this function? Isn't it basically the same what we had above? For None we return adjusted which is adjustPos(pos)

Or alternative just have one NamedParameters.unapply for both and only adjust showing => when the proper parameter is selected

@@ -116,8 +118,8 @@ class PcInlayHintsProvider(
InlayHintKind.Type,
)
.addDefinition(adjustedPos.start)
case ByNameParameters(byNameParams) =>
def adjustByNameParameterPos(pos: SourcePosition): SourcePosition =
case NamedParameters(_) | ByNameParameters(_) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

We now invoke the unapply and don't do anything with the results, no? Could we split it into two cases and just extract common methods? Otherwise for each tree we calculate everything twice.

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

Successfully merging this pull request may close these issues.

2 participants