-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support completions for extension definition parameter #18331
Conversation
d64894b
to
281576d
Compare
This PR also contains refactor in Presentation Compiler completions, to reuse completion mode from the compiler instead of providing own logic for that. It caused a lot of issues already which tend to be fixed by this PR such as Term completions for |
b1d1944
to
7c8ebd9
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.
Generally that looks reasonable, but I'm wondering about one thing, if you're using untyped trees only to establish the mode and get the prefix, how will that work for e.g.
extension (x: Bar.Fo@@)
will the scope for the completion search be correct?
@@ -256,8 +192,7 @@ class Completions( | |||
private def findSuffix(symbol: Symbol): CompletionSuffix = | |||
CompletionSuffix.empty | |||
.chain { suffix => // for [] suffix | |||
if shouldAddSnippet && | |||
cursorPos.allowBracketSuffix && symbol.info.typeParams.nonEmpty | |||
if shouldAddSnippet && symbol.info.typeParams.nonEmpty |
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'm not sure you can just get rid of cursorPos.allowBracketSuffix
. I think one of its responsibilities is getting rid of square brackets for methods, for which we want to have ()
as suffix. Can you add a test to make sure I'm wrong.
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 added a test, but overall I believe it was fixed #15750, and now we don't have to calculate it manually.
presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala
Outdated
Show resolved
Hide resolved
Valid point. It won't work for any Select. I'll update the PR with the fix. |
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 good! Just one comment
check( | ||
"""|trait Foo | ||
|object T: | ||
| extension [A](using Foo)(x: Fo@@)(using Fo@@) |
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.
| extension [A](using Foo)(x: Fo@@)(using Fo@@) | |
| extension [A](using Foo)(x: Fo@@)(using Foo) |
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 good :)
4df84e4
to
7300205
Compare
Extension methods are extended into normal definitions. Because of that typed trees don't include any information about the extension method definition parameter: ```scala extension (x: In@@) ``` In order to add completions, we check if there is an exact path to the untyped tree, and if not, we fall back to it. There may also be more possible cases like that, but I can't think of any at the moment. [Cherry-picked de4ad2b]
Extension methods are extended into normal definitions. Because of that typed trees don't include any information about the extension method definition parameter: ```scala extension (x: In@@) ``` In order to add completions, we check if there is an exact path to the untyped tree, and if not, we fall back to it. There may also be more possible cases like that, but I can't think of any at the moment. [Cherry-picked de4ad2b]
Extension methods are extended into normal definitions.
Because of that typed trees don't include any information about the extension method definition parameter:
In order to add completions, we check if there is an exact path to the untyped tree, and if not, we fall back to it. There may also be more possible cases like that, but I can't think of any at the moment.