@@ -11,7 +11,9 @@ import scala.meta.internal.{semanticdb => s}
11
11
import dotty .semanticdb .Scala .{Descriptor => d }
12
12
import dotty .semanticdb .Scala ._
13
13
14
- class SemanticdbConsumer extends TastyConsumer {
14
+ import scala .io .Source
15
+
16
+ class SemanticdbConsumer (sourceFile : java.nio.file.Path ) extends TastyConsumer {
15
17
var stack : List [String ] = Nil
16
18
17
19
val semantic : s.TextDocument = s.TextDocument ()
@@ -24,6 +26,8 @@ class SemanticdbConsumer extends TastyConsumer {
24
26
val symbolsCache : HashMap [(String , s.Range ), String ] = HashMap ()
25
27
var local_offset : Int = 0
26
28
29
+ val sourceCode = Source .fromFile(sourceFile.toFile).mkString
30
+
27
31
final def apply (reflect : Reflection )(root : reflect.Tree ): Unit = {
28
32
import reflect ._
29
33
@@ -373,7 +377,6 @@ class SemanticdbConsumer extends TastyConsumer {
373
377
if (symbolPathsMap.contains(key)) return
374
378
if (is_global) {
375
379
symbolPathsMap += key
376
- println(" duplicates" , key)
377
380
}
378
381
println(symbol_path, range, symbol.owner.flags, is_global)
379
382
occurrences =
@@ -591,34 +594,34 @@ class SemanticdbConsumer extends TastyConsumer {
591
594
parents.foreach(_ match {
592
595
case IsTypeTree (t) => traverseTypeTree(t)
593
596
case IsTerm (t) => {
594
- println(t.pos.startColumn, t.pos.endColumn)
595
597
traverseTree(t)
596
598
}
597
599
})
598
600
forceAddBecauseParents = false
599
601
600
602
selfopt match {
601
- case Some (vdef @ ValDef (name, _, _)) => {
602
- val posColumn : Int = parents.foldLeft(vdef.pos.startColumn)(
603
+ case Some (vdef @ ValDef (name, _, _)) if name != " _" => {
604
+ // To find the current position, we will heuristically
605
+ // reparse the source code.
606
+ // The process is done in three steps:
607
+ // 1) Find a position before the '{' of the self but after any
608
+ // non related '{'. Here, it will be the largest end pos of a parent
609
+ // 2) Find the first '{'
610
+ // 3) Iterate until the character we are seeing is a letter
611
+ val startPosSearch : Int = parents.foldLeft(tree.pos.endColumn)(
603
612
(old : Int , ct : TermOrTypeTree ) =>
604
613
ct match {
605
- case IsTerm (t) =>
606
- if (t.pos.endColumn + 3 < old) { t.pos.endColumn + 3 } else {
607
- old
608
- }
614
+ case IsTerm (t) if t.pos.endColumn < old => t.pos.endColumn
609
615
case _ => old
610
616
})
611
- println(posColumn)
612
- println(vdef)
613
- println(vdef.pos.startColumn,
614
- tree.pos.startColumn,
615
- tree.pos.endColumn)
617
+ var posColumn = sourceCode.indexOf(" {" , startPosSearch)
618
+ while (! sourceCode(posColumn).isLetter && posColumn < sourceCode.length) posColumn += 1
619
+
616
620
addSelfDefinition(name,
617
621
s.Range (vdef.pos.startLine,
618
622
posColumn,
619
623
vdef.pos.endLine,
620
624
posColumn + name.length))
621
- println(name)
622
625
}
623
626
case _ =>
624
627
}
0 commit comments