@@ -5,65 +5,59 @@ import bsp.PublishDiagnosticsParams as BspPublishDiagnosticsParams
55import cats .effect .std .MapRef
66import cats .effect .IO
77import cats .syntax .all .*
8- import langoustine .lsp
9- import langoustine .lsp .requests .textDocument .publishDiagnostics
10- import langoustine .lsp .runtime .*
11- import langoustine .lsp .structures .Diagnostic as LspDiagnostic
12- import langoustine .lsp .structures .DidChangeTextDocumentParams
13- import langoustine .lsp .structures .PublishDiagnosticsParams as LspPublishDiagnosticsParams
14- import langoustine .lsp .Communicate
15- import langoustine .lsp .Invocation
16- import org .scala .abusers .sls .NioConverter .*
178import smithy4s .json .Json
189
19- import java .net .URI
20-
2110/** Diagnostic State Manager
2211 *
2312 * This class is reposnobile for holding the state of the diagnostic displayed on the client
2413 *
2514 * Proposed heuristic is: On file save we trigger compilation, and this results in notifications being sent from BSP
26- * server. We will keep adding diagnostics, and will clean them only when [[PublishDiagnosticsParams.reset ]] is
27- * set to true.
15+ * server. We will keep adding diagnostics, and will clean them only when [[PublishDiagnosticsParams.reset ]] is set to
16+ * true.
2817 *
2918 * @param publishedDiagnostics
3019 */
31- class DiagnosticManager (publishedDiagnostics : MapRef [IO , URI , Option [Set [LspDiagnostic ]]]) {
32- private def convertDiagnostic (bspDiag : BspDiagnostic ): LspDiagnostic = {
20+ // FIXME revert this to URI
21+ class DiagnosticManager (publishedDiagnostics : MapRef [IO , String , Option [Set [lsp.Diagnostic ]]]) {
22+ private def convertDiagnostic (bspDiag : BspDiagnostic ): lsp.Diagnostic = {
3323 val data = Json .writeBlob(bspDiag)
34- upickle.default.read[LspDiagnostic ](data.asByteBuffer)
24+ // to be chimneyed
25+ Json .read[lsp.Diagnostic ](data).toOption.getOrElse(sys.error(s " Failed to convert BSP diagnostic to LSP: $data" ))
3526 }
3627
37- def didChange (in : Invocation [ DidChangeTextDocumentParams , IO ], pcDiags : Vector [ LspDiagnostic ]): IO [Unit ] =
28+ def didChange (client : SlsLanguageClient [ IO ], uri : String , pcDiags : List [lsp. Diagnostic ]): IO [Unit ] =
3829 // remove diagnostic on modified lines
3930 // ask presentation compiler for diagnostics
4031 for {
41- _ <- publishedDiagnostics(in.params.textDocument. uri.asNio ).set(pcDiags.toSet.some)
42- request = LspPublishDiagnosticsParams (in.params.textDocument. uri, Opt .empty, pcDiags.toVector )
43- _ <- in.toClient.notification(publishDiagnostics( request) )
32+ _ <- publishedDiagnostics(uri).set(pcDiags.toSet.some)
33+ request = lsp. PublishDiagnosticsParams ( uri, pcDiags, None )
34+ _ <- client.textDocumentPublishDiagnostics( request)
4435 } yield ()
4536
46- def onBuildPublishDiagnostics (lspClient : Communicate [IO ], input : BspPublishDiagnosticsParams ): IO [Unit ] = {
37+ def onBuildPublishDiagnostics (client : SlsLanguageClient [IO ], input : BspPublishDiagnosticsParams ): IO [Unit ] = {
4738 val bspUri = input.textDocument.uri
4839 val lspDiags = input.diagnostics.toSet.map(convertDiagnostic)
49- def request (diags : Set [LspDiagnostic ]) =
50- LspPublishDiagnosticsParams (DocumentUri (bspUri.value), Opt .empty, diags.toVector)
40+ def request (diags : Set [lsp.Diagnostic ]) =
41+ lsp.PublishDiagnosticsParams (bspUri.value, diags.toList, None )
42+
5143 if input.reset then {
5244 for {
53- _ <- publishedDiagnostics(input.textDocument.uri.asNio).set(lspDiags.some)
54- _ <- lspClient.notification(publishDiagnostics(request(lspDiags)))
45+ _ <- publishedDiagnostics(input.textDocument.uri.value).set(lspDiags.some)
46+ _ <- client.textDocumentPublishDiagnostics(
47+ lsp.PublishDiagnosticsParams (input.textDocument.uri.value, lspDiags.toList)
48+ )
5549 } yield ()
5650
5751 } else {
5852 for {
59- currentDiags <- publishedDiagnostics(bspUri.asNio ).updateAndGet(_.foldLeft(lspDiags)(_ ++ _).some)
60- _ <- lspClient.notification(publishDiagnostics( request(currentDiags.get) ))
53+ currentDiags <- publishedDiagnostics(bspUri.value ).updateAndGet(_.foldLeft(lspDiags)(_ ++ _).some)
54+ _ <- client.textDocumentPublishDiagnostics( request(currentDiags.get))
6155 } yield ()
6256 }
6357 }
6458}
6559
6660object DiagnosticManager {
6761 def instance : IO [DiagnosticManager ] =
68- MapRef .ofScalaConcurrentTrieMap[IO , URI , Set [LspDiagnostic ]].map(DiagnosticManager .apply)
62+ MapRef .ofScalaConcurrentTrieMap[IO , String , Set [lsp. Diagnostic ]].map(DiagnosticManager .apply)
6963}
0 commit comments