@@ -262,34 +262,37 @@ class EnsimeLanguageServer(in: InputStream, out: OutputStream) extends LanguageS
262
262
import scala .concurrent .ExecutionContext .Implicits ._
263
263
logger.info(s " Got hover request at ( ${position.line}, ${position.character}). " )
264
264
265
- // val res = for (doc <- documentManager.documentForUri(textDocument.uri)) yield {
266
- // val pos = doc.positionToOffset(position)
267
- // val future = ensimeActor ? TypeAtPointReq(
268
- // Right(toSourceFileInfo(textDocument.uri, Some(new String(doc.contents)))),
269
- // OffsetRange(pos, pos))
270
-
271
- // future.onComplete { f => logger.debug(s"Goto Definition future completed: succes? ${f.isSuccess}") }
272
-
273
- // future.map {
274
- // case typeInfo: TypeInfo =>
275
- // logger.info(s"Retrieved typeInfo $typeInfo")
276
- // Hover(Seq(RawMarkedString("scala", typeInfo.toString)), Some(Range(position, position)))
277
- // }
278
- // }
279
265
val res = for (doc <- documentManager.documentForUri(textDocument.uri)) yield {
280
- val future = ensimeActor ? DocUriAtPointReq (
281
- Right (toSourceFileInfo(textDocument.uri, Some (new String (doc.contents)))),
282
- OffsetRange (doc.positionToOffset(position)))
283
-
284
- future.onComplete { f => logger.debug(s " DocUriAtPointReq future completed: succes? ${f.isSuccess}" ) }
266
+ val pos = doc.positionToOffset(position)
285
267
286
- future.map {
268
+ val futureDocUriAtPoint = ensimeActor ? DocUriAtPointReq (
269
+ Right (toSourceFileInfo(textDocument.uri, Some (new String (doc.contents)))),
270
+ OffsetRange (pos))
271
+ futureDocUriAtPoint.onComplete { f => logger.debug(s " DocUriAtPointReq future completed: succes? ${f.isSuccess}" ) }
272
+ val futureDocStrOpt = futureDocUriAtPoint.map {
287
273
case Some (sigPair @ DocSigPair (DocSig (_, scalaSig), DocSig (_, javaSig))) =>
288
274
val sig = scalaSig.orElse(javaSig).getOrElse(" " )
289
275
logger.info(s " Retrieved signature $sig from @sigPair " )
290
- Hover (Seq (RawMarkedString (" scala" , sig)), Some (Range (position, position)))
276
+ Some (sig).filter(_ != " " )
277
+ }
278
+
279
+ val futureTypeAtPoint = ensimeActor ? TypeAtPointReq (
280
+ Right (toSourceFileInfo(textDocument.uri, Some (new String (doc.contents)))),
281
+ OffsetRange (pos, pos))
282
+ futureTypeAtPoint.onComplete { f => logger.debug(s " TypeAtPointReq future completed: succes? ${f.isSuccess}" ) }
283
+ val futureTypeStrOpt = futureTypeAtPoint.map {
284
+ case typeInfo : TypeInfo =>
285
+ logger.info(s " Retrieved typeInfo $typeInfo" )
286
+ // Some(typeInfo.name)
287
+ Some (typeInfo.fullName)
288
+ }
289
+
290
+ for {fdStrOpt <- futureDocStrOpt; ftStrOpt <- futureTypeStrOpt} yield {
291
+ val sig = fdStrOpt.orElse(ftStrOpt).getOrElse(" " )
292
+ Hover (Seq (RawMarkedString (" scala" , sig)), Some (Range (position, position)))
291
293
}
292
294
}
295
+
293
296
res.map { f => Await .result(f, 5 seconds) } getOrElse Hover (Nil , None )
294
297
}
295
298
0 commit comments