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

feature: Add missing case patterns #5496

Closed

Conversation

ghostbuster91
Copy link
Collaborator

@ghostbuster91 ghostbuster91 commented Jul 30, 2023

Comment on lines +33 to +38
| def method(tree: Tree) = {
| tree match {
| case Node(_, _) => ???
| case Leaf(_) => ???
| }
| }
Copy link
Collaborator Author

@ghostbuster91 ghostbuster91 Jul 30, 2023

Choose a reason for hiding this comment

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

The test fails for now because the Leaf case is added in wrong place.
The current output is:

Leaf(_) match {
  case Node(_, _) => ???
}

My idea is to create something like AutoImportProvider where I would get access to the typedTree and more importantly its parent, which in our case is

tree match {
  case Node(_, _) => ???
}

I could then use the endRange of such tree, and insert the missing cases just one line before it. This would involve going through the presentation compiler interface.

Though maybe there is a simpler way. Let me know what you think.
Eventually I could try to use

      name <- trees
        .findLastEnclosingAt[Term.Name](path, params.getRange().getStart())

but that gives the parent of the whole match, which seems to be too much.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think untyped trees should be enough here. I'm not sure what you mean by "the parent of the whole match". The whole match should be a Term.Match. Using that you should be able to find the last case and place new ones after it. Here you can explore the syntax trees: https://astexplorer.net.

Copy link
Collaborator Author

@ghostbuster91 ghostbuster91 Jul 31, 2023

Choose a reason for hiding this comment

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

By "parent of the whole match" I meant that I was getting:

def method(tree: Tree) = {
   tree match {
     case Node(_, _) => ???
     case Leaf(_) => ???
   }
 }

but I must have had something wrong because now it works as expected. Thanks 👍

@ghostbuster91
Copy link
Collaborator Author

Closing in favor of scala/scala3#18314

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.

None yet

2 participants