@@ -7,6 +7,7 @@ import cats.effect.IO
77import cats .syntax .all .*
88import fs2 .io .process .ProcessBuilder
99import fs2 .text
10+ import ScalaBuildTargetInformation .*
1011import jsonrpclib .fs2 .FS2Channel
1112import langoustine .lsp .*
1213import langoustine .lsp .runtime .*
@@ -28,6 +29,7 @@ import scala.meta.pc.InlayHintsParams
2829import scala .meta .pc .OffsetParams
2930import scala .meta .pc .PresentationCompiler
3031import scala .meta .pc .VirtualFileParams
32+ import org .scala .abusers .pc .ScalaVersion
3133
3234class ServerImpl (
3335 syncManager : SyncManager ,
@@ -129,17 +131,20 @@ class ServerImpl(
129131 val handleDidChange : Invocation [DidChangeTextDocumentParams , IO ] => IO [Unit ] = {
130132 val debounce = Debouncer (300 .millis)
131133
134+ def isSupported (info : ScalaBuildTargetInformation ): Boolean = {
135+ import scala .math .Ordered .orderingToOrdered
136+ info.scalaVersion > ScalaVersion (" 3.7.2" )
137+ }
138+
132139 /**
133140 * We want to debounce compiler diagnostics as they are expensive to compute and we can't really cancel them
134141 * as they are triggered by notification and AFAIK, LSP cancellation only works for requests.
135142 */
136- def pcDiagnostics (in : Invocation [DidChangeTextDocumentParams , IO ]): IO [Unit ] =
143+ def pcDiagnostics (in : Invocation [DidChangeTextDocumentParams , IO ], info : ScalaBuildTargetInformation , uri : URI ): IO [Unit ] =
137144 cancelTokens.mkCancelToken.use { token =>
138- val uri = in.params.textDocument.uri.asNio
139145 for {
140146 _ <- LoggingUtils .logDebug(in.toClient, " Getting PresentationCompiler diagnostics" )
141147 textDocument <- syncManager.getDocumentState(uri)
142- info <- syncManager.getBuildTargetInformation(uri)
143148 pc <- pcProvider.get(info)
144149 params = virtualFileParams(uri, textDocument.content, token)
145150 diags <- IO .fromCompletableFuture(IO (pc.didChange(params)))
@@ -151,7 +156,9 @@ class ServerImpl(
151156 in => for {
152157 _ <- syncManager.didChange(in)
153158 _ <- LoggingUtils .logDebug(in.toClient, " Updated DocumentState" )
154- _ <- debounce.debounce(pcDiagnostics(in))
159+ uri = in.params.textDocument.uri.asNio
160+ info <- syncManager.getBuildTargetInformation(uri)
161+ _ <- if isSupported(info) then debounce.debounce(pcDiagnostics(in, info, uri)) else IO .unit
155162 } yield ()
156163 }
157164
0 commit comments