@@ -7,18 +7,13 @@ import dotty.tools.pc.completions.CompletionValue.SingletonValue
77import dotty .tools .dotc .ast .tpd .*
88import dotty .tools .dotc .core .Constants .Constant
99import dotty .tools .dotc .core .Contexts .Context
10- import dotty .tools .dotc .core .Flags
11- import dotty .tools .dotc .core .StdNames
1210import dotty .tools .dotc .core .Symbols
1311import dotty .tools .dotc .core .Types .AndType
1412import dotty .tools .dotc .core .Types .AppliedType
1513import dotty .tools .dotc .core .Types .ConstantType
1614import dotty .tools .dotc .core .Types .OrType
17- import dotty .tools .dotc .core .Types .TermRef
1815import dotty .tools .dotc .core .Types .Type
1916import dotty .tools .dotc .core .Types .TypeRef
20- import dotty .tools .dotc .util .Spans .Span
21- import dotty .tools .dotc .core .Symbols .defn
2217
2318object SingletonCompletions :
2419 def contribute (
@@ -55,79 +50,3 @@ object SingletonCompletions:
5550 collectSingletons(tpe1).intersect(collectSingletons(tpe2))
5651 case _ => Nil
5752
58- object InterCompletionType :
59- def inferType (path : List [Tree ])(using Context ): Option [Type ] =
60- path match
61- case (lit : Literal ) :: Select (Literal (_), _) :: Apply (Select (Literal (_), _), List (s : Select )) :: rest if s.symbol == defn.Predef_undefined =>
62- inferType(rest, lit.span)
63- case ident :: rest => inferType(rest, ident.span)
64- case _ => None
65-
66- def inferType (path : List [Tree ], span : Span )(using Context ): Option [Type ] =
67- path match
68- case Apply (head, List (p : Select )) :: rest if p.name == StdNames .nme.??? && p.qualifier.symbol.name == StdNames .nme.Predef && p.span.isSynthetic =>
69- inferType(rest, span)
70- case Block (_, expr) :: rest if expr.span.contains(span) =>
71- inferType(rest, span)
72- case If (cond, _, _) :: rest if ! cond.span.contains(span) =>
73- inferType(rest, span)
74- case Typed (expr, tpt) :: _ if expr.span.contains(span) && ! tpt.tpe.isErroneous => Some (tpt.tpe)
75- case Block (_, expr) :: rest if expr.span.contains(span) =>
76- inferType(rest, span)
77- case Bind (_, body) :: rest if body.span.contains(span) => inferType(rest, span)
78- case Alternative (_) :: rest => inferType(rest, span)
79- case Try (block, _, _) :: rest if block.span.contains(span) => inferType(rest, span)
80- case CaseDef (_, _, body) :: Try (_, cases, _) :: rest if body.span.contains(span) && cases.exists(_.span.contains(span)) => inferType(rest, span)
81- case If (cond, _, _) :: rest if ! cond.span.contains(span) => inferType(rest, span)
82- case CaseDef (_, _, body) :: Match (_, cases) :: rest if body.span.contains(span) && cases.exists(_.span.contains(span)) =>
83- inferType(rest, span)
84- case NamedArg (_, arg) :: rest if arg.span.contains(span) => inferType(rest, span)
85- // x match
86- // case @@
87- case CaseDef (pat, _, _) :: Match (sel, cases) :: rest if pat.span.contains(span) && cases.exists(_.span.contains(span)) && ! sel.tpe.isErroneous =>
88- sel.tpe match
89- case tpe : TermRef => Some (tpe.symbol.info).filterNot(_.isErroneous)
90- case tpe => Some (tpe)
91- // List(@@)
92- case SeqLiteral (_, tpe) :: _ if ! tpe.tpe.isErroneous =>
93- Some (tpe.tpe)
94- // val _: T = @@
95- // def _: T = @@
96- case (defn : ValOrDefDef ) :: rest if ! defn.tpt.tpe.isErroneous => Some (defn.tpt.tpe)
97- // f(@@)
98- case (app : Apply ) :: rest =>
99- val param =
100- for {
101- ind <- app.args.zipWithIndex.collectFirst {
102- case (arg, id) if arg.span.contains(span) => id
103- }
104- params <- app.symbol.paramSymss.find(! _.exists(_.isTypeParam))
105- param <- params.get(ind)
106- } yield param.info
107- param match
108- // def f[T](a: T): T = ???
109- // f[Int](@@)
110- // val _: Int = f(@@)
111- case Some (t : TypeRef ) if t.symbol.is(Flags .TypeParam ) =>
112- for {
113- (typeParams, args) <-
114- app match
115- case Apply (TypeApply (fun, args), _) =>
116- val typeParams = fun.symbol.paramSymss.headOption.filter(_.forall(_.isTypeParam))
117- typeParams.map((_, args.map(_.tpe)))
118- // val f: (j: "a") => Int
119- // f(@@)
120- case Apply (Select (v, StdNames .nme.apply), _) =>
121- v.symbol.info match
122- case AppliedType (des, args) =>
123- Some ((des.typeSymbol.typeParams, args))
124- case _ => None
125- case _ => None
126- ind = typeParams.indexOf(t.symbol)
127- tpe <- args.get(ind)
128- if ! tpe.isErroneous
129- } yield tpe
130- case Some (tpe) => Some (tpe)
131- case _ => None
132- case _ => None
133-
0 commit comments