Skip to content

Commit 2f1d6d4

Browse files
committed
nit: Improve formatting of changes files
1 parent f989032 commit 2f1d6d4

File tree

4 files changed

+104
-34
lines changed

4 files changed

+104
-34
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ class DiagnosticProvider(driver: InteractiveDriver, params: VirtualFileParams):
2424

2525
private def toLsp(diag: Diagnostic)(using Context): Option[lsp4j.Diagnostic] =
2626
Option.when(diag.pos.exists):
27-
val message =
28-
if Diagnostic.shouldExplain(diag) then
29-
diag.msg.message + "\n\n# Explanation (enabled by `-explain`)\n\n" + diag.msg.explanation
30-
else diag.msg.message
27+
val explanation =
28+
if Diagnostic.shouldExplain(diag)
29+
then
30+
"\n\n# Explanation (enabled by `-explain`)\n\n" + diag.msg.explanation
31+
else ""
3132
val lspDiag = lsp4j.Diagnostic(
3233
diag.pos.toLsp,
33-
message,
34+
diag.msg.message + explanation,
3435
toDiagnosticSeverity(diag.level),
35-
"presentation compiler",
36+
"presentation compiler"
3637
)
3738
lspDiag.setCode(diag.msg.errorId.errorNumber)
3839

@@ -48,7 +49,8 @@ class DiagnosticProvider(driver: InteractiveDriver, params: VirtualFileParams):
4849
val lspAction = lsp4j.CodeAction(action.title)
4950
lspAction.setKind(lsp4j.CodeActionKind.QuickFix)
5051
lspAction.setIsPreferred(true)
51-
val edits = action.patches.groupBy(_.srcPos.source.path)
52+
val edits = action.patches
53+
.groupBy(_.srcPos.source.path)
5254
.map((path, actions) => path -> (actions.map(toLspTextEdit).asJava))
5355
.asJava
5456

@@ -57,8 +59,12 @@ class DiagnosticProvider(driver: InteractiveDriver, params: VirtualFileParams):
5759
lspAction
5860

5961
private def toLspTextEdit(actionPatch: ActionPatch): lsp4j.TextEdit =
60-
val startPos = lsp4j.Position(actionPatch.srcPos.startLine, actionPatch.srcPos.startColumn)
61-
val endPos = lsp4j.Position(actionPatch.srcPos.endLine, actionPatch.srcPos.endColumn)
62+
val startPos = lsp4j.Position(
63+
actionPatch.srcPos.startLine,
64+
actionPatch.srcPos.startColumn
65+
)
66+
val endPos =
67+
lsp4j.Position(actionPatch.srcPos.endLine, actionPatch.srcPos.endColumn)
6268
val range = lsp4j.Range(startPos, endPos)
6369
lsp4j.TextEdit(range, actionPatch.replacement)
6470

presentation-compiler/test/dotty/tools/pc/base/BaseDiagnosticsSuite.scala

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,49 @@ import scala.meta.pc.CancelToken
1414
import scala.meta.pc.VirtualFileParams
1515

1616
class BaseDiagnosticsSuite extends PcAssertions:
17-
case class TestDiagnostic(startIndex: Int, endIndex: Int, msg: String, severity: DiagnosticSeverity)
17+
case class TestDiagnostic(
18+
startIndex: Int,
19+
endIndex: Int,
20+
msg: String,
21+
severity: DiagnosticSeverity
22+
)
1823

19-
def options : List[String] = Nil
20-
21-
val pc = RawScalaPresentationCompiler().newInstance("", TestResources.classpath.asJava, options.asJava)
24+
def options: List[String] = Nil
2225

