Skip to content

Commit da6c055

Browse files
committed
Revert changes to backticked prefix calculations
1 parent 4be7db7 commit da6c055

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ object Completion:
116116

117117
completionSymbolKind | completionKind
118118

119+
/** When dealing with <errors> in varios palces we check to see if they are
120+
* due to incomplete backticks. If so, we ensure we get the full prefix
121+
* including the backtick.
122+
*
123+
* @param content The source content that we'll check the positions for the prefix
124+
* @param start The start position we'll start to look for the prefix at
125+
* @param end The end position we'll look for the prefix at
126+
* @return Either the full prefix including the ` or an empty string
127+
*/
128+
private def checkBacktickPrefix(content: Array[Char], start: Int, end: Int): String =
129+
content.lift(start) match
130+
case Some(char) if char == '`' =>
131+
content.slice(start, end).mkString
132+
case _ =>
133+
""
134+
119135
/**
120136
* Inspect `path` to determine the completion prefix. Only symbols whose name start with the
121137
* returned prefix should be considered.
@@ -139,6 +155,14 @@ object Completion:
139155
completionPrefix(selector :: Nil, pos)
140156
.getOrElse("")
141157

158+
// Foo.`se<TAB> will result in Select(Ident(Foo), <error>)
159+
case (select: untpd.Select) :: _ if select.name == nme.ERROR =>
160+
checkBacktickPrefix(select.source.content(), select.nameSpan.start, select.span.end)
161+
162+
// import scala.util.chaining.`s<TAB> will result in a Ident(<error>)
163+
case (ident: untpd.Ident) :: _ if ident.name == nme.ERROR =>
164+
checkBacktickPrefix(ident.source.content(), ident.span.start, ident.span.end)
165+
142166
case (tree: untpd.RefTree) :: _ if tree.name != nme.ERROR =>
143167
tree.name.toString.take(pos.span.point - tree.span.point)
144168

0 commit comments

Comments
 (0)