@@ -18,7 +18,6 @@ import scala.build.{BloopBuildClient, GeneratedSource, Logger}
18
18
import scala .jdk .CollectionConverters .*
19
19
20
20
class BspClient (
21
- readFilesEs : ExecutorService ,
22
21
@ volatile var logger : Logger ,
23
22
var forwardToOpt : Option [b.BuildClient ] = None
24
23
) extends b.BuildClient with BuildClientForwardStubs with BloopBuildClient
@@ -27,76 +26,68 @@ class BspClient(
27
26
private def updatedPublishDiagnosticsParams (
28
27
params : b.PublishDiagnosticsParams ,
29
28
genSource : GeneratedSource
30
- ): Either [() => b.PublishDiagnosticsParams , b. PublishDiagnosticsParams ] = {
29
+ ): b.PublishDiagnosticsParams = {
31
30
val updatedUri = genSource.reportingPath.fold(
32
31
_ => params.getTextDocument.getUri,
33
32
_.toNIO.toUri.toASCIIString
34
33
)
35
34
val updatedDiagnostics =
36
35
if (genSource.wrapperParamsOpt.isEmpty)
37
- Right ( params.getDiagnostics)
36
+ params.getDiagnostics
38
37
else
39
- Left { () =>
40
- val updateLine = scalaLine => scalaLineToScLine(scalaLine, genSource.wrapperParamsOpt)
41
- params.getDiagnostics.asScala.toSeq
42
- .map { diag =>
43
- val updatedDiagOpt = for {
44
- startLine <- updateLine(diag.getRange.getStart.getLine)
45
- endLine <- updateLine(diag.getRange.getEnd.getLine)
46
- } yield {
47
- val diag0 = diag.duplicate()
48
- diag0.getRange.getStart.setLine(startLine)
49
- diag0.getRange.getEnd.setLine(endLine)
50
-
51
- val scalaDiagnostic = new Gson ().fromJson[b.ScalaDiagnostic ](
52
- diag0.getData().asInstanceOf [JsonElement ],
53
- classOf [b.ScalaDiagnostic ]
54
- )
55
-
56
- scalaDiagnostic.getActions().asScala.foreach { action =>
57
- for {
58
- change <- action.getEdit().getChanges().asScala
59
- startLine <- updateLine(change.getRange.getStart.getLine)
60
- endLine <- updateLine(change.getRange.getEnd.getLine)
61
- } yield {
62
- change.getRange().getStart.setLine(startLine)
63
- change.getRange().getEnd.setLine(endLine)
64
- }
38
+ val updateLine = scalaLine => scalaLineToScLine(scalaLine, genSource.wrapperParamsOpt)
39
+ params.getDiagnostics.asScala.toSeq
40
+ .map { diag =>
41
+ val updatedDiagOpt = for {
42
+ startLine <- updateLine(diag.getRange.getStart.getLine)
43
+ endLine <- updateLine(diag.getRange.getEnd.getLine)
44
+ } yield {
45
+ val diag0 = diag.duplicate()
46
+ diag0.getRange.getStart.setLine(startLine)
47
+ diag0.getRange.getEnd.setLine(endLine)
48
+
49
+ val scalaDiagnostic = new Gson ().fromJson[b.ScalaDiagnostic ](
50
+ diag0.getData().asInstanceOf [JsonElement ],
51
+ classOf [b.ScalaDiagnostic ]
52
+ )
53
+
54
+ scalaDiagnostic.getActions().asScala.foreach { action =>
55
+ for {
56
+ change <- action.getEdit().getChanges().asScala
57
+ startLine <- updateLine(change.getRange.getStart.getLine)
58
+ endLine <- updateLine(change.getRange.getEnd.getLine)
59
+ } yield {
60
+ change.getRange().getStart.setLine(startLine)
61
+ change.getRange().getEnd.setLine(endLine)
65
62
}
63
+ }
66
64
67
- diag0.setData(scalaDiagnostic)
65
+ diag0.setData(scalaDiagnostic)
68
66
69
- if (
70
- diag0.getMessage.contains(
71
- " cannot be a main method since it cannot be accessed statically"
72
- )
67
+ if (
68
+ diag0.getMessage.contains(
69
+ " cannot be a main method since it cannot be accessed statically"
70
+ )
71
+ )
72
+ diag0.setMessage(
73
+ WarningMessages .mainAnnotationNotSupported( /* annotationIgnored */ false )
73
74
)
74
- diag0.setMessage(
75
- WarningMessages .mainAnnotationNotSupported( /* annotationIgnored */ false )
76
- )
77
75
78
- diag0
79
- }
80
- updatedDiagOpt.getOrElse(diag)
76
+ diag0
81
77
}
82
- .asJava
83
- }
84
- def updatedParamsFor (
85
- updatedDiagnostics : java.util.List [b.Diagnostic ]
86
- ): b.PublishDiagnosticsParams = {
87
- val updatedTextDoc = new b.TextDocumentIdentifier (updatedUri)
88
- val updatedParams = new b.PublishDiagnosticsParams (
89
- updatedTextDoc,
90
- params.getBuildTarget,
91
- updatedDiagnostics,
92
- params.getReset
93
- )
94
- updatedParams.setOriginId(params.getOriginId)
95
- updatedParams
96
- }
97
- updatedDiagnostics
98
- .left.map(f => () => updatedParamsFor(f()))
99
- .map(updatedParamsFor(_))
78
+ updatedDiagOpt.getOrElse(diag)
79
+ }
80
+ .asJava
81
+
82
+ val updatedTextDoc = new b.TextDocumentIdentifier (updatedUri)
83
+ val updatedParams = new b.PublishDiagnosticsParams (
84
+ updatedTextDoc,
85
+ params.getBuildTarget,
86
+ updatedDiagnostics,
87
+ params.getReset
88
+ )
89
+ updatedParams.setOriginId(params.getOriginId)
90
+ updatedParams
100
91
}
101
92
102
93
override def onBuildPublishDiagnostics (params : b.PublishDiagnosticsParams ): Unit = {
@@ -116,24 +107,11 @@ class BspClient(
116
107
}
117
108
}
118
109
119
- def call (updatedParams0 : b.PublishDiagnosticsParams ): Unit =
120
- super .onBuildPublishDiagnostics(updatedParams0)
121
110
updatedParamsOpt match {
122
111
case None =>
123
- call(params)
124
- case Some (Right (updatedParams0)) =>
125
- call(updatedParams0)
126
- case Some (Left (updateParamsFunc)) =>
127
- val runnable =
128
- new Runnable {
129
- def run (): Unit =
130
- try call(updateParamsFunc())
131
- catch {
132
- case t : Throwable =>
133
- logger.debug(s " Caught $t while publishing updated diagnostics " )
134
- }
135
- }
136
- readFilesEs.submit(runnable)
112
+ super .onBuildPublishDiagnostics(params)
113
+ case Some (updatedParams) =>
114
+ super .onBuildPublishDiagnostics(updatedParams)
137
115
}
138
116
}
139
117
0 commit comments