23-
case class TestVirtualFileParams(uri: URI, text: String) extends VirtualFileParams {
26+
val pc = RawScalaPresentationCompiler().newInstance(
27+
"",
28+
TestResources.classpath.asJava,
29+
options.asJava
30+
)
31+
32+
case class TestVirtualFileParams(uri: URI, text: String)
33+
extends VirtualFileParams {
2434
override def shouldReturnDiagnostics: Boolean = true
2535
override def token: CancelToken = EmptyCancelToken
2636
}
2737

2838
def check(
29-
text: String,
30-
expected: List[TestDiagnostic],
31-
additionalChecks: List[Diagnostic] => Unit = identity
39+
text: String,
40+
expected: List[TestDiagnostic],
41+
additionalChecks: List[Diagnostic] => Unit = identity
3242
): Unit =
3343
val diagnostics = pc
34-
.didChange(TestVirtualFileParams(URI.create("file:/Diagnostic.scala"), text))
44+
.didChange(
45+
TestVirtualFileParams(URI.create("file:/Diagnostic.scala"), text)
46+
)
3547
.asScala
3648

37-
val actual = diagnostics.map(d => TestDiagnostic(d.getRange().getStart().getOffset(text), d.getRange().getEnd().getOffset(text), d.getMessage(), d.getSeverity()))
38-
assertEquals(expected, actual, s"Expected [${expected.mkString(", ")}] but got [${actual.mkString(", ")}]")
49+
val actual = diagnostics.map(d =>
50+
TestDiagnostic(
51+
d.getRange().getStart().getOffset(text),
52+
d.getRange().getEnd().getOffset(text),
53+
d.getMessage(),
54+
d.getSeverity()
55+
)
56+
)
57+
assertEquals(
58+
expected,
59+
actual,
60+
s"Expected [${expected.mkString(", ")}] but got [${actual.mkString(", ")}]"
61+
)
3962
additionalChecks(diagnostics.toList)

presentation-compiler/test/dotty/tools/pc/tests/DiagnosticProviderSuite.scala

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,29 @@ class DiagnosticProviderSuite extends BaseDiagnosticsSuite {
1616
"""|object M:
1717
| Int.maaxValue
1818
|""".stripMargin,
19-
List(TestDiagnostic(12,25, "value maaxValue is not a member of object Int - did you mean Int.MaxValue?", DiagnosticSeverity.Error))
20-
)
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+
)
27+
)
2128

2229
@Test def warning =
2330
check(
2431
"""|object M:
2532
| 1 + 1
2633
|""".stripMargin,
27-
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+
)
2842
)
2943

3044
@Test def mixed =
@@ -34,8 +48,18 @@ class DiagnosticProviderSuite extends BaseDiagnosticsSuite {
3448
| 1 + 1
3549
|""".stripMargin,
3650
List(
37-
TestDiagnostic(12,25, "value maaxValue is not a member of object Int - did you mean Int.MaxValue?", DiagnosticSeverity.Error),
38-
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+
)
3963
)
4064
)
4165

@@ -45,12 +69,29 @@ class DiagnosticProviderSuite extends BaseDiagnosticsSuite {
4569
| private private class Test
4670
|""".stripMargin,
4771
List(
48-
TestDiagnostic(20, 27, "Repeated modifier private", DiagnosticSeverity.Error),
72+
TestDiagnostic(
73+
20,
74+
27,
75+
"Repeated modifier private",
76+
DiagnosticSeverity.Error
77+
)
4978
),
5079
diags =>
51-
val action = diags.head.getData().asInstanceOf[java.util.List[CodeAction]].asScala.head
52-
assertWithDiff("Remove repeated modifier: \"private\"", action.getTitle(), false)
53-
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+
)
5495
)
5596

5697
}

presentation-compiler/test/dotty/tools/pc/tests/ExplainDiagnosticProviderSuite.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import scala.meta.internal.jdk.CollectionConverters.*
1111

1212
class ExplainDiagnosticProviderSuite extends BaseDiagnosticsSuite {
1313

14-
override def options : List[String] = List("-explain")
14+
override def options: List[String] = List("-explain")
1515

1616
@Test def error1 =
1717
check(
@@ -24,8 +24,9 @@ class ExplainDiagnosticProviderSuite extends BaseDiagnosticsSuite {
2424
|""".stripMargin,
2525
List(
2626
TestDiagnostic(
27-
64,65,
28-
"""|Reference to m is ambiguous.
27+
64,
28+
65,
29+
"""|Reference to m is ambiguous.
2930
|It is both defined in object C
3031
|and inherited subsequently in object T
3132
|
@@ -48,8 +49,7 @@ class ExplainDiagnosticProviderSuite extends BaseDiagnosticsSuite {
4849
| - When importing, you can avoid naming conflicts by renaming:
4950
| import scala.{m => mTick}
5051
|""".stripMargin,
51-
DiagnosticSeverity.Error
52-
52+
DiagnosticSeverity.Error
5353
)
5454
)
5555
)

0 commit comments

Comments
 (0)