-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Draft: additional completions for using clause #23647
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?
Conversation
I've added some additional tests that are failing currently:
|
Scala CLA signed |
|@main def main1(): Unit = | ||
| val str = "hello" | ||
| val int = 4 | ||
| hello(using str, int) |
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.
Looks like this check is actually failing because we check if arguments.size == 1
I would leave this test out or just document the current behaviour.
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.
yeah the test was written this way as this was one of the proposed solutions to do nothing when we have 2 arguments. When I remove that guard the using
keyword will be before int
arg anyway. I'm not sure should i leave it that way or try to fix it.
s"""|def hello(using String): Unit = ??? | ||
|@main def main1(): Unit = | ||
| val str = "hello" | ||
| hello(using str) |
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.
Looks like this one is adding two usings still, do you need help figuring this one out?
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.
yup some hints will be welcomed :). As far as I understand it the completion check is done from method invocation level, but I'm not sure how could I check the actual code or find out if there already i s'using' clause in any other way.
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.
Thanks for working on this!
adjustedPath match | ||
case (ident: Ident) :: (app@Apply(_,args)) :: _ if args.size == 1 => | ||
app.symbol.info match | ||
case mt@MethodType(termNames) if app.symbol.paramSymss.last.exists(_.is(Given)) => |
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.
case mt@MethodType(termNames) if app.symbol.paramSymss.last.exists(_.is(Given)) => | |
case mt@MethodType(termNames) if app.symbol.paramSymss.last.exists(_.is(Given)) && | |
!text.substring(app.fun.span.end, arg.span.start).contains("using") => |
I was thinking if we can make it simpler, but I can't see how.
CompletionAffix.empty | ||
.chain { suffix => // for [] suffix | ||
if shouldAddSuffix && symbol.info.typeParams.nonEmpty then | ||
suffix.withNewSuffixSnippet(Affix(SuffixKind.Bracket)) | ||
else suffix | ||
} | ||
.chain{ suffix => | ||
adjustedPath match | ||
case (ident: Ident) :: (app@Apply(_,args)) :: _ if args.size == 1 => |
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.
case (ident: Ident) :: (app@Apply(_,args)) :: _ if args.size == 1 => | |
case (ident: Ident) :: (app@Apply(_, List(arg))) :: _ => |
|@main def main1(): Unit = | ||
| val str = "hello" | ||
| val int = 4 | ||
| hello(using str, int) |
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.
| hello(using str, int) | |
| hello(str, int) |
let's document and fix later
fix for #22939