Skip to content

Commit 1ad9360

Browse files
committed
setting query is "sbt/setting"
1 parent a8e770c commit 1ad9360

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

main/src/main/scala/sbt/internal/server/LanguageServerProtocol.scala

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package server
55
import sjsonnew.JsonFormat
66
import sjsonnew.support.scalajson.unsafe.Converter
77
import sbt.protocol.Serialization
8+
import sbt.protocol.{ SettingQuery => Q }
89
import sbt.internal.protocol._
910
import sbt.internal.protocol.codec._
1011
import sbt.internal.langserver._
@@ -24,6 +25,7 @@ private[sbt] trait LanguageServerProtocol extends CommandChannel {
2425
protected def authOptions: Set[ServerAuthentication]
2526
protected def setInitialized(value: Boolean): Unit
2627
protected def log: Logger
28+
protected def onSettingQuery(execId: Option[String], req: Q): Unit
2729

2830
protected def onRequestMessage(request: JsonRpcRequestMessage): Unit = {
2931

@@ -54,6 +56,11 @@ private[sbt] trait LanguageServerProtocol extends CommandChannel {
5456
case "sbt/exec" =>
5557
val param = Converter.fromJson[SbtExecParams](json).get
5658
append(Exec(param.commandLine, Some(request.id), Some(CommandSource(name))))
59+
case "sbt/setting" => {
60+
import sbt.protocol.codec.JsonProtocol._
61+
val param = Converter.fromJson[Q](json).get
62+
onSettingQuery(Option(request.id), param)
63+
}
5764
case _ => ()
5865
}
5966
}

main/src/main/scala/sbt/internal/server/NetworkChannel.scala

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import java.net.{ Socket, SocketTimeoutException }
99
import java.util.concurrent.atomic.AtomicBoolean
1010

1111
import sjsonnew._
12-
import sjsonnew.support.scalajson.unsafe.Converter
1312
import scala.annotation.tailrec
1413
import sbt.protocol._
1514
import sbt.internal.langserver.ErrorCodes
16-
import sbt.internal.protocol.JsonRpcResponseMessage
1715
import sbt.internal.util.ObjectEvent
1816
import sbt.internal.util.codec.JValueFormats
1917
import sbt.util.Logger
@@ -283,7 +281,7 @@ final class NetworkChannel(val name: String,
283281
def onCommand(command: CommandMessage): Unit = command match {
284282
case x: InitCommand => onInitCommand(x)
285283
case x: ExecCommand => onExecCommand(x)
286-
case x: SettingQuery => onSettingQuery(x)
284+
case x: SettingQuery => onSettingQuery(None, x)
287285
}
288286

289287
private def onInitCommand(cmd: InitCommand): Unit = {
@@ -312,9 +310,13 @@ final class NetworkChannel(val name: String,
312310
}
313311
}
314312

315-
private def onSettingQuery(req: SettingQuery) = {
313+
protected def onSettingQuery(execId: Option[String], req: SettingQuery) = {
316314
if (initialized) {
317-
StandardMain.exchange publishEventMessage SettingQuery.handleSettingQuery(req, structure)
315+
import sbt.protocol.codec.JsonProtocol._
316+
SettingQuery.handleSettingQueryEither(req, structure) match {
317+
case Right(x) => langRespond(x, execId)
318+
case Left(s) => langError(execId, ErrorCodes.InvalidParams, s)
319+
}
318320
} else {
319321
log.warn(s"ignoring query $req before initialization")
320322
}

main/src/main/scala/sbt/internal/server/SettingQuery.scala

+9-8
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,19 @@ object SettingQuery {
110110
toJson(value)
111111
})
112112

113-
def handleSettingQuery(req: SettingQuery, structure: BuildStructure): SettingQueryResponse = {
113+
def handleSettingQueryEither(req: SettingQuery,
114+
structure: BuildStructure): Either[String, SettingQuerySuccess] = {
114115
val key = Parser.parse(req.setting, scopedKeyParser(structure))
115116

116-
val result =
117-
for {
118-
key <- key
119-
json <- getSettingJsonValue(structure, key)
120-
} yield SettingQuerySuccess(json, key.key.manifest.toString)
117+
for {
118+
key <- key
119+
json <- getSettingJsonValue(structure, key)
120+
} yield SettingQuerySuccess(json, key.key.manifest.toString)
121+
}
121122

122-
result match {
123+
def handleSettingQuery(req: SettingQuery, structure: BuildStructure): SettingQueryResponse =
124+
handleSettingQueryEither(req, structure) match {
123125
case Right(x) => x
124126
case Left(s) => SettingQueryFailure(s)
125127
}
126-
}
127128
}

server.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11

2+
$ cat ~/.sbt/1.0/server/0845deda85cb41abdb9f/token.json
3+
24
### initialize
35

46
```json
57
{ "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "initializationOptions": { "token": "************" } } }
68
```
79

8-
### ExecCommand
10+
### sbt/exec
911

1012
```json
1113
{ "jsonrpc": "2.0", "id": 1, "method": "sbt/exec", "params": { "commandLine": "compile" } }
1214
```
1315

16+
### sbt/setting
17+
18+
```json
19+
{ "jsonrpc": "2.0", "id": 1, "method": "sbt/setting", "params": { "setting": "root/name" } }
20+
```
21+
22+
Here's an example of a bad query:
23+
24+
```json
25+
{ "jsonrpc": "2.0", "id": 1, "method": "sbt/setting", "params": { "setting": "name" } }
26+
```
27+
28+
29+
```
30+
Content-Length: 104
31+
Content-Type: application/vscode-jsonrpc; charset=utf-8
32+
33+
{"jsonrpc":"2.0","id":"1","error":{"code":-32602,"message":"Not a valid project ID: name\nname\n ^"}}
34+
```

0 commit comments

Comments
 (0)