@@ -240,17 +240,20 @@ class DottyLanguageServer extends LanguageServer
240
240
val document = params.getTextDocument
241
241
val uri = new URI (document.getUri)
242
242
val driver = driverFor(uri)
243
+ implicit def ctx : Context = driver.currentCtx
243
244
val worksheetMode = isWorksheet(uri)
244
245
245
- val (text, positionMapper) =
246
- if (worksheetMode) (wrapWorksheet(document.getText), Some (toUnwrappedPosition _))
247
- else (document.getText, None )
246
+ val text =
247
+ if (worksheetMode)
248
+ wrapWorksheet(document.getText)
249
+ else
250
+ document.getText
248
251
249
252
val diags = driver.run(uri, text)
250
253
251
254
client.publishDiagnostics(new PublishDiagnosticsParams (
252
255
document.getUri,
253
- diags.flatMap(diagnostic(_, positionMapper)(driver.currentCtx) ).asJava))
256
+ diags.flatMap(diagnostic).asJava))
254
257
}
255
258
256
259
override def didChange (params : DidChangeTextDocumentParams ): Unit = {
@@ -262,19 +265,22 @@ class DottyLanguageServer extends LanguageServer
262
265
checkMemory()
263
266
264
267
val driver = driverFor(uri)
268
+ implicit def ctx : Context = driver.currentCtx
265
269
266
270
val change = params.getContentChanges.get(0 )
267
271
assert(change.getRange == null , " TextDocumentSyncKind.Incremental support is not implemented" )
268
272
269
- val (text, positionMapper) =
270
- if (worksheetMode) (wrapWorksheet(change.getText), Some (toUnwrappedPosition _))
271
- else (change.getText, None )
273
+ val text =
274
+ if (worksheetMode)
275
+ wrapWorksheet(change.getText)
276
+ else
277
+ change.getText
272
278
273
279
val diags = driver.run(uri, text)
274
280
275
281
client.publishDiagnostics(new PublishDiagnosticsParams (
276
282
document.getUri,
277
- diags.flatMap(diagnostic(_, positionMapper)(driver.currentCtx) ).asJava))
283
+ diags.flatMap(diagnostic).asJava))
278
284
}
279
285
}
280
286
@@ -299,7 +305,7 @@ class DottyLanguageServer extends LanguageServer
299
305
override def completion (params : CompletionParams ) = computeAsync { cancelToken =>
300
306
val uri = new URI (params.getTextDocument.getUri)
301
307
val driver = driverFor(uri)
302
- implicit val ctx = driver.currentCtx
308
+ implicit def ctx : Context = driver.currentCtx
303
309
304
310
val pos = sourcePosition(driver, uri, params.getPosition)
305
311
val items = driver.compilationUnits.get(uri) match {
@@ -318,13 +324,13 @@ class DottyLanguageServer extends LanguageServer
318
324
override def definition (params : TextDocumentPositionParams ) = computeAsync { cancelToken =>
319
325
val uri = new URI (params.getTextDocument.getUri)
320
326
val driver = driverFor(uri)
321
- implicit val ctx = driver.currentCtx
327
+ implicit def ctx : Context = driver.currentCtx
322
328
323
329
val pos = sourcePosition(driver, uri, params.getPosition)
324
330
val path = Interactive .pathTo(driver.openedTrees(uri), pos)
325
331
326
332
val definitions = Interactive .findDefinitions(path, pos, driver).toList
327
- definitions.flatMap(d => location(d.namePos, positionMapperFor(d.source) )).asJava
333
+ definitions.flatMap(d => location(d.namePos)).asJava
328
334
}
329
335
330
336
override def references (params : ReferenceParams ) = computeAsync { cancelToken =>
@@ -341,7 +347,7 @@ class DottyLanguageServer extends LanguageServer
341
347
val pos = sourcePosition(driver, uri, params.getPosition)
342
348
343
349
val (definitions, originalSymbols) = {
344
- implicit val ctx : Context = driver.currentCtx
350
+ implicit def ctx : Context = driver.currentCtx
345
351
val path = Interactive .pathTo(driver.openedTrees(uri), pos)
346
352
val definitions = Interactive .findDefinitions(path, pos, driver)
347
353
val originalSymbols = Interactive .enclosingSourceSymbols(path, pos)
@@ -359,7 +365,7 @@ class DottyLanguageServer extends LanguageServer
359
365
val name = definition.name(ctx).sourceModuleName.toString
360
366
val trees = remoteDriver.sourceTreesContaining(name)(ctx)
361
367
val matches = Interactive .findTreesMatching(trees, includes, definition)(ctx)
362
- matches.map(tree => location(tree.namePos(ctx), positionMapperFor(tree.source) ))
368
+ matches.map(tree => location(tree.namePos(ctx)))
363
369
}
364
370
}
365
371
}.toList
@@ -370,7 +376,7 @@ class DottyLanguageServer extends LanguageServer
370
376
override def rename (params : RenameParams ) = computeAsync { cancelToken =>
371
377
val uri = new URI (params.getTextDocument.getUri)
372
378
val driver = driverFor(uri)
373
- implicit val ctx = driver.currentCtx
379
+ implicit def ctx : Context = driver.currentCtx
374
380
375
381
val uriTrees = driver.openedTrees(uri)
376
382
val pos = sourcePosition(driver, uri, params.getPosition)
@@ -429,15 +435,15 @@ class DottyLanguageServer extends LanguageServer
429
435
.flatMap((uriOpt, ref) => uriOpt.map(uri => (uri.toString, ref)))
430
436
.mapValues(refs =>
431
437
refs.flatMap(ref =>
432
- range(ref.namePos, positionMapperFor(ref.source) ).map(nameRange => new TextEdit (nameRange, newName))).distinct.asJava)
438
+ range(ref.namePos).map(nameRange => new TextEdit (nameRange, newName))).distinct.asJava)
433
439
434
440
new WorkspaceEdit (changes.asJava)
435
441
}
436
442
437
443
override def documentHighlight (params : TextDocumentPositionParams ) = computeAsync { cancelToken =>
438
444
val uri = new URI (params.getTextDocument.getUri)
439
445
val driver = driverFor(uri)
440
- implicit val ctx = driver.currentCtx
446
+ implicit def ctx : Context = driver.currentCtx
441
447
442
448
val pos = sourcePosition(driver, uri, params.getPosition)
443
449
val uriTrees = driver.openedTrees(uri)
@@ -449,15 +455,15 @@ class DottyLanguageServer extends LanguageServer
449
455
val refs = Interactive .findTreesMatching(uriTrees, includes, sym)
450
456
(for {
451
457
ref <- refs
452
- nameRange <- range(ref.namePos, positionMapperFor(ref.source) )
458
+ nameRange <- range(ref.namePos)
453
459
} yield new DocumentHighlight (nameRange, DocumentHighlightKind .Read ))
454
460
}.distinct.asJava
455
461
}
456
462
457
463
override def hover (params : TextDocumentPositionParams ) = computeAsync { cancelToken =>
458
464
val uri = new URI (params.getTextDocument.getUri)
459
465
val driver = driverFor(uri)
460
- implicit val ctx = driver.currentCtx
466
+ implicit def ctx : Context = driver.currentCtx
461
467
462
468
val pos = sourcePosition(driver, uri, params.getPosition)
463
469
val trees = driver.openedTrees(uri)
@@ -481,26 +487,26 @@ class DottyLanguageServer extends LanguageServer
481
487
override def documentSymbol (params : DocumentSymbolParams ) = computeAsync { cancelToken =>
482
488
val uri = new URI (params.getTextDocument.getUri)
483
489
val driver = driverFor(uri)
484
- implicit val ctx = driver.currentCtx
490
+ implicit def ctx : Context = driver.currentCtx
485
491
486
492
val uriTrees = driver.openedTrees(uri)
487
493
488
494
val defs = Interactive .namedTrees(uriTrees, Include .empty)
489
495
(for {
490
496
d <- defs if ! isWorksheetWrapper(d)
491
- info <- symbolInfo(d.tree.symbol, d.namePos, positionMapperFor(d.source) )
497
+ info <- symbolInfo(d.tree.symbol, d.namePos)
492
498
} yield JEither .forLeft(info)).asJava
493
499
}
494
500
495
501
override def symbol (params : WorkspaceSymbolParams ) = computeAsync { cancelToken =>
496
502
val query = params.getQuery
497
503
498
504
drivers.values.toList.flatMap { driver =>
499
- implicit val ctx = driver.currentCtx
505
+ implicit def ctx : Context = driver.currentCtx
500
506
501
507
val trees = driver.sourceTreesContaining(query)
502
508
val defs = Interactive .namedTrees(trees, Include .empty, _.name.toString.contains(query))
503
- defs.flatMap(d => symbolInfo(d.tree.symbol, d.namePos, positionMapperFor(d.source) ))
509
+ defs.flatMap(d => symbolInfo(d.tree.symbol, d.namePos))
504
510
}.asJava
505
511
}
506
512
@@ -511,7 +517,7 @@ class DottyLanguageServer extends LanguageServer
511
517
val pos = sourcePosition(driver, uri, params.getPosition)
512
518
513
519
val (definitions, originalSymbols) = {
514
- implicit val ctx : Context = driver.currentCtx
520
+ implicit def ctx : Context = driver.currentCtx
515
521
val path = Interactive .pathTo(driver.openedTrees(uri), pos)
516
522
val originalSymbols = Interactive .enclosingSourceSymbols(path, pos)
517
523
val definitions = Interactive .findDefinitions(path, pos, driver)
@@ -528,7 +534,7 @@ class DottyLanguageServer extends LanguageServer
528
534
tree => predicates.exists(_(tree))
529
535
}
530
536
val matches = Interactive .namedTrees(trees, Include .local, predicate)(ctx)
531
- matches.map(tree => location(tree.namePos(ctx), positionMapperFor(tree.source) ))
537
+ matches.map(tree => location(tree.namePos(ctx)))
532
538
}
533
539
}.toList
534
540
@@ -539,7 +545,7 @@ class DottyLanguageServer extends LanguageServer
539
545
540
546
val uri = new URI (params.getTextDocument.getUri)
541
547
val driver = driverFor(uri)
542
- implicit val ctx = driver.currentCtx
548
+ implicit def ctx : Context = driver.currentCtx
543
549
544
550
val pos = sourcePosition(driver, uri, params.getPosition)
545
551
val trees = driver.openedTrees(uri)
@@ -653,9 +659,9 @@ object DottyLanguageServer {
653
659
}
654
660
655
661
/** Convert a SourcePosition to an lsp4j.Range */
656
- def range (p : SourcePosition , positionMapper : Option [ SourcePosition => SourcePosition ] = None ): Option [lsp4j.Range ] =
662
+ def range (p : SourcePosition ): Option [lsp4j.Range ] =
657
663
if (p.exists) {
658
- val mappedPosition = positionMapper .map(_(p)).getOrElse(p)
664
+ val mappedPosition = positionMapperFor(p.source) .map(_(p)).getOrElse(p)
659
665
Some (new lsp4j.Range (
660
666
new lsp4j.Position (mappedPosition.startLine, mappedPosition.startColumn),
661
667
new lsp4j.Position (mappedPosition.endLine, mappedPosition.endColumn)
@@ -664,19 +670,16 @@ object DottyLanguageServer {
664
670
None
665
671
666
672
/** Convert a SourcePosition to an lsp4.Location */
667
- def location (p : SourcePosition , positionMapper : Option [ SourcePosition => SourcePosition ] = None ): Option [lsp4j.Location ] =
673
+ def location (p : SourcePosition ): Option [lsp4j.Location ] =
668
674
for {
669
675
uri <- toUriOption(p.source)
670
- r <- range(p, positionMapper )
676
+ r <- range(p)
671
677
} yield new lsp4j.Location (uri.toString, r)
672
678
673
679
/**
674
- * Convert a MessageContainer to an lsp4j.Diagnostic. The positions are transformed vy
675
- * `positionMapper`.
680
+ * Convert a MessageContainer to an lsp4j.Diagnostic.
676
681
*/
677
- def diagnostic (mc : MessageContainer ,
678
- positionMapper : Option [SourcePosition => SourcePosition ] = None
679
- )(implicit ctx : Context ): Option [lsp4j.Diagnostic ] =
682
+ def diagnostic (mc : MessageContainer )(implicit ctx : Context ): Option [lsp4j.Diagnostic ] =
680
683
if (! mc.pos.exists)
681
684
None // diagnostics without positions are not supported: https://github.com/Microsoft/language-server-protocol/issues/249
682
685
else {
@@ -697,7 +700,7 @@ object DottyLanguageServer {
697
700
val message = mc.contained()
698
701
if (displayMessage(message, mc.pos.source)) {
699
702
val code = message.errorId.errorNumber.toString
700
- range(mc.pos, positionMapper ).map(r =>
703
+ range(mc.pos).map(r =>
701
704
new lsp4j.Diagnostic (
702
705
r, mc.message, severity(mc.level), /* source =*/ " " , code))
703
706
} else {
@@ -866,7 +869,7 @@ object DottyLanguageServer {
866
869
}
867
870
868
871
/** Create an lsp4j.SymbolInfo from a Symbol and a SourcePosition */
869
- def symbolInfo (sym : Symbol , pos : SourcePosition , positionMapper : Option [ SourcePosition => SourcePosition ] )(implicit ctx : Context ): Option [lsp4j.SymbolInformation ] = {
872
+ def symbolInfo (sym : Symbol , pos : SourcePosition )(implicit ctx : Context ): Option [lsp4j.SymbolInformation ] = {
870
873
def symbolKind (sym : Symbol )(implicit ctx : Context ): lsp4j.SymbolKind = {
871
874
import lsp4j .{SymbolKind => SK }
872
875
@@ -893,7 +896,7 @@ object DottyLanguageServer {
893
896
else
894
897
null
895
898
896
- location(pos, positionMapper ).map(l => new lsp4j.SymbolInformation (name, symbolKind(sym), l, containerName))
899
+ location(pos).map(l => new lsp4j.SymbolInformation (name, symbolKind(sym), l, containerName))
897
900
}
898
901
899
902
/** Convert `signature` to a `SignatureInformation` */
0 commit comments