@@ -1589,7 +1589,6 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
1589
1589
val visibleDiagnostics =
1590
1590
localClient.diagnostics().takeWhile(! _.getReset).flatMap(_.getDiagnostics.asScala)
1591
1591
1592
- expect(visibleDiagnostics.nonEmpty)
1593
1592
expect(visibleDiagnostics.length == 1 )
1594
1593
1595
1594
val updateActionableDiagnostic = visibleDiagnostics.head
@@ -1625,6 +1624,77 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
1625
1624
}
1626
1625
}
1627
1626
}
1627
+
1628
+ if (actualScalaVersion.startsWith(" 3." ))
1629
+ List (" .sc" , " .scala" ).foreach { filetype =>
1630
+ test(s " bsp should report actionable diagnostic from bloop for $filetype files (Scala 3) " ) {
1631
+ val fileName = s " Hello $filetype"
1632
+ val inputs = TestInputs (
1633
+ os.rel / fileName ->
1634
+ s """
1635
+ |object Hello {
1636
+ | sealed trait TestTrait
1637
+ | case class TestA() extends TestTrait
1638
+ | case class TestB() extends TestTrait
1639
+ | val traitInstance: TestTrait = ???
1640
+ | traitInstance match {
1641
+ | case TestA() =>
1642
+ | }
1643
+ |}
1644
+ | """ .stripMargin
1645
+ )
1646
+ withBsp(inputs, Seq (" ." )) {
1647
+ (_, localClient, remoteServer) =>
1648
+ async {
1649
+ // prepare build
1650
+ val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
1651
+ // build code
1652
+ val targets = buildTargetsResp.getTargets.asScala.map(_.getId()).asJava
1653
+ await(remoteServer.buildTargetCompile(new b.CompileParams (targets)).asScala)
1654
+
1655
+ val visibleDiagnostics =
1656
+ localClient.diagnostics().map(_.getDiagnostics().asScala).find(
1657
+ ! _.isEmpty
1658
+ ).getOrElse(
1659
+ Nil
1660
+ )
1661
+
1662
+ expect(visibleDiagnostics.size == 1 )
1663
+
1664
+ val updateActionableDiagnostic = visibleDiagnostics.head
1665
+
1666
+ checkDiagnostic(
1667
+ diagnostic = updateActionableDiagnostic,
1668
+ expectedMessage = " match may not be exhaustive." ,
1669
+ expectedSeverity = b.DiagnosticSeverity .WARNING ,
1670
+ expectedStartLine = 6 ,
1671
+ expectedStartCharacter = 2 ,
1672
+ expectedEndLine = 6 ,
1673
+ expectedEndCharacter = 15 ,
1674
+ expectedSource = Some (" bloop" ),
1675
+ strictlyCheckMessage = false
1676
+ )
1677
+
1678
+ val scalaDiagnostic = new Gson ().fromJson[b.ScalaDiagnostic ](
1679
+ updateActionableDiagnostic.getData().asInstanceOf [JsonElement ],
1680
+ classOf [b.ScalaDiagnostic ]
1681
+ )
1682
+
1683
+ val actions = scalaDiagnostic.getActions().asScala.toList
1684
+ assert(actions.size == 1 )
1685
+ val changes = actions.head.getEdit().getChanges().asScala.toList
1686
+ assert(changes.size == 1 )
1687
+ val textEdit = changes.head
1688
+
1689
+ expect(textEdit.getNewText().contains(" \n case TestB() => ???" ))
1690
+ expect(textEdit.getRange().getStart.getLine == 7 )
1691
+ expect(textEdit.getRange().getStart.getCharacter == 19 )
1692
+ expect(textEdit.getRange().getEnd.getLine == 7 )
1693
+ expect(textEdit.getRange().getEnd.getCharacter == 19 )
1694
+ }
1695
+ }
1696
+ }
1697
+ }
1628
1698
test(" bsp should support jvmRunEnvironment request" ) {
1629
1699
val inputs = TestInputs (
1630
1700
os.rel / " Hello.scala" ->
@@ -1818,95 +1888,6 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
1818
1888
)
1819
1889
}
1820
1890
1821
- if (actualScalaVersion.startsWith(" 3." ))
1822
- test(" actionable diagnostics from compiler" ) {
1823
- val inputs = TestInputs (
1824
- os.rel / " test.sc" ->
1825
- """ //> using scala 3.3.2-RC1-bin-20230723-5afe621-NIGHTLY
1826
- |def foo(): Int = 23
1827
- |
1828
- |def test: Int = foo
1829
- |// ^^^ error: missing parentheses
1830
- |""" .stripMargin
1831
- )
1832
-
1833
- withBsp(inputs, Seq (" ." )) { (root, localClient, remoteServer) =>
1834
- async {
1835
- val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
1836
- val target = {
1837
- val targets = buildTargetsResp.getTargets.asScala.map(_.getId).toSeq
1838
- expect(targets.length == 2 )
1839
- extractMainTargets(targets)
1840
- }
1841
-
1842
- val targetUri = TestUtil .normalizeUri(target.getUri)
1843
- checkTargetUri(root, targetUri)
1844
-
1845
- val targets = List (target).asJava
1846
-
1847
- val compileResp = await {
1848
- remoteServer
1849
- .buildTargetCompile(new b.CompileParams (targets))
1850
- .asScala
1851
- }
1852
- expect(compileResp.getStatusCode == b.StatusCode .ERROR )
1853
-
1854
- val diagnosticsParams = {
1855
- val diagnostics = localClient.diagnostics()
1856
- val params = diagnostics(2 )
1857
- expect(params.getBuildTarget.getUri == targetUri)
1858
- expect(
1859
- TestUtil .normalizeUri(params.getTextDocument.getUri) ==
1860
- TestUtil .normalizeUri((root / " test.sc" ).toNIO.toUri.toASCIIString)
1861
- )
1862
- params
1863
- }
1864
-
1865
- val diagnostics = diagnosticsParams.getDiagnostics.asScala
1866
- expect(diagnostics.size == 1 )
1867
-
1868
- val theDiagnostic = diagnostics.head
1869
-
1870
- checkDiagnostic(
1871
- diagnostic = theDiagnostic,
1872
- expectedMessage =
1873
- " method foo in class test$_ must be called with () argument" ,
1874
- expectedSeverity = b.DiagnosticSeverity .ERROR ,
1875
- expectedStartLine = 3 ,
1876
- expectedStartCharacter = 16 ,
1877
- expectedEndLine = 3 ,
1878
- expectedEndCharacter = 19
1879
- )
1880
-
1881
- // Shouldn't dataKind be set to "scala"? expect(theDiagnostic.getDataKind == "scala")
1882
-
1883
- val gson = new com.google.gson.Gson ()
1884
-
1885
- val scalaDiagnostic : b.ScalaDiagnostic = gson.fromJson(
1886
- theDiagnostic.getData.toString,
1887
- classOf [b.ScalaDiagnostic ]
1888
- )
1889
-
1890
- val actions = scalaDiagnostic.getActions.asScala
1891
- expect(actions.size == 1 )
1892
-
1893
- val action = actions.head
1894
- expect(action.getTitle == " Insert ()" )
1895
-
1896
- val edit = action.getEdit
1897
- expect(edit.getChanges.asScala.size == 1 )
1898
- val change = edit.getChanges.asScala.head
1899
-
1900
- val expectedRange = new b.Range (
1901
- new b.Position (9 , 19 ),
1902
- new b.Position (9 , 19 )
1903
- )
1904
- expect(change.getRange == expectedRange)
1905
- expect(change.getNewText == " ()" )
1906
- }
1907
- }
1908
- }
1909
-
1910
1891
if (! actualScalaVersion.startsWith(" 2.12" ))
1911
1892
test(" actionable diagnostics on deprecated using directives" ) {
1912
1893
val inputs = TestInputs (
@@ -2074,7 +2055,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
2074
2055
params
2075
2056
}
2076
2057
2077
- private def checkDiagnostic (
2058
+ protected def checkDiagnostic (
2078
2059
diagnostic : b.Diagnostic ,
2079
2060
expectedMessage : String ,
2080
2061
expectedSeverity : b.DiagnosticSeverity ,
@@ -2090,10 +2071,11 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
2090
2071
expect(diagnostic.getRange.getStart.getCharacter == expectedStartCharacter)
2091
2072
expect(diagnostic.getRange.getEnd.getLine == expectedEndLine)
2092
2073
expect(diagnostic.getRange.getEnd.getCharacter == expectedEndCharacter)
2074
+ val message = TestUtil .removeAnsiColors(diagnostic.getMessage)
2093
2075
if (strictlyCheckMessage)
2094
- assertNoDiff(diagnostic.getMessage , expectedMessage)
2076
+ assertNoDiff(message , expectedMessage)
2095
2077
else
2096
- expect(diagnostic.getMessage .contains(expectedMessage))
2078
+ expect(message .contains(expectedMessage))
2097
2079
for (es <- expectedSource)
2098
2080
expect(diagnostic.getSource == es)
2099
2081
}
0 commit comments