-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #10264: Add code completion for extension methods #10473
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
Fix #10264: Add code completion for extension methods #10473
Conversation
3bfc89c
to
3bd6d93
Compare
The tests are passing now. @nicolasstucki As far as I can see you've had some experience with the code around completions so it would be nice if you could have a look at that |
Actually, I only wrote the test infrastructure for completion tests. The tests seem to be good. @smarter could you have a look at the implementation of the completion logic? |
@@ -2176,4 +2176,8 @@ trait Applications extends Compatibility { | |||
report.error(em"not an extension method: $methodRef", receiver.srcPos) | |||
app | |||
} | |||
|
|||
def isApplicableExtensionMethod(ref: TermRef, receiver: Type)(using Context) = |
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.
You could check !receiver.isBottomType
here to exclude Nothing and Null so you don't have to exclude them in the caller.
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.
Right, I can move the check here but not sure we should exclude Null. The compiler still lets you define an extension on Null so I think for consistency this should be displayed in a completion
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.
The compiler still lets you define an extension on Null so I think for consistency this should be displayed in a completion
I don't think it's a big deal either way, but because by default Null
is a subtype of every reference type, one should be careful to not include all the extension methods that apply to reference types in the list
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.
Checking isBottomType
then
val givensInScope = ctx.implicits.eligible(defn.AnyType).map(_.implicitRef.underlyingRef) | ||
val implicitScopeCompanions = ctx.run.implicitScope(qual.tpe).companionRefs.showAsList | ||
val givensInImplicitScope = implicitScopeCompanions.flatMap(_.membersBasedOnFlags(required = Given, excluded = EmptyFlags)).map(_.symbol.info) | ||
val implicitExtensionSources = givensInImplicitScope ++ implicitScopeCompanions ++ givensInScope |
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.
http://dotty.epfl.ch/docs/reference/contextual/extension-methods.html section "Translation of Calls to Extension Methods" defines four possible sources of extension methods, it would be nice to add a comment above each line here which corresponds to one of these source (the line can just be a copy-paste of the corresponding documentation).
3bd6d93
to
fd73164
Compare
fd73164
to
b9da708
Compare
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.
Nicely done, thanks!
@smarter ready for merge |
(note that you should have the rights to merge PRs yourself, and it's OK to do so once it's been approved) |
No description provided.