Skip to content

Commit bd6de10

Browse files
committed
Move more code out of def computeCompletions
1 parent 297facb commit bd6de10

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

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

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,48 +34,20 @@ object Completion {
3434

3535
private def computeCompletions(pos: SourcePosition, path: List[Tree])(implicit ctx: Context): (Int, List[Symbol]) = {
3636

37-
/**
38-
* Extract basic info about completion location and the kind of symbols to include.
39-
*
40-
* @param path The path to the position where completion happens
41-
* @param inImport If set, indicates that this is the completion of an import node. When
42-
* completing imports, both types and terms are always included.
43-
* @return The information about completion (offset, kinds of symbol, etc.)
44-
*/
45-
def completionInfo(path: List[Tree], inImport: Boolean): CompletionInfo = path match {
46-
case (ref: RefTree) :: _ =>
47-
if (ref.name == nme.ERROR)
48-
CompletionInfo(ref.pos.point, "", Mode.None)
49-
else {
50-
val mode =
51-
if (inImport) Mode.Import
52-
else if (ref.name.isTermName) Mode.Term
53-
else Mode.Type
54-
55-
CompletionInfo(
56-
ref.pos.point,
57-
ref.name.toString.take(pos.pos.point - ref.pos.point),
58-
mode)
59-
}
60-
61-
case _ =>
62-
CompletionInfo(0, "", Mode.None)
63-
}
64-
6537
val info = path match {
6638
case (Thicket(name :: _ :: Nil)) :: (imp: Import) :: _ =>
6739
if (name.pos.contains(pos.pos))
68-
completionInfo(name.asInstanceOf[Tree] :: Nil, /* inImport = */ true)
69-
else completionInfo(path, /* inImport = */ true)
40+
CompletionInfo(name.asInstanceOf[Tree] :: Nil, pos, inImport = true)
41+
else CompletionInfo(path, pos, inImport = true)
7042

7143
case (imp: Import) :: _ =>
7244
imp.selectors.find(_.pos.contains(pos.pos)) match {
73-
case None => CompletionInfo(imp.expr.pos.point, "", Mode.Import)
74-
case Some(sel) => completionInfo(sel.asInstanceOf[Tree] :: Nil, /* inImport = */ true)
45+
case None => new CompletionInfo(imp.expr.pos.point, "", Mode.Import)
46+
case Some(sel) => CompletionInfo(sel.asInstanceOf[Tree] :: Nil, pos, inImport = true)
7547
}
7648

7749
case other =>
78-
completionInfo(other, /* inImport = */ false)
50+
CompletionInfo(other, pos, inImport = false)
7951
}
8052

8153
def accessibleMembers(site: Type, superAccess: Boolean = true): Seq[Symbol] = site match {
@@ -177,7 +149,7 @@ object Completion {
177149
* @param prefix A prefix that potential completion results must match.
178150
* @param mode The completion mode.
179151
*/
180-
private case class CompletionInfo(offset: Int, prefix: String, mode: Mode) {
152+
private class CompletionInfo(val offset: Int, val prefix: String, val mode: Mode) {
181153

182154
private[this] val completions = Scopes.newScope.openForMutations
183155

@@ -234,6 +206,36 @@ object Completion {
234206
}
235207
}
236208
}
209+
private object CompletionInfo {
210+
211+
/**
212+
* Extract basic info about completion location and the kind of symbols to include.
213+
*
214+
* @param path The path to the position where completion happens
215+
* @param inImport If set, indicates that this is the completion of an import node. When
216+
* completing imports, both types and terms are always included.
217+
* @return The information about completion (offset, kinds of symbol, etc.)
218+
*/
219+
def apply(path: List[Tree], pos: SourcePosition, inImport: Boolean): CompletionInfo = path match {
220+
case (ref: RefTree) :: _ =>
221+
if (ref.name == nme.ERROR)
222+
new CompletionInfo(ref.pos.point, "", Mode.None)
223+
else {
224+
val mode =
225+
if (inImport) Mode.Import
226+
else if (ref.name.isTermName) Mode.Term
227+
else Mode.Type
228+
229+
new CompletionInfo(
230+
ref.pos.point,
231+
ref.name.toString.take(pos.pos.point - ref.pos.point),
232+
mode)
233+
}
234+
235+
case _ =>
236+
new CompletionInfo(0, "", Mode.None)
237+
}
238+
}
237239

238240
/**
239241
* The completion mode: defines what kinds of symbols should be included in the completion

0 commit comments

Comments
 (0)