Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit 5e33e16

Browse files
author
fc
committed
Removed scala-json-rpc workarounds using version 2.0.1
1 parent bbd78b7 commit 5e33e16

File tree

7 files changed

+15
-27
lines changed

7 files changed

+15
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Log level settting:
7373
"scalaLanguageServer.logLevel" : "DEBUG"
7474
}
7575

76-
This setting is passed to the Language Server affecting the log leven on the server, possible values "DEBUG", "ERROR", "INFO", "WARN"
76+
This setting is passed to the Language Server affecting the log level on the server, possible values "DEBUG", "ERROR", "INFO", "WARN"
7777

7878

7979
# Publish

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ lazy val languageserver = project.
2727
settings(commonSettings).
2828
settings(
2929
libraryDependencies ++= Seq(
30-
"com.dhpcs" %% "scala-json-rpc" % "2.0.0",
30+
"com.dhpcs" %% "scala-json-rpc" % "2.0.1",
3131
"com.typesafe.scala-logging" %% "scala-logging" % "3.7.2",
3232
"org.slf4j" % "slf4j-api" % "1.7.21",
3333
"ch.qos.logback" % "logback-classic" % "1.1.7",

ensime-lsp/src/main/scala/org/github/dragos/vscode/EnsimeLanguageServer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class EnsimeLanguageServer(in: InputStream, out: OutputStream) extends LanguageS
216216
res.map(f => CompletionList(false, Await.result(f, 5 seconds))) getOrElse CompletionList(false, Nil)
217217
}
218218

219-
override def gotoDefinitionRequest(textDocument: TextDocumentIdentifier, position: Position): LocationSeq = {
219+
override def gotoDefinitionRequest(textDocument: TextDocumentIdentifier, position: Position): DefinitionResult = {
220220
import scala.concurrent.ExecutionContext.Implicits._
221221
logger.info(s"Got goto definition request at (${position.line}, ${position.character}).")
222222

@@ -252,8 +252,8 @@ class EnsimeLanguageServer(in: InputStream, out: OutputStream) extends LanguageS
252252
}
253253
}
254254

255-
val r = (res.map { f => Await.result(f, 5 seconds) } getOrElse Seq.empty[Location])
256-
LocationSeq(r)
255+
val locs = res.map { f => Await.result(f, 5 seconds) } getOrElse Vector.empty[Location]
256+
DefinitionResult(locs)
257257
}
258258

259259
override def hoverRequest(textDocument: TextDocumentIdentifier, position: Position): Hover = {

languageserver/src/main/scala/langserver/core/Connection.scala

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,9 @@ class Connection(inStream: InputStream, outStream: OutputStream)(val commandHand
161161

162162
private def handleCommand(method: String, id: CorrelationId, command: ServerCommand) = {
163163
Future(commandHandler(method, command)).map { result =>
164-
val r = Try{
165-
result match {
166-
case ls: LocationSeq => JsonRpcResponseSuccessMessage(Json.toJson(ls.locs), id) //Special case, new play-json-rcp can not deal with Seq of JsValue
167-
case ds: DocumentSymbolResult => JsonRpcResponseSuccessMessage(Json.toJson(ds.params), id) //Special case, new play-json-rcp can not deal with Seq of JsValue
168-
case r => ResultResponse.write(r, id)
169-
}
170-
}
171-
r.recover{case e => logger.error("ResultResponse.write:"+result); e.printStackTrace }
172-
r.foreach{rJson =>
173-
msgWriter.write(rJson)
174-
}
164+
val t = Try{ResultResponse.write(result, id)}
165+
t.recover{case e => logger.error("ResultResponse.write:"+result); e.printStackTrace }
166+
t.foreach{rJson => msgWriter.write(rJson)}
175167
}
176168
}
177169
}

languageserver/src/main/scala/langserver/core/LanguageServer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ class LanguageServer(inStream: InputStream, outStream: OutputStream) extends Laz
8484

8585
}
8686

87-
def gotoDefinitionRequest(textDocument: TextDocumentIdentifier, position: Position): LocationSeq = {
88-
LocationSeq(Seq.empty[Location])
87+
def gotoDefinitionRequest(textDocument: TextDocumentIdentifier, position: Position): DefinitionResult = {
88+
DefinitionResult(Seq.empty[Location])
8989
}
9090

9191
def hoverRequest(textDocument: TextDocumentIdentifier, position: Position): Hover = {

languageserver/src/main/scala/langserver/messages/Commands.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,16 @@ object Notification extends NotificationCompanion[Notification] {
260260
}
261261

262262
case class DocumentSymbolResult(params: Seq[SymbolInformation]) extends ResultResponse
263-
264-
case class LocationSeq(locs: Seq[Location]) extends ResultResponse
263+
case class DefinitionResult(params: Seq[Location]) extends ResultResponse
265264

266265
object ResultResponse extends ResponseCompanion[Any] {
267266
import JsonRpcUtils._
268267

269-
implicit val positionParamsFormat = Json.format[Location]
270-
271268
override val ResponseFormats = Message.MessageFormats(
272269
"initialize" -> Json.format[InitializeResult],
273270
"textDocument/completion" -> Json.format[CompletionList],
274-
"textDocument/definition" -> Json.format[LocationSeq],
275-
//"textDocument/definition" -> implicitly[Format[Seq[Location]]], //Runtime exception with latest play-json-rcp
271+
"textDocument/definition" -> valueFormat(DefinitionResult)(_.params),
276272
"textDocument/hover" -> Json.format[Hover],
277-
"textDocument/documentSymbol" -> Json.format[DocumentSymbolResult],
273+
"textDocument/documentSymbol" -> valueFormat(DocumentSymbolResult)(_.params),
278274
"shutdown" -> Json.format[ShutdownResult])
279275
}

languageserver/src/main/scala/langserver/utils/JsonRpcUtils.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ object JsonRpcUtils {
3434
* )
3535
* }}}
3636
*/
37-
def valueFormat[A, B: OFormat](apply: B => A)(unapply: A => B): OFormat[A] = new OFormat[A] {
37+
def valueFormat[A, B: Format](apply: B => A)(unapply: A => B): Format[A] = new Format[A] {
3838
override def reads(json: JsValue) = Reads.of[B].reads(json).map(apply(_))
39-
override def writes(o: A) = Writes.of[B].writes(unapply(o)).as[JsObject]
39+
override def writes(o: A) = Writes.of[B].writes(unapply(o))
4040
}
4141
}

0 commit comments

Comments
 (0)