@@ -24,6 +24,7 @@ import dotty.tools.dotc.printing.Texts._
24
24
import dotty .tools .dotc .util .{NameTransformer , NoSourcePosition , SourcePosition }
25
25
26
26
import scala .collection .mutable
27
+ import scala .util .control .NonFatal
27
28
28
29
/**
29
30
* One of the results of a completion query.
@@ -61,6 +62,8 @@ object Completion {
61
62
*/
62
63
def completionMode (path : List [Tree ], pos : SourcePosition ): Mode =
63
64
path match {
65
+ case Ident (_) :: Import (_, _) :: _ =>
66
+ Mode .Import
64
67
case (ref : RefTree ) :: _ =>
65
68
if (ref.name.isTermName) Mode .Term
66
69
else if (ref.name.isTypeName) Mode .Type
@@ -211,13 +214,35 @@ object Completion {
211
214
// import a.C
212
215
def isSameSymbolImportedDouble = denotss.forall(_.denots == first.denots)
213
216
217
+ def isScalaPackage (scopedDenots : ScopedDenotations ) =
218
+ scopedDenots.denots.exists(_.info.typeSymbol.owner == defn.ScalaPackageClass )
219
+
220
+ def isJavaLangPackage (scopedDenots : ScopedDenotations ) =
221
+ scopedDenots.denots.exists(_.info.typeSymbol.owner == defn.JavaLangPackageClass )
222
+
223
+ // For example
224
+ // import java.lang.annotation
225
+ // is shadowed by
226
+ // import scala.annotation
227
+ def isJavaLangAndScala =
228
+ try
229
+ denotss.forall(denots => isScalaPackage(denots) || isJavaLangPackage(denots))
230
+ catch
231
+ case NonFatal (_) => false
232
+
214
233
denotss.find(! _.ctx.isImportContext) match {
215
234
// most deeply nested member or local definition if not shadowed by an import
216
235
case Some (local) if local.ctx.scope == first.ctx.scope =>
217
236
resultMappings += name -> local.denots
218
237
219
238
case None if isSingleImport || isImportedInDifferentScope || isSameSymbolImportedDouble =>
220
239
resultMappings += name -> first.denots
240
+ case None if isJavaLangAndScala =>
241
+ denotss.foreach{
242
+ denots =>
243
+ if isScalaPackage(denots) then
244
+ resultMappings += name -> denots.denots
245
+ }
221
246
222
247
case _ =>
223
248
}
0 commit comments