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

Commit bbd78b7

Browse files
author
fc
committed
Fixed textDocument/documentSymbol issue, added notofications, code format changes
1 parent ab14077 commit bbd78b7

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import java.nio.charset.Charset
4040
import langserver.core.MessageReader
4141

4242
class EnsimeLanguageServer(in: InputStream, out: OutputStream) extends LanguageServer(in, out) {
43-
private var system:ActorSystem = _
43+
private var system: ActorSystem = _
4444
private var fileStore: TempFileStore = _
4545

4646
// Ensime root actor

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import akka.actor.TypedActor.PostStop
2121

2222
class EnsimeProjectServer(langServer: EnsimeLanguageServer,
2323
implicit val config: EnsimeConfig,
24-
implicit val ensimeServerConfig:EnsimeServerConfig) extends Actor with LazyLogging {
24+
implicit val ensimeServerConfig: EnsimeServerConfig) extends Actor with LazyLogging {
2525
implicit val timeout: Timeout = Timeout(10 seconds)
2626

2727
val broadcaster = context.actorOf(Broadcaster(), "broadcaster")

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class Connection(inStream: InputStream, outStream: OutputStream)(val commandHand
9595
Option(Notification.read(notification)).fold(
9696
logger.error(s"No notification type exists with method=${notification.method}")
9797
)(_.fold(
98-
errors => logger.error(s"Invalid Notification: $errors"),
98+
errors => logger.error(s"Invalid Notification: $errors - Message: $message"),
9999
notifySubscribers))
100100

101101
case request: JsonRpcRequestMessage =>
@@ -161,16 +161,15 @@ 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-
logger.info("Result:"+result)
165164
val r = Try{
166165
result match {
167-
case ls:LocationSeq => JsonRpcResponseSuccessMessage(Json.toJson(ls.locs), id) //Special case, new play-json-rcp can not deal with Seq of JsValue
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
168168
case r => ResultResponse.write(r, id)
169169
}
170170
}
171171
r.recover{case e => logger.error("ResultResponse.write:"+result); e.printStackTrace }
172172
r.foreach{rJson =>
173-
logger.info("Result json:"+r)
174173
msgWriter.write(rJson)
175174
}
176175
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ case class DidCloseTextDocumentParams(textDocument: TextDocumentIdentifier) exte
225225
case class DidSaveTextDocumentParams(textDocument: TextDocumentIdentifier) extends Notification
226226
case class DidChangeWatchedFiles(changes: Seq[FileEvent]) extends Notification
227227

228+
case class Initialized() extends Notification
229+
object Initialized {
230+
implicit val format: Format[Initialized] = OFormat(
231+
Reads(jsValue => JsSuccess(Initialized())),
232+
OWrites[Initialized](s => Json.obj()))
233+
}
234+
235+
236+
case class CancelRequest(id: Int) extends Notification
237+
228238
case class FileEvent(uri: String, `type`: Int)
229239
object FileEvent { implicit val format = Json.format[FileEvent] }
230240

@@ -243,7 +253,10 @@ object Notification extends NotificationCompanion[Notification] {
243253
"textDocument/didChange" -> Json.format[DidChangeTextDocumentParams],
244254
"textDocument/didClose" -> Json.format[DidCloseTextDocumentParams],
245255
"textDocument/didSave" -> Json.format[DidSaveTextDocumentParams],
246-
"workspace/didChangeWatchedFiles" -> Json.format[DidChangeWatchedFiles])
256+
"workspace/didChangeWatchedFiles" -> Json.format[DidChangeWatchedFiles],
257+
"initialized" -> Initialized.format,
258+
"$/cancelRequest" -> Json.format[CancelRequest]
259+
)
247260
}
248261

249262
case class DocumentSymbolResult(params: Seq[SymbolInformation]) extends ResultResponse
@@ -261,6 +274,6 @@ object ResultResponse extends ResponseCompanion[Any] {
261274
"textDocument/definition" -> Json.format[LocationSeq],
262275
//"textDocument/definition" -> implicitly[Format[Seq[Location]]], //Runtime exception with latest play-json-rcp
263276
"textDocument/hover" -> Json.format[Hover],
264-
"textDocument/documentSymbol" -> valueFormat(DocumentSymbolResult)(_.params),
277+
"textDocument/documentSymbol" -> Json.format[DocumentSymbolResult],
265278
"shutdown" -> Json.format[ShutdownResult])
266279
}

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

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

0 commit comments

Comments
 (0)