Skip to content

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

Merged
merged 1 commit into from
Nov 30, 2020

Conversation

prolativ
Copy link
Contributor

No description provided.

@prolativ prolativ force-pushed the extension-method-code-completion branch from 3bfc89c to 3bd6d93 Compare November 25, 2020 14:04
@prolativ
Copy link
Contributor Author

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

@nicolasstucki
Copy link
Contributor

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) =
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking isBottomType then

Comment on lines 240 to 243
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
Copy link
Member

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

@prolativ prolativ force-pushed the extension-method-code-completion branch from 3bd6d93 to fd73164 Compare November 27, 2020 15:52
@prolativ prolativ force-pushed the extension-method-code-completion branch from fd73164 to b9da708 Compare November 27, 2020 17:49
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Nicely done, thanks!

@prolativ
Copy link
Contributor Author

@smarter ready for merge

@smarter smarter merged commit 377ce48 into scala:master Nov 30, 2020
@smarter
Copy link
Member

smarter commented Nov 30, 2020

(note that you should have the rights to merge PRs yourself, and it's OK to do so once it's been approved)

@prolativ prolativ deleted the extension-method-code-completion branch November 30, 2020 08:47
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

4 participants