Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

harpocrates
Copy link
Contributor

The code detecting the completion prefix of the identifier before the cursor was not accounting for that identifier potentially being backticked.

This manifests both in the REPL where TAB completing inside backticks doesn't work and (what I care about more) in the presentation compiler completionsAt API.

@scala-jenkins scala-jenkins added this to the 2.13.17 milestone Jan 26, 2025
@harpocrates
Copy link
Contributor Author

Scala 3 handles this case correctly. I spent some time looking at the Scala 3 version of this code and realized from there that all of this reverse engineering of where the identifier starts is unnecessary - I think we can just use refTree.span.point

Scala 3 code - almost all of which is actually about cases Scala 2 doesn't worry about. The case for RefTree is what is relevant here.

@lrytz
Copy link
Member

lrytz commented Jan 27, 2025

Thanks!

It doesn't seem to work in the REPL, so there's something else in the way there. It's fine with me if you want to leave that aside.

But I wonder if returning Foo Bar for completing `Foo ` works as expected, i.e., if the backticks stay in place and we get `Foo Bar`. Is that the positionDelta in CompletionResult? Can we check that in the test?

Did you check if completing `Foo without a closing backtick is possible? Completing Option[Str for example also works.

It would also be nice if X.Foo completes to X.`Foo Bar`.

harpocrates added a commit to harpocrates/metals that referenced this pull request Jan 27, 2025
2.13 only and needs scala/scala#10986. 3.x
version should not need upstream changes - completion API seems to
already work around backticks.
@harpocrates
Copy link
Contributor Author

harpocrates commented Jan 27, 2025

It doesn't seem to work in the REPL, so there's something else in the way there. It's fine with me if you want to leave that aside.
...
It would also be nice if X.Foo completes to X.Foo Bar.

I think those might be due to pre-existing gaps. I'll double check though. Especially the first point surprises me a bit. I'd expect that if you have the closing backtick, the completion should work...

But I wonder if returning Foo Bar for completing Foo works as expected, i.e., if the backticks stay in place and we get Foo Bar. Is that the positionDelta in CompletionResult? Can we check that in the test?

I think so, but I'll check. I've been using this while exploring scalameta/metals-feature-requests#418 (see the screenshots there - the behavior at least through metals keeps the backticks in place).

Did you check if completing `Foo without a closing backtick is possible? Completing Option[Str for example also works.

That won't work yet - we'd need to back port this logic. This matters less for Metals since we can instead configure editors to auto-close backticks (plus that's more robust if you are in the middle of a line - the rest of your line doesn't get parsed into the backticked ident)

Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

LMK when you're done. We can go ahead as it currently is - modulo my question below.

@harpocrates
Copy link
Contributor Author

harpocrates commented Feb 9, 2025

Alright, I did a loop here and I don't think there's anything further I want to investigate for now. LMK if that's OK.

I unsuccessfully took a stab at getting the REPL to support correctly adding backticks (scala/bug#6919) just in case I could use that to determine definitively the "right" positionDelta value - this is my first time using jline and the logic around the words is tricky (I got to the point that some things we're being backticked correctly, but other things would crash).

I've since made the LSP half of this change for Scala 3.6 (scala/scala3#22555). My plan is to get this PR merged and then merge scalameta/metals#7204 to get roughly the same behavior in 2.13.x.

Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

I think we can go ahead with this. Just a small suggestion.

The code detecting the completion prefix of the identifier before the
cursor was not accounting for that identifier potentially being
backticked.

This manifests both in the REPL where TAB completing inside backticks
doesn't work and (what I care about more) in the presentation compiler
`completionsAt` API.
@harpocrates harpocrates force-pushed the backtick-completions2 branch from f2c96ff to 54d5f37 Compare February 10, 2025 12:27
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

Thanks!

@lrytz lrytz enabled auto-merge February 10, 2025 12:40
@lrytz lrytz merged commit 99614f8 into scala:2.13.x Feb 10, 2025
3 checks passed
@harpocrates harpocrates deleted the backtick-completions2 branch February 10, 2025 15:31
@harpocrates
Copy link
Contributor Author

@lrytz When do you expect Scala 2.13.17 to be released? Looking at the last several releases in the 2.13.x, it seems like they are roughly every 4-6 month, so that would but 2.13.17 around June, right?

@SethTisue
Copy link
Member

@harpocrates in short, we don't know for sure yet (see https://contributors.scala-lang.org/t/scala-2-13-17-release-planning/6994) but yes, 4–6 months is a good guess. we don't currently have a reason to do it faster

@tgodzik
Copy link
Contributor

tgodzik commented Feb 11, 2025

It is possible to work around it in Metals by switching to a method, that will match on the changed cases and use completionsAt otherwise.

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.

5 participants