Description
Compiler version
3.2.0-RC1-bin-20220307-6dc591a-NIGHTLY-git-6dc591a
Explanation
As a follow-up to the work done in #14594 there are still a couple situations that still don't offer you a completions if your preface already includes an opened backtick.
Minimized code
The first case be illustrated by the following:
val `foo-bar` = 3
val x = `foo<TAB>
In this situation no completion is offered because the tree that is contained for the current position is Literal(Constant(null))
. This seems to come from:
The second situation is when this is a type instead of a term like so:
type Foo = `Lis<TAB>
The tree that is returned here is TypeDef(Foo,Ident(<error>))
One final example is:
val `foo-bar` = 3
`foo<TAB>
In this situation Interactive.patTo
just returns the entire document.
Expectation
I'd expect the correct backticked completions to be offered in all 3 of these examples.
Potential solutions
The first way I tried to solve this was by adding specific cases for the first two in various places to catch those trees. For example in:
https://github.com/lampepfl/dotty/blob/808c66925daa518294e15419dffec9b7c1490848/compiler/src/dotty/tools/dotc/interactive/Completion.scala#L61-L79
and
https://github.com/lampepfl/dotty/blob/808c66925daa518294e15419dffec9b7c1490848/compiler/src/dotty/tools/dotc/interactive/Completion.scala#L85-L110
and
https://github.com/lampepfl/dotty/blob/808c66925daa518294e15419dffec9b7c1490848/compiler/src/dotty/tools/dotc/interactive/Completion.scala#L128-L137
While this works for those two situations it's quite a bit of code for very specific scenarios, and we're probably missing some as well that would also need to be added in. An alternative proposed by @bishabosha here is as follows:
We had a small discussion and it could be worth trying to make a new Token for an unfinished backticked identifier, which we can then make a valid tree for