Skip to content

Commit dbce4e8

Browse files
authored
Backport changes for the presentation compiler from Metals (#21756)
2 parents fd0548e + 87db0da commit dbce4e8

File tree

8 files changed

+51
-20
lines changed

8 files changed

+51
-20
lines changed

presentation-compiler/src/main/dotty/tools/pc/CompilerSearchVisitor.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CompilerSearchVisitor(
2828
owner.isStatic && owner.isPublic
2929

3030
private def isAccessible(sym: Symbol): Boolean = try
31-
sym != NoSymbol && sym.isPublic && sym.isStatic || isAccessibleImplicitClass(sym)
31+
(sym != NoSymbol && sym.isAccessibleFrom(ctx.owner.info) && sym.isStatic) || isAccessibleImplicitClass(sym)
3232
catch
3333
case err: AssertionError =>
3434
logger.log(Level.WARNING, err.getMessage())

presentation-compiler/src/main/dotty/tools/pc/PcDefinitionProvider.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ class PcDefinitionProvider(
131131
otherDefs.headOption.orElse(exportedDefs.headOption) match
132132
case Some(srcTree) =>
133133
val pos = srcTree.namePos
134-
pos.toLocation match
135-
case None => DefinitionResultImpl.empty
136-
case Some(loc) =>
134+
if pos.exists then
135+
val loc = new Location(params.uri().toString(), pos.toLsp)
137136
DefinitionResultImpl(
138137
SemanticdbSymbols.symbolName(sym),
139-
List(loc).asJava
138+
List(loc).asJava,
140139
)
140+
else DefinitionResultImpl.empty
141141
case None =>
142142
DefinitionResultImpl.empty
143143
else

presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ class ShortenedTypePrinter(
527527
else if includeDefaultParam == ShortenedTypePrinter.IncludeDefaultParam.ResolveLater && isDefaultParam
528528
then " = ..."
529529
else "" // includeDefaultParam == Never or !isDefaultParam
530-
s"$keywordName: ${paramTypeString}$default"
530+
val inline = if(param.is(Flags.Inline)) "inline " else ""
531+
s"$inline$keywordName: ${paramTypeString}$default"
531532
end if
532533
end paramLabel
533534

presentation-compiler/src/main/dotty/tools/pc/utils/InteractiveEnrichments.scala

-6
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ object InteractiveEnrichments extends CommonMtagsEnrichments:
9999
def focusAt(point: Int): SourcePosition =
100100
pos.withSpan(pos.span.withPoint(point).focus)
101101

102-
def toLocation: Option[l.Location] =
103-
for
104-
uri <- InteractiveDriver.toUriOption(pos.source)
105-
range <- if pos.exists then Some(pos.toLsp) else None
106-
yield new l.Location(uri.toString(), range)
107-
108102
def encloses(other: SourcePosition): Boolean =
109103
pos.start <= other.start && pos.end >= other.end
110104

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
796796
| def k: Int = m(1, a@@)
797797
|""".stripMargin,
798798
"""|aaa = : Int
799-
|assert(assertion: Boolean): Unit
799+
|assert(inline assertion: Boolean): Unit
800800
|""".stripMargin,
801801
topLines = Some(2),
802802
)
@@ -810,7 +810,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
810810
| def k: Int = m(inn = 1, a@@)
811811
|""".stripMargin,
812812
"""|aaa = : Int
813-
|assert(assertion: Boolean): Unit
813+
|assert(inline assertion: Boolean): Unit
814814
|""".stripMargin,
815815
topLines = Some(2),
816816
)
@@ -912,7 +912,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
912912
|""".stripMargin,
913913
"""|aaa = : Int
914914
|abb = : Option[Int]
915-
|assert(assertion: Boolean): Unit
915+
|assert(inline assertion: Boolean): Unit
916916
|""".stripMargin,
917917
topLines = Some(3),
918918
)
@@ -927,7 +927,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
927927
|""".stripMargin,
928928
"""|aaa = : Int
929929
|abb = : Option[Int]
930-
|assert(assertion: Boolean): Unit
930+
|assert(inline assertion: Boolean): Unit
931931
|""".stripMargin,
932932
topLines = Some(3),
933933
)
@@ -945,7 +945,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
945945
|""".stripMargin,
946946
"""|aaa = : Int
947947
|abb = : Option[Int]
948-
|assert(assertion: Boolean): Unit
948+
|assert(inline assertion: Boolean): Unit
949949
|""".stripMargin,
950950
topLines = Some(3),
951951
)
@@ -963,7 +963,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
963963
|""".stripMargin,
964964
"""|abb = : Option[Int]
965965
|acc = : List[Int]
966-
|assert(assertion: Boolean): Unit
966+
|assert(inline assertion: Boolean): Unit
967967
|""".stripMargin,
968968
topLines = Some(3),
969969
)

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionCancelSuite.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ class CompletionCancelSuite extends BaseCompletionSuite:
9090
| val x = asser@@
9191
|}
9292
""".stripMargin,
93-
"""|assert(assertion: Boolean): Unit
94-
|assert(assertion: Boolean, message: => Any): Unit
93+
"""|assert(inline assertion: Boolean): Unit
94+
|assert(inline assertion: Boolean, inline message: => Any): Unit
9595
|""".stripMargin
9696
)
9797

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSnippetSuite.scala

