1- //> using lib " tech.neander::langoustine-lsp::0.0.6"
2- //> using lib " tech.neander::jsonrpclib-fs2::0.0.2"
3- //> using lib " co.fs2::fs2-io::3.2.11"
4-
51import langoustine .lsp .*
62
7- import requests .*
8- import notifications as nt
9- import structures .*
10- import aliases .*
11- import enumerations .*
12- import json .*
13-
143import cats .effect .*
154import jsonrpclib .fs2 .*
165
@@ -27,27 +16,44 @@ import cats.syntax.all.*
2716
2817object LSP extends IOApp .Simple :
2918 import QuickmaffsLSP .{server , State }
19+
3020 def run =
31- FS2Channel
32- .lspCompliant[IO ](
33- byteStream = fs2.io.stdin(256 ),
34- byteSink = fs2.io.stdout
35- )
21+ FS2Channel [IO ](2048 , None )
3622 .evalTap { channel =>
3723 IO .ref(Map .empty[DocumentUri , State ])
3824 .flatMap { state =>
3925 server(state).bind(channel)
4026 }
4127 }
42- .flatMap(_.openStream)
43- .evalMap(_ => IO .never)
28+ .flatMap(channel =>
29+ fs2.Stream
30+ .eval(IO .never) // running the server forever
31+ .concurrently(
32+ fs2.io
33+ .stdin[IO ](512 )
34+ .through(lsp.decodePayloads)
35+ .through(channel.input)
36+ )
37+ .concurrently(
38+ channel.output
39+ .through(lsp.encodePayloads)
40+ .through(fs2.io.stdout[IO ])
41+ )
42+ )
4443 .compile
4544 .drain
45+ .guarantee(IO .consoleForIO.errorln(" Terminating server" ))
4646 end run
4747
4848end LSP
4949
5050object QuickmaffsLSP :
51+ import requests .*
52+ import structures .*
53+ import aliases .*
54+ import enumerations .*
55+ import json .*
56+
5157 enum State :
5258 case Empty
5359 case InvalidCode (err : QuickmaffsParser .ParsingError )
@@ -107,7 +113,7 @@ object QuickmaffsLSP:
107113 def recompile (uri : DocumentUri , back : Communicate [IO ]) =
108114 def publish (vec : Vector [Diagnostic ]) =
109115 back.notification(
110- nt. textDocument.publishDiagnostics,
116+ textDocument.publishDiagnostics,
111117 PublishDiagnosticsParams (uri, diagnostics = vec)
112118 )
113119
@@ -161,11 +167,11 @@ object QuickmaffsLSP:
161167 case _ => None
162168 }
163169
164- ImmutableLSPBuilder
170+ LSPBuilder
165171 .create[IO ]
166172 .handleRequest(initialize) { (in, back) =>
167173 back.notification(
168- nt. window.showMessage,
174+ window.showMessage,
169175 ShowMessageParams (
170176 message = " Hello from Quickmaffs" ,
171177 `type` = enumerations.MessageType .Info
@@ -192,10 +198,10 @@ object QuickmaffsLSP:
192198 )
193199 }
194200 }
195- .handleNotification(nt. textDocument.didOpen) { (in, back) =>
201+ .handleNotification(textDocument.didOpen) { (in, back) =>
196202 recompile(in.textDocument.uri, back)
197203 }
198- .handleNotification(nt. textDocument.didSave) { (in, back) =>
204+ .handleNotification(textDocument.didSave) { (in, back) =>
199205 recompile(in.textDocument.uri, back)
200206 }
201207 .handleRequest(textDocument.definition) { (in, back) =>
0 commit comments