Skip to content

Commit e27d3ac

Browse files
committed
Try to extract name when backtick is missing
Previously, completion prefix would show up as an empty string if we had an unclosed backtick. Now, we try to extract the prefix from the file contents in that case. An alternative approach would be to tranfer somehow the name string in `nme.Error`, but I didn't see anything like that done before, so not sure how to properly address that. Fixes #12514
1 parent 31292be commit e27d3ac

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ object Completion {
9292
}.getOrElse("")
9393

9494
case (ref: untpd.RefTree) :: _ =>
95-
if (ref.name == nme.ERROR) ""
95+
if (ref.name == nme.ERROR) {
96+
val content = ref.source.content()
97+
// if the error resulted from unclosed back tick
98+
if content(ref.span.start) == '`' then
99+
content.slice(ref.span.start + 1, ref.span.end).mkString
100+
else
101+
""
102+
}
96103
else ref.name.toString.take(pos.span.point - ref.span.point)
97104

98105
case _ =>

language-server/test/dotty/tools/languageserver/CompletionTest.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,4 +842,10 @@ class CompletionTest {
842842
|object Main { "abc".xx${m1} }""".withSource
843843
.completion(m1, Set())
844844
}
845+
846+
@Test def wrongAnyMember: Unit = {
847+
code"""|import scala.util.chaining.`sc${m1}
848+
|""".withSource
849+
.completion(m1, Set(("scalaUtilChainingOps",Method,"[A](a: A): scala.util.ChainingOps[A]")))
850+
}
845851
}

0 commit comments

Comments
 (0)