+23
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,29 @@ class CompletionSnippetSuite extends BaseCompletionSuite:
385385
)
386386

387387
@Test def `no-apply` =
388+
checkSnippet(
389+
s"""|package example
390+
|
391+
|object Widget{}
392+
|object Main {
393+
| Wi@@
394+
|}
395+
|""".stripMargin,
396+
"""|Widget - example
397+
|Window - java.awt
398+
|WindowPeer - java.awt.peer
399+
|WithFilter - [A](p: A => Boolean, xs: Array[A]): WithFilter[A]
400+
|WithFilter - [A, CC[_$$2]](self: IterableOps[A, CC, ?], p: A => Boolean): WithFilter[A, CC]
401+
|WithFilter - [K, V, IterableCC[_$$3], CC[_$$4,_$$5] <: IterableOps[?, AnyConstr, ?]](self: MapOps[K, V, CC, ?] & IterableOps[(K, V), IterableCC, ?], p: ((K, V)) => Boolean): WithFilter[K, V, IterableCC, CC]
402+
|WithFilter - [K, V, IterableCC[_$$1], MapCC[X,Y] <: scala.collection.Map[X, Y], CC[X,Y] <: scala.collection.Map[X, Y] & SortedMapOps[X, Y, CC, ?]](self: SortedMapOps[K, V, CC, ?] & MapOps[K, V, MapCC, ?] & IterableOps[(K, V), IterableCC, ?], p: ((K, V)) => Boolean): WithFilter[K, V, IterableCC, MapCC, CC]
403+
|WithFilter - [A, IterableCC[_$$1], CC[X] <: SortedSet[X]](self: SortedSetOps[A, CC, ?] & IterableOps[A, IterableCC, ?], p: A => Boolean): WithFilter[A, IterableCC, CC]
404+
|WithFilter - (p: Char => Boolean, s: String): WithFilter
405+
|WithFilter - [A](l: Stream[A] @uncheckedVariance, p: A => Boolean): WithFilter[A]
406+
|""".stripMargin,
407+
includeDetail = true,
408+
)
409+
410+
@Test def `no-apply2` =
388411
checkSnippet(
389412
s"""|package example
390413
|

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala

+13
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,19 @@ class CompletionSuite extends BaseCompletionSuite:
21072107
|""".stripMargin
21082108
)
21092109

2110+
@Test def `shadowing` =
2111+
check(
2112+
"""|package pkg
2113+
|object Main {
2114+
| val x = ListBuff@@
2115+
|}
2116+
|""".stripMargin,
2117+
"""|ListBuffer[A](elems: A*): ListBuffer[A] - scala.collection.mutable
2118+
|new ListBuffer[A]: ListBuffer[A] - scala.collection.mutable
2119+
|ListBuffer - scala.collection.mutable
2120+
|""".stripMargin
2121+
)
2122+
21102123
@Test def `conflict-edit-2` =
21112124
checkEdit(
21122125
"""|package a

0 commit comments

Comments
 (0)