-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add quick fix to add .nn #23598
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
base: main
Are you sure you want to change the base?
Add quick fix to add .nn #23598
Conversation
cc @noti0na1 |
case Some(tree) if tree != null => | ||
val content = tree.source.content().slice(tree.srcPos.startPos.start, tree.srcPos.endPos.end).mkString | ||
val replacement = tree match | ||
case Apply(fun, args) => "(" + content + ").nn" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safer to add "( )" by default? For example, (if ... then ... else ...).nn
. Then, we only add "( )" if the tree is a ident, select, or a regular apply?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like the best approach. The only problem I have is detecting a regular apply. Binary infix operators have ApplyKind Regular and I couldn't find another way to determine if Apply's were initially written as a regular non-infix apply in the source code. Do you know if there's a way to detect "true" regular apply's?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've addressed all the other comments in the latest commit, but I'm still unsure how to detect functions written Infix. For the time being, both ApplyKind Regular and InfixTuple have "()" added to them while ApplyKind Using has no brackets.
…es for in-line match and if, improve formatting, and add more test Signed-off-by: Seyon Sivatharan <sivatharanseyon@gmail.com>
An extension to #23461 that adds a quick fix to add a .nn. For example, if the code were
the quick fix would transform the code to
The code is WIP (I've put some ugly workarounds to get it to work). Right now, it adds brackets whenever the root node is an Apply. This is needed for infix functions (both those with ApplyKind InfixTuple and those that are written as such in the source code, such as + which is desugared to an ApplyKind Regular I think), but there may be other edge cases where brackets are needed. I've discussed these edges cases a bit with @olhotak and @HarrisL2, but it's possible that we've missed some (or I've forgotten to add them).