Skip to content

Commit

Permalink
bugfix: Fix issues with recent nightlies
Browse files Browse the repository at this point in the history
It seems in the recent nightlies the package will always be printed out, so instead I changed toTextRef to work around it.
  • Loading branch information
tgodzik committed Jun 22, 2023
1 parent f7b9984 commit 2293c95
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,22 @@ object DotcPrinter:
*/
private def printPrefix(tp: Type): Text = homogenize(tp) match
case NoPrefix => ""
case tp: SingletonType => toTextRef(tp) ~ "."
case tp: SingletonType =>
toTextRef(tp) ~ "."
case tp => trimPrefix(toTextLocal(tp)) ~ "#"

def fullName(sym: Symbol): String =
fullNameString(sym)

override def toTextRef(tp: SingletonType): Text = controlled {
tp match
case tp: TermRef if !printDebug && tp.symbol.is(Package) =>
toTextPrefix(tp.prefix) ~
tp.symbol.name.stripModuleClassSuffix.toString()
case _ =>
super.toTextRef(tp)
}

override def toText(tp: Type): Text =
// Override the behavior for `AppliedType` because
// `toText` in RefinedPrinter doesn't pretty print AppliedType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class ShortenedNames(
true
else false
case founds =>
founds.exists(s =>
founds.exists { s =>
s == short.symbol || s.typeRef.metalsDealias.typeSymbol == short.symbol
)
}
if isOk then
history(short.name) = short
true
Expand Down
28 changes: 2 additions & 26 deletions tests/cross/src/test/scala/tests/pc/CompletionDocSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,9 @@ class CompletionDocSuite extends BaseCompletionSuite {
|Try[T](r: => T): Try[T]""".stripMargin
),
)

check(
"scala7",
"scala7".tag(IgnoreScalaVersion(ver => ver.contains("NIGHTLY"))),
"""
|object A {
| scala.collection.mutable.StringBuilder@@
Expand Down Expand Up @@ -561,31 +562,6 @@ class CompletionDocSuite extends BaseCompletionSuite {
|StringBuilder(capacity: Int): StringBuilder
|StringBuilder(initCapacity: Int, initValue: String): StringBuilder
|""".stripMargin,
"2.13.11" ->
"""|> A builder of `String` which is also a mutable sequence of characters.
|
| This class provides an API mostly compatible with `java.lang.StringBuilder`,
| except where there are conflicts with the Scala collections API, such as the `reverse` method:
| [reverse](reverse) produces a new `StringBuilder`, and [reverseInPlace](reverseInPlace) mutates this builder.
|
| Mutating operations return either `this.type`, i.e., the current builder, or `Unit`.
|
| Other methods extract data or information from the builder without mutating it.
|
| The distinction is also reflected in naming conventions used by collections,
| such as `append`, which mutates, and `appended`, which does not, or `reverse`,
| which does not mutate, and `reverseInPlace`, which does.
|
| The `String` result may be obtained using either `result()` or `toString`.
|
| $multipleResults
|
|
|**See**
|- ["Scala's Collection Library overview"](https://docs.scala-lang.org/overviews/collections-2.13/concrete-mutable-collection-classes.html#stringbuilders)
| section on `StringBuilders` for more information.
|StringBuilder scala.collection.mutable
|""".stripMargin,
),
)

Expand Down
21 changes: 20 additions & 1 deletion tests/cross/src/test/scala/tests/pc/CompletionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,14 @@ class CompletionSuite extends BaseCompletionSuite {
|""".stripMargin,
)

val pre331: String =
"""|dynamics scala.languageFeature
|existentials scala.languageFeature
|experimental scala.languageFeature
|higherKinds scala.languageFeature
|implicitConversions scala.languageFeature
|""".stripMargin

check(
"ordering-1",
s"""|object Main {
Expand All @@ -1265,7 +1273,18 @@ class CompletionSuite extends BaseCompletionSuite {
|experimental scala.languageFeature
|implicitConversions scala.languageFeature
|postfixOps scala.languageFeature
|""".stripMargin
|""".stripMargin,
"3.2" -> pre331,
"3.1" -> pre331,
"3.3.0" -> pre331,
"3.3.1" -> pre331,
"3" ->
"""|dynamics languageFeature
|existentials languageFeature
|experimental languageFeature
|higherKinds languageFeature
|implicitConversions languageFeature
|""".stripMargin,
),
)

Expand Down
57 changes: 31 additions & 26 deletions tests/cross/src/test/scala/tests/pc/SignatureHelpDocSuite.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tests.pc

import tests.BaseSignatureHelpSuite
import scala.meta.internal.mtags.BuildInfo

class SignatureHelpDocSuite extends BaseSignatureHelpSuite {

Expand Down Expand Up @@ -134,7 +133,13 @@ class SignatureHelpDocSuite extends BaseSignatureHelpSuite {
),
)

val addedSpace = if (BuildInfo.scalaCompilerVersion == "2.13.11") "" else " "
val addedSpace =
if (
scalaVersion == "2.13.11" ||
(scalaVersion.startsWith("3.3") &&
!(scalaVersion.startsWith("3.3.0") || scalaVersion.startsWith("3.3.1")))
) ""
else " "
checkDoc(
"curry3",
"""
Expand Down Expand Up @@ -200,30 +205,30 @@ class SignatureHelpDocSuite extends BaseSignatureHelpSuite {
| @param op (Int, Int) => Int
|""".stripMargin,
"3" ->
"""|Applies a binary operator to a start value and all elements of this collection,
| going left to right.
|
| Note: will not terminate for infinite-sized collections.
| Note: might return different results for different runs, unless the
|underlying collection type is ordered or the operator is associative
|and commutative.
|
|
|**Type Parameters**
|- `B`: the result type of the binary operator.
|
|**Parameters**
|- `z`: the start value.
|- `op`: the binary operator.
|
|**Returns:** the result of inserting `op` between consecutive elements of this collection,
| going left to right with the start value `z` on the left:
| `op(...op(z, x), x, ..., x)` where `x, ..., x`
| are the elements of this collection.
| Returns `z` if this collection is empty.
|foldLeft[B](z: B)(op: (B, Int) => B): B
| ^^^^^^^^^^^^^^^^^
|""".stripMargin,
s"""|Applies a binary operator to a start value and all elements of this collection,
| going left to right.
|
| Note: will not terminate for infinite-sized collections.
| Note: might return different results for different runs, unless the
|underlying collection type is ordered or the operator is associative
|and commutative.
|
|
|**Type Parameters**
|- `B`: the result type of the binary operator.
|
|**Parameters**
|- `z`: the start value.
|- `op`: the binary operator.
|
|**Returns:** the result of inserting `op` between consecutive elements of this collection,
| going left to right with the start value `z` on the left:
| `op(...op(z, x), x, ..., x)` where `x, ..., x`
| ${addedSpace}are the elements of this collection.
| Returns `z` if this collection is empty.
|foldLeft[B](z: B)(op: (B, Int) => B): B
| ^^^^^^^^^^^^^^^^^
|""".stripMargin,
),
)

Expand Down

0 comments on commit 2293c95

Please sign in to comment.