Skip to content

Commit c4fb30b

Browse files
committed
Changes after review
1 parent 32f33f2 commit c4fb30b

File tree

7 files changed

+52
-50
lines changed

7 files changed

+52
-50
lines changed

sls/resources/logback.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
<appender-ref ref="SLS_LOG"/>
2929
</logger>
3030

31-
<!-- Root logger (optional) -->
3231
<root level="INFO">
33-
<!-- Add a console appender if desired -->
34-
<!-- <appender-ref ref="STDOUT"/> -->
3532
</root>
3633

3734
</configuration>

sls/src/org/scala/abusers/sls/BspStateManager.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import langoustine.lsp.*
1212
import langoustine.lsp.structures.*
1313
import org.scala.abusers.pc.ScalaVersion
1414
import org.scala.abusers.sls.NioConverter.asNio
15+
import org.scala.abusers.sls.LoggingUtils.*
1516

1617
import java.net.URI
1718

@@ -54,11 +55,11 @@ class BspStateManager(
5455

5556
def importBuild(back: Communicate[IO]) =
5657
for {
57-
_ <- LoggingUtils.logMessage(back, "Starting build import.") // in the future this should be a task with progress
58+
_ <- back.logMessage("Starting build import.") // in the future this should be a task with progress
5859
importedBuild <- getBuildInformation(bspServer)
5960
_ <- bspServer.generic.buildTargetCompile(CompileParams(targets = importedBuild.map(_.buildTarget.id).toList))
6061
_ <- targets.set(importedBuild)
61-
_ <- LoggingUtils.logMessage(back, "Build import finished.")
62+
_ <- back.logMessage("Build import finished.")
6263
} yield ()
6364

6465
private val byScalaVersion: Ordering[ScalaBuildTargetInformation] = new Ordering[ScalaBuildTargetInformation] {
@@ -122,7 +123,7 @@ class BspStateManager(
122123
targets0 <- targets.get
123124
possibleBuildTargets = possibleIds.flatMap(id => targets0.find(_.buildTarget.id == id))
124125
bestBuildTarget = possibleBuildTargets.maxBy(_.buildTarget.project.scala.map(_.data.scalaVersion))
125-
_ <- LoggingUtils.logDebug(in.toClient, s"Best build target for $uri is ${bestBuildTarget.toString}")
126+
_ <- in.toClient.logDebug(s"Best build target for $uri is ${bestBuildTarget.toString}")
126127
} yield state.updated(uri, bestBuildTarget)
127128
)
128129
}

sls/src/org/scala/abusers/sls/DiagnosticManager.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import java.net.URI
2323
* This class is reposnobile for holding the state of the diagnostic displayed on the client
2424
*
2525
* 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
26+
* server. We will keep adding diagnostics, and will clean them only when [[PublishDiagnosticsParams.reset]] is
27+
* set to true.
2728
*
2829
* @param publishedDiagnostics
2930
*/

sls/src/org/scala/abusers/sls/LoggingUtils.scala

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@ import langoustine.lsp.structures.ShowMessageParams
77
import langoustine.lsp.Communicate
88

99
object LoggingUtils {
10-
def sendMessage(back: Communicate[IO], msg: String): IO[Unit] =
11-
back.notification(
12-
requests.window.showMessage,
13-
ShowMessageParams(enumerations.MessageType.Info, msg),
14-
) *> logMessage(back, msg)
10+
extension (back: Communicate[IO]) {
11+
def sendMessage(msg: String): IO[Unit] =
12+
back.notification(
13+
requests.window.showMessage,
14+
ShowMessageParams(enumerations.MessageType.Info, msg),
15+
) *> logMessage(msg)
1516

16-
def logMessage(back: Communicate[IO], message: String): IO[Unit] =
17-
back.notification(
18-
requests.window.logMessage,
19-
LogMessageParams(enumerations.MessageType.Info, message),
20-
)
17+
def logMessage(message: String): IO[Unit] =
18+
back.notification(
19+
requests.window.logMessage,
20+
LogMessageParams(enumerations.MessageType.Info, message),
21+
)
2122

22-
def logDebug(back: Communicate[IO], message: String): IO[Unit] =
23-
back.notification(
24-
requests.window.logMessage,
25-
LogMessageParams(enumerations.MessageType.Debug, message),
26-
)
23+
def logDebug(message: String): IO[Unit] =
24+
back.notification(
25+
requests.window.logMessage,
26+
LogMessageParams(enumerations.MessageType.Debug, message),
27+
)
28+
}
2729
}

sls/src/org/scala/abusers/sls/ServerImpl.scala

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import langoustine.lsp.structures.*
1515
import langoustine.lsp.structures as lngst
1616
import org.eclipse.lsp4j
1717
import org.scala.abusers.pc.IOCancelTokens
18+
import LoggingUtils.*
1819
import org.scala.abusers.pc.PresentationCompilerDTOInterop.*
1920
import org.scala.abusers.pc.PresentationCompilerProvider
2021
import org.scala.abusers.sls.NioConverter.asNio
@@ -32,7 +33,7 @@ import scala.meta.pc.VirtualFileParams
3233
import org.scala.abusers.pc.ScalaVersion
3334

3435
class 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
}

sls/src/org/scala/abusers/sls/SimpleLanguageServer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ object SimpleScalaServer extends LangoustineApp {
3939
textDocumentSync <- TextDocumentSyncManager.instance.toResource
4040
bspClientDeferred <- Deferred[IO, BuildServer].toResource
4141
bspStateManager <- BspStateManager.instance(BuildServer.suspend(bspClientDeferred.get)).toResource
42-
syncManager <- SyncManager.instance(textDocumentSync, bspStateManager).toResource
42+
stateManager <- StateManager.instance(textDocumentSync, bspStateManager).toResource
4343
cancelTokens <- IOCancelTokens.instance
4444
diagnosticManager <- DiagnosticManager.instance.toResource
45-
impl = ServerImpl(syncManager, pcProvider, cancelTokens, diagnosticManager)
45+
impl = ServerImpl(stateManager, pcProvider, cancelTokens, diagnosticManager)
4646
} yield LSPBuilder
4747
.create[IO]
4848
.handleRequest(initialize)(impl.handleInitialize(steward, bspClientDeferred))

sls/src/org/scala/abusers/sls/SyncManager.scala renamed to sls/src/org/scala/abusers/sls/StateManager.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import org.scala.abusers.sls.NioConverter.asNio
1010

1111
import java.net.URI
1212

13-
object SyncManager {
13+
object StateManager {
1414

15-
def instance(textDocumentSyncManager: TextDocumentSyncManager, bspStateManager: BspStateManager): IO[SyncManager] =
16-
Mutex[IO].map(SyncManager(textDocumentSyncManager, bspStateManager, _))
15+
def instance(textDocumentSyncManager: TextDocumentSyncManager, bspStateManager: BspStateManager): IO[StateManager] =
16+
Mutex[IO].map(StateManager(textDocumentSyncManager, bspStateManager, _))
1717

1818
}
1919

@@ -25,7 +25,7 @@ object SyncManager {
2525
*
2626
* By unifying this in single manager, we can control what has to be synchronized.
2727
*/
28-
class SyncManager(
28+
class StateManager(
2929
textDocumentSyncManager: TextDocumentSyncManager,
3030
bspStateManager: BspStateManager,
3131
mutex: Mutex[IO],

0 commit comments

Comments
 (0)