11package dotty .tools .pc .tests
22
3- import java .net .URI
4- import scala .meta .internal .jdk .CollectionConverters .*
5- import scala .meta .internal .metals .EmptyCancelToken
6- import scala .meta .pc .VirtualFileParams
7- import scala .meta .pc .CancelToken
8-
9- import org .junit .Test
10- import org .eclipse .lsp4j .DiagnosticSeverity
11- import dotty .tools .pc .utils .TestExtensions .getOffset
12- import dotty .tools .pc .base .TestResources
13- import java .nio .file .Path
14- import dotty .tools .pc .RawScalaPresentationCompiler
15- import dotty .tools .pc .utils .PcAssertions
16- import org .eclipse .lsp4j .Diagnostic
3+ import dotty .tools .pc .base .BaseDiagnosticsSuite
174import org .eclipse .lsp4j .CodeAction
5+ import org .eclipse .lsp4j .Diagnostic
6+ import org .eclipse .lsp4j .DiagnosticSeverity
7+ import org .junit .Test
188
19- class DiagnosticProviderSuite extends PcAssertions {
20- case class TestDiagnostic (startIndex : Int , endIndex : Int , msg : String , severity : DiagnosticSeverity )
21-
22- val pc = RawScalaPresentationCompiler ().newInstance(" " , TestResources .classpath.asJava, Nil .asJava)
23-
24- case class TestVirtualFileParams (uri : URI , text : String ) extends VirtualFileParams {
25- override def shouldReturnDiagnostics : Boolean = true
26- override def token : CancelToken = EmptyCancelToken
27- }
28-
29- def check (
30- text : String ,
31- expected : List [TestDiagnostic ],
32- additionalChecks : List [Diagnostic ] => Unit = identity
33- ): Unit =
34- val diagnostics = pc
35- .didChange(TestVirtualFileParams (URI .create(" file:/Diagnostic.scala" ), text))
36- .asScala
9+ import java .net .URI
10+ import scala .meta .internal .jdk .CollectionConverters .*
3711
38- val actual = diagnostics.map(d => TestDiagnostic (d.getRange().getStart().getOffset(text), d.getRange().getEnd().getOffset(text), d.getMessage(), d.getSeverity()))
39- assertEquals(expected, actual, s " Expected [ ${expected.mkString(" , " )}] but got [ ${actual.mkString(" , " )}] " )
40- additionalChecks(diagnostics.toList)
12+ class DiagnosticProviderSuite extends BaseDiagnosticsSuite {
4113
4214 @ Test def error =
4315 check(
4416 """ |object M:
4517 | Int.maaxValue
4618 |""" .stripMargin,
47- List (TestDiagnostic (12 ,25 , " value maaxValue is not a member of object Int - did you mean Int.MaxValue?" , DiagnosticSeverity .Error ))
19+ List (
20+ TestDiagnostic (
21+ 12 ,
22+ 25 ,
23+ " value maaxValue is not a member of object Int - did you mean Int.MaxValue?" ,
24+ DiagnosticSeverity .Error
25+ )
26+ )
4827 )
4928
5029 @ Test def warning =
5130 check(
5231 """ |object M:
5332 | 1 + 1
5433 |""" .stripMargin,
55- List (TestDiagnostic (12 , 17 , " A pure expression does nothing in statement position" , DiagnosticSeverity .Warning ))
34+ List (
35+ TestDiagnostic (
36+ 12 ,
37+ 17 ,
38+ " A pure expression does nothing in statement position" ,
39+ DiagnosticSeverity .Warning
40+ )
41+ )
5642 )
5743
5844 @ Test def mixed =
@@ -62,8 +48,18 @@ class DiagnosticProviderSuite extends PcAssertions {
6248 | 1 + 1
6349 |""" .stripMargin,
6450 List (
65- TestDiagnostic (12 ,25 , " value maaxValue is not a member of object Int - did you mean Int.MaxValue?" , DiagnosticSeverity .Error ),
66- TestDiagnostic (28 , 33 , " A pure expression does nothing in statement position" , DiagnosticSeverity .Warning )
51+ TestDiagnostic (
52+ 12 ,
53+ 25 ,
54+ " value maaxValue is not a member of object Int - did you mean Int.MaxValue?" ,
55+ DiagnosticSeverity .Error
56+ ),
57+ TestDiagnostic (
58+ 28 ,
59+ 33 ,
60+ " A pure expression does nothing in statement position" ,
61+ DiagnosticSeverity .Warning
62+ )
6763 )
6864 )
6965
@@ -73,12 +69,29 @@ class DiagnosticProviderSuite extends PcAssertions {
7369 | private private class Test
7470 |""" .stripMargin,
7571 List (
76- TestDiagnostic (20 , 27 , " Repeated modifier private" , DiagnosticSeverity .Error ),
72+ TestDiagnostic (
73+ 20 ,
74+ 27 ,
75+ " Repeated modifier private" ,
76+ DiagnosticSeverity .Error
77+ )
7778 ),
7879 diags =>
79- val action = diags.head.getData().asInstanceOf [java.util.List [CodeAction ]].asScala.head
80- assertWithDiff(" Remove repeated modifier: \" private\" " , action.getTitle(), false )
81- assertEquals(1 , action.getEdit().getChanges().size(), " There should be one change" )
80+ val action = diags.head
81+ .getData()
82+ .asInstanceOf [java.util.List [CodeAction ]]
83+ .asScala
84+ .head
85+ assertWithDiff(
86+ " Remove repeated modifier: \" private\" " ,
87+ action.getTitle(),
88+ false
89+ )
90+ assertEquals(
91+ 1 ,
92+ action.getEdit().getChanges().size(),
93+ " There should be one change"
94+ )
8295 )
8396
8497}
0 commit comments