Skip to content

Commit 3e96c0f

Browse files
committed
Address review comments
1 parent 0519aca commit 3e96c0f

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

compiler/src/dotty/tools/dotc/config/Printers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object Printers {
2424
val implicits: Printer = noPrinter
2525
val implicitsDetailed: Printer = noPrinter
2626
val inlining: Printer = noPrinter
27-
val interactiv: Printer = new Printer
27+
val interactiv: Printer = noPrinter
2828
val overload: Printer = noPrinter
2929
val patmatch: Printer = noPrinter
3030
val pickling: Printer = noPrinter

compiler/src/dotty/tools/dotc/core/Symbols.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ object Symbols {
667667
case None =>
668668
val idSet = mutable.SortedSet[String]()
669669
tree.foreachSubTree {
670-
case tree: tpd.NameTree => idSet += tree.name.toString
670+
case tree: tpd.NameTree if tree.name.isInstanceOf[SimpleName] => idSet += tree.name.toString
671671
case _ =>
672672
}
673673
val ids = idSet.toArray

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ object Interactive {
8484

8585
( sym == tree.symbol
8686
|| sym.exists && sym == sourceSymbol(tree.symbol)
87-
|| include != 0 && sym.name == tree.symbol.name && sym.owner != tree.symbol.owner
87+
|| include != 0 && sym.name == tree.symbol.name && sym.maybeOwner != tree.symbol.maybeOwner
8888
&& ( (include & Include.overridden) != 0 && overrides(sym, tree.symbol)
8989
|| (include & Include.overriding) != 0 && overrides(tree.symbol, sym)
9090
)
@@ -99,6 +99,7 @@ object Interactive {
9999
* @return offset and list of symbols for possible completions
100100
*/
101101
// deprecated
102+
// FIXME: Remove this method
102103
def completions(trees: List[SourceTree], pos: SourcePosition)(implicit ctx: Context): (Int, List[Symbol]) = {
103104
val path = pathTo(trees, pos)
104105
val boundary = enclosingDefinitionInPath(path).symbol
@@ -148,14 +149,17 @@ object Interactive {
148149
ref.name.isTermName,
149150
ref.name.isTypeName)
150151
case _ =>
151-
println(i"COMPUTE from ${path.headOption}")
152152
(0, "", false, false)
153153
}
154154

155155
/** Include in completion sets only symbols that
156-
* - start with given name prefix
157-
* - do not contain '$' except in prefix where it is explicitly written by user
158-
* - have same term/type kind as name prefix given so far
156+
* 1. start with given name prefix, and
157+
* 2. do not contain '$' except in prefix where it is explicitly written by user, and
158+
* 3. have same term/type kind as name prefix given so far
159+
*
160+
* The reason for (2) is that we do not want to present compiler-synthesized identifiers
161+
* as completion results. However, if a user explicitly writes all '$' characters in an
162+
* identifier, we should complete the rest.
159163
*/
160164
def include(sym: Symbol) =
161165
sym.name.startsWith(prefix) &&
@@ -197,7 +201,9 @@ object Interactive {
197201
addMember(imp.site, name)
198202
addMember(imp.site, name.toTypeName)
199203
}
200-
for (renamed <- imp.reverseMapping.keys) addImport(renamed)
204+
// FIXME: We need to also take renamed items into account for completions,
205+
// That means we have to return list of a pairs (Name, Symbol) instead of a list
206+
// of symbols from `completions`.!=
201207
for (imported <- imp.originals if !imp.excluded.contains(imported)) addImport(imported)
202208
if (imp.isWildcardImport)
203209
for (mbr <- accessibleMembers(imp.site) if !imp.excluded.contains(mbr.name.toTermName))
@@ -209,8 +215,7 @@ object Interactive {
209215
implicit val ctx = ictx
210216

211217
if (ctx.owner.isClass) {
212-
for (mbr <- accessibleMembers(ctx.owner.thisType))
213-
addMember(ctx.owner.thisType, mbr.name)
218+
addAccessibleMembers(ctx.owner.thisType)
214219
ctx.owner.asClass.classInfo.selfInfo match {
215220
case selfSym: Symbol => add(selfSym)
216221
case _ =>
@@ -391,7 +396,7 @@ object Interactive {
391396
}
392397
localCtx
393398
case tree @ Template(constr, parents, self, _) =>
394-
if ((constr :: self :: parents).exists(nested `eq` _)) ctx
399+
if ((constr :: self :: parents).contains(nested)) ctx
395400
else contextOfStat(tree.body, nested, tree.symbol, outer.inClassContext(self.symbol))
396401
case _ =>
397402
outer

language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala

+13-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,19 @@ class DottyLanguageServer extends LanguageServer
6565

6666
myDrivers = new mutable.HashMap
6767
for (config <- configs) {
68-
val classpathFlags = List("-classpath", (config.classDirectory +: config.dependencyClasspath).mkString(File.pathSeparator))
69-
val sourcepathFlags = List("-sourcepath", config.sourceDirectories.mkString(File.pathSeparator), "-scansource")
70-
val settings = defaultFlags ++ config.compilerArguments.toList ++ classpathFlags ++ sourcepathFlags
68+
implicit class updateDeco(ss: List[String]): List[String] {
69+
def update(pathKind: String, pathInfo: String) = {
70+
val idx = ss.indexOf(pathKind)
71+
val ss1 = if (idx >= 0) ss.take(idx) ++ ss.drop(idx + 2) else ss
72+
ss1 ++ List(pathKind, pathInfo)
73+
}
74+
}
75+
val settings =
76+
defaultFlags ++
77+
config.compilerArguments.toList
78+
.update("-classpath", (config.classDirectory +: config.dependencyClasspath).mkString(File.pathSeparator))
79+
.update("-sourcepath", config.sourceDirectories.mkString(File.pathSeparator)) :+
80+
"-scansource"
7181
myDrivers.put(config, new InteractiveDriver(settings))
7282
}
7383
}

0 commit comments

Comments
 (0)