@@ -6,6 +6,7 @@ import scala.tasty.file.TastyConsumer
66import scala .tasty .util .TreeTraverser
77import dotty .tools .dotc .tastyreflect
88import scala .collection .mutable .HashMap
9+ import scala .meta .internal .{semanticdb => s }
910
1011class SemanticdbConsumer extends TastyConsumer {
1112 var stack : List [String ] = Nil
@@ -32,6 +33,12 @@ class SemanticdbConsumer extends TastyConsumer {
3233 ""
3334 }
3435 }*/
36+ val semantic : s.TextDocument = s.TextDocument ()
37+ var occurrences : Seq [s.SymbolOccurrence ] = Seq ()
38+
39+ def toSemanticdb (text : String ): s.TextDocument = {
40+ s.TextDocument (text = text, occurrences = occurrences)
41+ }
3542
3643 final def apply (reflect : Reflection )(root : reflect.Tree ): Unit = {
3744 import reflect ._
@@ -65,6 +72,10 @@ class SemanticdbConsumer extends TastyConsumer {
6572 // TODO had a "NoDenotation" test to avoid
6673 // relying on the name itself
6774 " "
75+ } else if (symbol.name == " <root>" ) then {
76+ // TODO had a "NoDenotation" test to avoid
77+ // relying on the name itself
78+ " "
6879 } else {
6980 val previous_symbol = iterateParent(symbol.owner)
7081 val next_atom =
@@ -89,63 +100,30 @@ class SemanticdbConsumer extends TastyConsumer {
89100 val previous_path = stack.head
90101
91102 tree match {
92- /* case IsClassDef(body) =>
93- val ClassDef(name, _, _, _, _) = body
94- //println("[classdef] ", body)
95- val path = stack.head + name + "#"
96- println(path)
97- stack = path :: stack
98- super.traverseTree(body)
99- stack = stack.tail
100- case IsTypeDef(body) =>
101- println("[typedef] ", body)
102- super.traverseTree(body)
103- case IsDefDef(body) =>
104- val DefDef(name, _, _, _, _) = body
105- val def_atom =
106- name match {
107- case "<init>" => "`<init>`"
108- case _ => name
109- }
110- val path_repr = stack.head + def_atom
111- val path = path_repr + "(" + insertPathDefDef(path_repr) + ")."
112- println(path)
113- //println("[defdef] ", body)
114- stack = path :: stack
115- super.traverseTree(body)
116- stack = stack.tail
117- case IsValDef(body) =>
118- val ValDef(name, _, _) = body
119- val path_repr = stack.head + name
120- val path = path_repr + "(" + insertPathValDef(path_repr) + ")"
121- println(path)
122- //println("[defdef] ", body)
123- stack = path :: stack
124- super.traverseTree(body)
125- stack = stack.tail
126- case IsPackageDef(body) =>
127- println("[packagedef] ", body)
128- super.traverseTree(body)*/
129103 case IsDefinition (body) =>
130104 // println("[definition] ", body)
131- println(iterateParent(tree.symbol))
132- super .traverseTree(body)
133- /* case IsPackageClause(body) =>
134- //println(body.pos.start, body.pos.end)
135- val PackageClause(name, list_tree : List[Tree]) = body
136- //println(tree)
137- val path = packageDefToOccurence(name)
138- println(path)
139- stack = path :: stack
140- // call to traverse tree instead of super.traverseTree to avoid
141- // skipping this child entirely (super.xx will traverse subtrees)
142- //list_tree.foreach{traverseTree}
143- /* case IsTerm(body) =>
144- //println("[term] ", body)
145- super.traverseTree(body)*/
146- // iterating this way will probably make us see terms we don't want
105+ val symbol_path = iterateParent(tree.symbol)
106+
107+ val range =
108+ if (tree.symbol.name == " <init>" ) {
109+ s.Range (tree.symbol.pos.startLine,
110+ tree.symbol.pos.startColumn,
111+ tree.symbol.pos.startLine,
112+ tree.symbol.pos.endColumn)
113+ } else {
114+ s.Range (tree.symbol.pos.startLine,
115+ tree.symbol.pos.startColumn,
116+ tree.symbol.pos.startLine,
117+ tree.symbol.pos.startColumn + tree.symbol.name.length)
118+ }
119+ occurrences =
120+ occurrences :+
121+ s.SymbolOccurrence (
122+ Some (range),
123+ symbol_path,
124+ s.SymbolOccurrence .Role .DEFINITION
125+ )
147126 super .traverseTree(body)
148- stack = stack.tail*/
149127 case tree =>
150128 super .traverseTree(tree)
151129 }
0 commit comments