Add pattern completion for unapply contexts#20274
Merged
natsukagami merged 5 commits intoscala:mainfrom May 22, 2024
Merged
Conversation
rochala
reviewed
Apr 27, 2024
Contributor
rochala
left a comment
There was a problem hiding this comment.
I left 2 comments, and if you could also add test which checks deeper nesting levels. Other than that it looks fine to me
Will this also work for multiple nested levels ?
null match
case Some(Some(Some(Som@@))))
presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala
Show resolved
Hide resolved
| |} | ||
| |""".stripMargin, | ||
| """|Some(value) scala | ||
| |Some[A](value: A): Some[A] |
Contributor
There was a problem hiding this comment.
I'm not sure whether we should still show synthetic constructor / apply completions in this case. They are invalid here.
Completions for completions is a different story though, as we have no logic to detect whether it has nested members yet, so this is another improvement that could be made in the future.
If you want to remove Some[A](value: A): Some[A] I suppose it can be achieved by adding unapply cases here:
//file: Completions.scala
private lazy val shouldAddSnippet =
path match
/* In case of `method@@()` we should not add snippets and the path
* will contain apply as the parent of the current tree.
*/
case (fun) :: (appl: GenericApply) :: _ if appl.fun == fun =>
false
case _ :: (withcursor @ Select(fun, name)) :: (appl: GenericApply) :: _
if appl.fun == withcursor && name.decoded == Cursor.value =>
false
case (_: (Import | Export)) :: _ => false
case _ :: (_: (Import | Export)) :: _ => false
case _ => trueThe idea was to collect patterns given the Unapply tree as the parent. We need to deconstruct the UnApply type tree and get the type of the placeholder ident.
rochala
approved these changes
May 22, 2024
WojciechMazur
added a commit
that referenced
this pull request
Jul 8, 2024
Backports #20274 to the LTS branch. PR submitted by the release tooling. [skip ci]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #19972.
Add pattern completion for
Unapplytree contexts.A typical example would be
which should be prompted
Some(value), due toList.unapplySeqexpectingOption[T]patterns as arguments.