Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

SuperCl4sh
Copy link
Contributor

An extension to #23461 that adds a quick fix to add a .nn. For example, if the code were

val t: String | Null = ???
val s: String = t

the quick fix would transform the code to

val t: String | Null = ???
val s: String = t.nn

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).

@SuperCl4sh SuperCl4sh marked this pull request as draft July 24, 2025 18:45
@SuperCl4sh SuperCl4sh marked this pull request as ready for review July 25, 2025 18:23
@HarrisL2
Copy link
Contributor

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"
Copy link
Member

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?

Copy link
Contributor Author

@SuperCl4sh SuperCl4sh Jul 27, 2025

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?

Copy link
Contributor Author

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>
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.

3 participants