Skip to content

Commit

Permalink
Backport changes for the presentation compiler from Metals (#21756)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik authored Oct 14, 2024
2 parents fd0548e + 87db0da commit dbce4e8
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CompilerSearchVisitor(
owner.isStatic && owner.isPublic

private def isAccessible(sym: Symbol): Boolean = try
sym != NoSymbol && sym.isPublic && sym.isStatic || isAccessibleImplicitClass(sym)
(sym != NoSymbol && sym.isAccessibleFrom(ctx.owner.info) && sym.isStatic) || isAccessibleImplicitClass(sym)
catch
case err: AssertionError =>
logger.log(Level.WARNING, err.getMessage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ class PcDefinitionProvider(
otherDefs.headOption.orElse(exportedDefs.headOption) match
case Some(srcTree) =>
val pos = srcTree.namePos
pos.toLocation match
case None => DefinitionResultImpl.empty
case Some(loc) =>
if pos.exists then
val loc = new Location(params.uri().toString(), pos.toLsp)
DefinitionResultImpl(
SemanticdbSymbols.symbolName(sym),
List(loc).asJava
List(loc).asJava,
)
else DefinitionResultImpl.empty
case None =>
DefinitionResultImpl.empty
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ class ShortenedTypePrinter(
else if includeDefaultParam == ShortenedTypePrinter.IncludeDefaultParam.ResolveLater && isDefaultParam
then " = ..."
else "" // includeDefaultParam == Never or !isDefaultParam
s"$keywordName: ${paramTypeString}$default"
val inline = if(param.is(Flags.Inline)) "inline " else ""
s"$inline$keywordName: ${paramTypeString}$default"
end if
end paramLabel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ object InteractiveEnrichments extends CommonMtagsEnrichments:
def focusAt(point: Int): SourcePosition =
pos.withSpan(pos.span.withPoint(point).focus)

def toLocation: Option[l.Location] =
for
uri <- InteractiveDriver.toUriOption(pos.source)
range <- if pos.exists then Some(pos.toLsp) else None
yield new l.Location(uri.toString(), range)

def encloses(other: SourcePosition): Boolean =
pos.start <= other.start && pos.end >= other.end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
| def k: Int = m(1, a@@)
|""".stripMargin,
"""|aaa = : Int
|assert(assertion: Boolean): Unit
|assert(inline assertion: Boolean): Unit
|""".stripMargin,
topLines = Some(2),
)
Expand All @@ -810,7 +810,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
| def k: Int = m(inn = 1, a@@)
|""".stripMargin,
"""|aaa = : Int
|assert(assertion: Boolean): Unit
|assert(inline assertion: Boolean): Unit
|""".stripMargin,
topLines = Some(2),
)
Expand Down Expand Up @@ -912,7 +912,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
|""".stripMargin,
"""|aaa = : Int
|abb = : Option[Int]
|assert(assertion: Boolean): Unit
|assert(inline assertion: Boolean): Unit
|""".stripMargin,
topLines = Some(3),
)
Expand All @@ -927,7 +927,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
|""".stripMargin,
"""|aaa = : Int
|abb = : Option[Int]
|assert(assertion: Boolean): Unit
|assert(inline assertion: Boolean): Unit
|""".stripMargin,
topLines = Some(3),
)
Expand All @@ -945,7 +945,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
|""".stripMargin,
"""|aaa = : Int
|abb = : Option[Int]
|assert(assertion: Boolean): Unit
|assert(inline assertion: Boolean): Unit
|""".stripMargin,
topLines = Some(3),
)
Expand All @@ -963,7 +963,7 @@ class CompletionArgSuite extends BaseCompletionSuite:
|""".stripMargin,
"""|abb = : Option[Int]
|acc = : List[Int]
|assert(assertion: Boolean): Unit
|assert(inline assertion: Boolean): Unit
|""".stripMargin,
topLines = Some(3),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class CompletionCancelSuite extends BaseCompletionSuite:
| val x = asser@@
|}
""".stripMargin,
"""|assert(assertion: Boolean): Unit
|assert(assertion: Boolean, message: => Any): Unit
"""|assert(inline assertion: Boolean): Unit
|assert(inline assertion: Boolean, inline message: => Any): Unit
|""".stripMargin
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,29 @@ class CompletionSnippetSuite extends BaseCompletionSuite:
)

@Test def `no-apply` =
checkSnippet(
s"""|package example
|
|object Widget{}
|object Main {
| Wi@@
|}
|""".stripMargin,
"""|Widget - example
|Window - java.awt
|WindowPeer - java.awt.peer
|WithFilter - [A](p: A => Boolean, xs: Array[A]): WithFilter[A]
|WithFilter - [A, CC[_$$2]](self: IterableOps[A, CC, ?], p: A => Boolean): WithFilter[A, CC]
|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]
|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]
|WithFilter - [A, IterableCC[_$$1], CC[X] <: SortedSet[X]](self: SortedSetOps[A, CC, ?] & IterableOps[A, IterableCC, ?], p: A => Boolean): WithFilter[A, IterableCC, CC]
|WithFilter - (p: Char => Boolean, s: String): WithFilter
|WithFilter - [A](l: Stream[A] @uncheckedVariance, p: A => Boolean): WithFilter[A]
|""".stripMargin,
includeDetail = true,
)

@Test def `no-apply2` =
checkSnippet(
s"""|package example
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,19 @@ class CompletionSuite extends BaseCompletionSuite:
|""".stripMargin
)

@Test def `shadowing` =
check(
"""|package pkg
|object Main {
| val x = ListBuff@@
|}
|""".stripMargin,
"""|ListBuffer[A](elems: A*): ListBuffer[A] - scala.collection.mutable
|new ListBuffer[A]: ListBuffer[A] - scala.collection.mutable
|ListBuffer - scala.collection.mutable
|""".stripMargin
)

@Test def `conflict-edit-2` =
checkEdit(
"""|package a
Expand Down

0 comments on commit dbce4e8

Please sign in to comment.