@@ -78,6 +78,22 @@ object Completion {
78
78
Mode .None
79
79
}
80
80
81
+ /** When dealing with <errors> in varios palces we check to see if they are
82
+ * due to incomplete backticks. If so, we ensure we get the full prefix
83
+ * including the backtick.
84
+ *
85
+ * @param content The source content that we'll check the positions for the prefix
86
+ * @param start The start position we'll start to look for the prefix at
87
+ * @param end The end position we'll look for the prefix at
88
+ * @return Either the full prefix including the ` or an empty string
89
+ */
90
+ private def checkBacktickPrefix (content : Array [Char ], start : Int , end : Int ): String =
91
+ content.lift(start) match
92
+ case Some (char) if char == '`' =>
93
+ content.slice(start, end).mkString
94
+ case _ =>
95
+ " "
96
+
81
97
/**
82
98
* Inspect `path` to determine the completion prefix. Only symbols whose name start with the
83
99
* returned prefix should be considered.
@@ -92,15 +108,14 @@ object Completion {
92
108
completionPrefix(selector :: Nil , pos)
93
109
}.getOrElse(" " )
94
110
95
- // We special case Select here because we want to determine if the name
96
- // is an error due to an unclosed backtick.
97
- case (select : untpd.Select ) :: _ if (select.name == nme.ERROR ) =>
98
- val content = select.source.content()
99
- content.lift(select.nameSpan.start) match
100
- case Some (char) if char == '`' =>
101
- content.slice(select.nameSpan.start, select.span.end).mkString
102
- case _ =>
103
- " "
111
+ // Foo.`se<TAB> will result in Select(Ident(Foo), <error>)
112
+ case (select : untpd.Select ) :: _ if select.name == nme.ERROR =>
113
+ checkBacktickPrefix(select.source.content(), select.nameSpan.start, select.span.end)
114
+
115
+ // import scala.util.chaining.`s<TAB> will result in a Ident(<error>)
116
+ case (ident : untpd.Ident ) :: _ if ident.name == nme.ERROR =>
117
+ checkBacktickPrefix(ident.source.content(), ident.span.start, ident.span.end)
118
+
104
119
case (ref : untpd.RefTree ) :: _ =>
105
120
if (ref.name == nme.ERROR ) " "
106
121
else ref.name.toString.take(pos.span.point - ref.span.point)
0 commit comments