From 8fa4216d7e1d4232792b8d45fdce72e9fc6a33a6 Mon Sep 17 00:00:00 2001 From: Tom Grigg Date: Sat, 5 Jun 2021 16:19:31 -0700 Subject: [PATCH] Handle ExprType during tab completion Fixes #12600, #13365 --- .../dotty/tools/dotc/interactive/Completion.scala | 3 ++- .../test/dotty/tools/repl/TabcompleteTests.scala | 6 ++++++ .../tools/languageserver/CompletionTest.scala | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index bb552191fc36..8c19671293e0 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -300,7 +300,8 @@ object Completion { case name: TermName if include(denot, name) => Some((denot, name)) case _ => None - types.flatMap { tpe => + types.flatMap { tp => + val tpe = tp.widenExpr tpe.membersBasedOnFlags(required = ExtensionMethod, excluded = EmptyFlags) .collect { case DenotWithMatchingName(denot, name) => TermRef(tpe, denot.symbol) -> name } } diff --git a/compiler/test/dotty/tools/repl/TabcompleteTests.scala b/compiler/test/dotty/tools/repl/TabcompleteTests.scala index cbf267e7c846..540147bcd211 100644 --- a/compiler/test/dotty/tools/repl/TabcompleteTests.scala +++ b/compiler/test/dotty/tools/repl/TabcompleteTests.scala @@ -132,4 +132,10 @@ class TabcompleteTests extends ReplTest { @Test def i6415 = fromInitialState { implicit s => assertEquals(List("Predef"), tabComplete("object Foo { opaque type T = Pre")) } + + @Test def i12600 = fromInitialState { implicit s => + assertEquals(List("select", "show", "simplified"), + tabComplete("import quoted.* ; def fooImpl(using Quotes): Expr[Int] = { import quotes.reflect.* ; TypeRepr.of[Int].s")) + } + } diff --git a/language-server/test/dotty/tools/languageserver/CompletionTest.scala b/language-server/test/dotty/tools/languageserver/CompletionTest.scala index 615e8f3b4049..0f886dc25bf1 100644 --- a/language-server/test/dotty/tools/languageserver/CompletionTest.scala +++ b/language-server/test/dotty/tools/languageserver/CompletionTest.scala @@ -842,4 +842,19 @@ class CompletionTest { |object Main { "abc".xx${m1} }""".withSource .completion(m1, Set()) } + + @Test def i13365: Unit = { + code"""|import scala.quoted._ + | + |object Test { + | def test(using Quotes)(str: String) = { + | import quotes.reflect._ + | val msg = Expr(str) + | val printHello = '{ print("sdsd") } + | val tree = printHello.asTerm + | tree.sh${m1}@@ // doesn't work + | } + |}""".withSource + .completion(m1, Set(("show",Method, "(using x$2: x$1.reflect.Printer[x$1.reflect.Tree]): String"))) + } }