Skip to content

Completions for requests just before string #22894

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 2 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ object Completion:
else if sel.isGiven && sel.bound.span.contains(pos.span) then Mode.ImportOrExport
else Mode.None // import scala.{util => u@@}
case GenericImportOrExport(_) => Mode.ImportOrExport | Mode.Scope // import TrieMa@@
case untpd.InterpolatedString(_, untpd.Literal(Constants.Constant(_: String)) :: _) :: _ =>
Mode.Term | Mode.Scope
case untpd.Literal(Constants.Constant(_: String)) :: _ => Mode.Term | Mode.Scope // literal completions
case (ref: untpd.RefTree) :: _ =>
val maybeSelectMembers = if ref.isInstanceOf[untpd.Select] then Mode.Member else Mode.Scope
Expand Down Expand Up @@ -221,7 +223,17 @@ object Completion:
// Ignore synthetic select from `This` because in code it was `Ident`
// See example in dotty.tools.languageserver.CompletionTest.syntheticThis
case tpd.Select(qual @ tpd.This(_), _) :: _ if qual.span.isSynthetic => completer.scopeCompletions
case tpd.Select(qual, _) :: _ if qual.typeOpt.hasSimpleKind => completer.selectionCompletions(qual)
case tpd.Select(b @ tpd.Apply(c @ tpd.Select(d @ tpd.Select(_, StdNames.nme.StringContext), _), _), _) :: _ =>
Seq(b,c,d).foreach { tree =>
println("---------------------------")
println(tree)
println(tree.show)
println(completer.selectionCompletions(tree))
}
println(completer.scopeCompletions)
completer.scopeCompletions ++ completer.selectionCompletions(b)
case tpd.Select(qual, _) :: _ if qual.typeOpt.hasSimpleKind =>
completer.selectionCompletions(qual)
case tpd.Select(qual, _) :: _ => Map.empty
case (tree: tpd.ImportOrExport) :: _ => completer.directMemberCompletions(tree.expr)
case _ => completer.scopeCompletions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dotty.tools.pc.tests.completion

import dotty.tools.pc.base.BaseCompletionSuite
import org.junit.Test

class BlaSuite extends BaseCompletionSuite:
@Test
def t1 = check(
"""
|object M:
| val VersionRegex = "".r
| VersionRe@@"1234"
""".stripMargin,
"|VersionRegex: Regex".stripMargin
)

@Test
def t2 = check(
"""
|object M:
| ra@@"1234"
""".stripMargin,
"|raw(args: Any*): String".stripMargin
)
Loading