Skip to content
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

bugfix: Extension method completion with name conflict #5913

Merged
merged 1 commit into from Dec 11, 2023

Conversation

jkciesluk
Copy link
Member

When symbol with the same name as extension method was present in scope, completion edit would insert full symbol name of this method, which was incorrect.

package example

|import example.enrichments.*

object enrichments:
  extension (num: Int)
    def plus(other: Int): Int = num + other

def main = {
  val plus = 100.plus(19)
  val y = 19.pl@@ // resulted in
  val y = 19.example.enrichments.plus($0)
}

@@ -261,6 +261,10 @@ class CompletionProvider(
mkItem(
"{" + sym.fullNameBackticked + completionTextSuffix + "}"
)
case _ if v.completionItemKind == CompletionItemKind.Method =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that it never makes sense for methods to put the full name:

//> using scala 3.3.1

object O {
  def mmm = 3
  class Test {
    val mmm = "aaaa"
    val foo = mmm@@
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it seems that the issue is that we don't see the extension method in the scope and we don't shorten the name. Especially this doesn't make sense for extension methods.

Copy link
Contributor

@kasiaMarek kasiaMarek Dec 7, 2023

Choose a reason for hiding this comment

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

Sure, it's just that this part of the code isn't used exclusively for extension methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that it never makes sense for methods to put the full name

Thanks, I missed this case would also be changed, I changed it so the change applies only to extension methods.

Copy link
Member Author

@jkciesluk jkciesluk Dec 7, 2023

Choose a reason for hiding this comment

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

object O {
 def mmm = 3
 class Test {
   val mmm = "aaaa"
   val foo = mmm@@
 }
}

Actually there is a bug in this case in Scala 2 (compiler thinks that def mmm is in scope), I will work on it in a follow-up

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

LGTM!

@tgodzik
Copy link
Contributor

tgodzik commented Dec 7, 2023

Let's add the change to the compiler also.

@jkciesluk jkciesluk merged commit 26a01d9 into scalameta:main Dec 11, 2023
25 checks passed
@jkciesluk jkciesluk deleted the ext-comp branch December 11, 2023 10:19
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.

None yet

3 participants