@@ -15,6 +15,7 @@ import langoustine.lsp.structures.*
1515import langoustine .lsp .structures as lngst
1616import org .eclipse .lsp4j
1717import org .scala .abusers .pc .IOCancelTokens
18+ import LoggingUtils .*
1819import org .scala .abusers .pc .PresentationCompilerDTOInterop .*
1920import org .scala .abusers .pc .PresentationCompilerProvider
2021import org .scala .abusers .sls .NioConverter .asNio
@@ -32,7 +33,7 @@ import scala.meta.pc.VirtualFileParams
3233import org .scala .abusers .pc .ScalaVersion
3334
3435class ServerImpl (
35- syncManager : SyncManager ,
36+ stateManager : StateManager ,
3637 pcProvider : PresentationCompilerProvider ,
3738 cancelTokens : IOCancelTokens ,
3839 diagnosticManager : DiagnosticManager ,
@@ -76,7 +77,7 @@ class ServerImpl(
7677
7778 cancelTokens.mkCancelToken.use { token0 =>
7879 for {
79- docState <- syncManager .getDocumentState(uri0)
80+ docState <- stateManager .getDocumentState(uri0)
8081 inalyHintsParams = new InlayHintsParams {
8182 import docState .*
8283 def implicitConversions (): Boolean = true
@@ -104,7 +105,7 @@ class ServerImpl(
104105 val position = summon[WithPosition [Params ]].position(in.params)
105106 cancelTokens.mkCancelToken.use { token =>
106107 for {
107- docState <- syncManager .getDocumentState(uri)
108+ docState <- stateManager .getDocumentState(uri)
108109 offsetParams = toOffsetParams(position, docState, token)
109110 result <- pcParamsRequest(in.params, offsetParams)(thunk)
110111 } yield result
@@ -116,17 +117,17 @@ class ServerImpl(
116117 ): IO [Result ] = { // TODO Completion on context bound inserts []
117118 val uri = summon[WithURI [Params ]].uri(params)
118119 for {
119- info <- syncManager .getBuildTargetInformation(uri)
120+ info <- stateManager .getBuildTargetInformation(uri)
120121 pc <- pcProvider.get(info)
121122 result <- IO .fromCompletableFuture(IO (thunk(pc)(pcParams)))
122123 } yield result
123124 }
124125
125- def handleDidSave (in : Invocation [DidSaveTextDocumentParams , IO ]) = syncManager .didSave(in)
126+ def handleDidSave (in : Invocation [DidSaveTextDocumentParams , IO ]) = stateManager .didSave(in)
126127
127- def handleDidOpen (in : Invocation [DidOpenTextDocumentParams , IO ]) = syncManager .didOpen(in)
128+ def handleDidOpen (in : Invocation [DidOpenTextDocumentParams , IO ]) = stateManager .didOpen(in)
128129
129- def handleDidClose (in : Invocation [DidCloseTextDocumentParams , IO ]) = syncManager .didClose(in)
130+ def handleDidClose (in : Invocation [DidCloseTextDocumentParams , IO ]) = stateManager .didClose(in)
130131
131132 val handleDidChange : Invocation [DidChangeTextDocumentParams , IO ] => IO [Unit ] = {
132133 val debounce = Debouncer (300 .millis)
@@ -143,8 +144,8 @@ class ServerImpl(
143144 def pcDiagnostics (in : Invocation [DidChangeTextDocumentParams , IO ], info : ScalaBuildTargetInformation , uri : URI ): IO [Unit ] =
144145 cancelTokens.mkCancelToken.use { token =>
145146 for {
146- _ <- LoggingUtils .logDebug( in.toClient, " Getting PresentationCompiler diagnostics" )
147- textDocument <- syncManager .getDocumentState(uri)
147+ _ <- in.toClient.logDebug( " Getting PresentationCompiler diagnostics" )
148+ textDocument <- stateManager .getDocumentState(uri)
148149 pc <- pcProvider.get(info)
149150 params = virtualFileParams(uri, textDocument.content, token)
150151 diags <- IO .fromCompletableFuture(IO (pc.didChange(params)))
@@ -154,15 +155,15 @@ class ServerImpl(
154155 }
155156
156157 in => for {
157- _ <- syncManager .didChange(in)
158- _ <- LoggingUtils .logDebug( in.toClient, " Updated DocumentState" )
158+ _ <- stateManager .didChange(in)
159+ _ <- in.toClient.logDebug( " Updated DocumentState" )
159160 uri = in.params.textDocument.uri.asNio
160- info <- syncManager .getBuildTargetInformation(uri)
161+ info <- stateManager .getBuildTargetInformation(uri)
161162 _ <- if isSupported(info) then debounce.debounce(pcDiagnostics(in, info, uri)) else IO .unit
162163 } yield ()
163164 }
164165
165- def handleInitialized (in : Invocation [InitializedParams , IO ]): IO [Unit ] = syncManager .importBuild(in.toClient)
166+ def handleInitialized (in : Invocation [InitializedParams , IO ]): IO [Unit ] = stateManager .importBuild(in.toClient)
166167
167168 def handleInitialize (
168169 steward : ResourceSupervisor [IO ],
@@ -173,10 +174,10 @@ class ServerImpl(
173174 val rootUri = in.params.rootUri.toOption.getOrElse(sys.error(" what now?" ))
174175 val rootPath = os.Path (java.net.URI .create(rootUri.value).getPath())
175176 (for {
176- _ <- LoggingUtils .sendMessage( in.toClient, " ready to initialise!" )
177+ _ <- in.toClient.sendMessage( " Ready to initialise!" )
177178 _ <- importMillBsp(rootPath, in.toClient)
178179 bspClient <- connectWithBloop(in.toClient, steward, diagnosticManager)
179- _ <- LoggingUtils .logMessage( in.toClient, " Connection with bloop estabilished" )
180+ _ <- in.toClient.logMessage( " Connection with bloop estabilished" )
180181 response <- bspClient.generic.buildInitialize(
181182 InitializeBuildParams (
182183 displayName = " bloop" ,
@@ -186,13 +187,13 @@ class ServerImpl(
186187 capabilities = bsp.BuildClientCapabilities (languageIds = List (bsp.LanguageId (" scala" ))),
187188 )
188189 )
189- _ <- LoggingUtils .logMessage( in.toClient, s " Response from bsp: $response" )
190+ _ <- in.toClient.logMessage( s " Response from bsp: $response" )
190191 _ <- bspClient.generic.onBuildInitialized()
191192 _ <- bspClientDeferred.complete(bspClient)
192193 } yield InitializeResult (
193194 capabilities = serverCapabilities,
194195 serverInfo = Opt (InitializeResult .ServerInfo (" My first LSP!" )),
195- )).guaranteeCase(s => LoggingUtils .logMessage( in.toClient, s " closing initalize with $s" ))
196+ )).guaranteeCase(s => in.toClient.logMessage( s " closing initalize with $s" ))
196197 }
197198
198199 private def serverCapabilities : ServerCapabilities =
@@ -228,8 +229,8 @@ class ServerImpl(
228229 .merge(bspSocketProc.stderr)
229230 .through(text.utf8.decode)
230231 .through(text.lines)
231- .evalMap(s => LoggingUtils .logMessage(back, s " [bloop] $s" ))
232- .onFinalizeCase(c => LoggingUtils .sendMessage(back, s " Bloop process terminated $c" ))
232+ .evalMap(s => back .logMessage(s " [bloop] $s" ))
233+ .onFinalizeCase(c => back .sendMessage(s " Bloop process terminated $c" ))
233234 .compile
234235 .drain
235236 .background
@@ -242,11 +243,11 @@ class ServerImpl(
242243
243244 val bspClientRes = for {
244245 socketPath <- bspProcess
245- _ <- Resource .eval(IO .sleep(1 .seconds) *> LoggingUtils .logMessage(back, s " Looking for socket at $socketPath" ))
246+ _ <- Resource .eval(IO .sleep(1 .seconds) *> back .logMessage(s " Looking for socket at $socketPath" ))
246247 channel <- FS2Channel
247248 .resource[IO ]()
248249 .flatMap(_.withEndpoints(bspClientHandler(back, diagnosticManager)))
249- client <- makeBspClient(socketPath.toString, channel, msg => LoggingUtils .logDebug(back, s " reportin raw: $msg" ))
250+ client <- makeBspClient(socketPath.toString, channel, msg => back .logDebug(s " reporting raw: $msg" ))
250251 } yield client
251252
252253 steward.acquire(bspClientRes)
@@ -267,7 +268,7 @@ class ServerImpl(
267268 .through(text.lines)
268269
269270 allOutput
270- .evalMap(s => LoggingUtils .logMessage(back, s) )
271+ .evalMap(back .logMessage)
271272 .compile
272273 .drain
273274 }
0 commit comments