@@ -15,7 +15,6 @@ import dotty.tools.dotc.core.StdNames.nme
1515import dotty .tools .dotc .core .SymDenotations .SymDenotation
1616import dotty .tools .dotc .core .TypeError
1717import dotty .tools .dotc .core .Types .{ExprType , MethodOrPoly , NameFilter , NoType , TermRef , Type }
18- import dotty .tools .dotc .parsing .Scanners
1918import dotty .tools .dotc .parsing .Tokens
2019import dotty .tools .dotc .util .Chars
2120import dotty .tools .dotc .util .SourcePosition
@@ -118,6 +117,7 @@ object Completion {
118117 private def computeCompletions (pos : SourcePosition , path : List [Tree ])(using Context ): (Int , List [Completion ]) = {
119118 val mode = completionMode(path, pos)
120119 val rawPrefix = completionPrefix(path, pos)
120+
121121 val hasBackTick = rawPrefix.headOption.contains('`' )
122122 val prefix = if hasBackTick then rawPrefix.drop(1 ) else rawPrefix
123123
@@ -135,7 +135,8 @@ object Completion {
135135 }
136136
137137 val describedCompletions = describeCompletions(completions)
138- val backtickedCompletions = describedCompletions.map(backtickCompletions)
138+ val backtickedCompletions =
139+ describedCompletions.map(completion => backtickCompletions(completion, hasBackTick))
139140
140141 val offset = completionOffset(path)
141142
@@ -147,14 +148,14 @@ object Completion {
147148 (offset, backtickedCompletions)
148149 }
149150
150- def backtickCompletions (completion : Completion ) =
151- if needsBacktick(completion.label) then
151+ def backtickCompletions (completion : Completion , hasBackTick : Boolean ) =
152+ if hasBackTick || needsBacktick(completion.label) then
152153 completion.copy(label = s " ` ${completion.label}` " )
153154 else
154155 completion
155156
156157 // This borrows from Metals, which itself borrows from Ammonite. This uses
157- // the same apprach , but some of the utils that already exist in Dotty.
158+ // the same approach , but some of the utils that already exist in Dotty.
158159 // https://github.com/scalameta/metals/blob/main/mtags/src/main/scala/scala/meta/internal/mtags/KeywordWrapper.scala
159160 // https://github.com/com-lihaoyi/Ammonite/blob/73a874173cd337f953a3edc9fb8cb96556638fdd/amm/util/src/main/scala/ammonite/util/Model.scala
160161 private def needsBacktick (s : String ) =
@@ -429,6 +430,7 @@ object Completion {
429430 private def include (denot : SingleDenotation , nameInScope : Name )(using Context ): Boolean =
430431 val sym = denot.symbol
431432
433+
432434 nameInScope.startsWith(prefix) &&
433435 sym.exists &&
434436 completionsFilter(NoType , nameInScope) &&
0 commit comments