Skip to content

Commit 70fc3b6

Browse files
committed
fix several bugs
1 parent 0d460cb commit 70fc3b6

File tree

3 files changed

+45
-59
lines changed

3 files changed

+45
-59
lines changed

semanticdb/input/src/main/scala/example/Classes.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package example
22

33
class C1(val x1: Int) extends AnyVal
44

5-
//class C2(val x2: Int) extends AnyVal
6-
/*object C2
5+
class C2(val x2: Int) extends AnyVal
6+
object C2
77

88
case class C3(x: Int)
99

@@ -31,4 +31,3 @@ object N {
3131
local + 2
3232
}
3333
}
34-
*/

semanticdb/src/dotty/semanticdb/SemanticdbConsumer.scala

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
7070
}
7171
}
7272

73+
implicit class PatternExtender(tree: Pattern) {
74+
def isUserCreated: Boolean = {
75+
return !(tree.pos.exists && tree.pos.start == tree.pos.end)
76+
}
77+
}
78+
7379
implicit class SymbolExtender(symbol: Symbol) {
7480
def isClass: Boolean = symbol match {
7581
case IsClassSymbol(_) => true
@@ -251,9 +257,9 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
251257

252258
def resolveClass(symbol: ClassSymbol): Symbol =
253259
(symbol.companionClass, symbol.companionModule) match {
260+
case (Some(c), _) => c
254261
case (_, Some(module)) if symbol.flags.is(Flags.Object) => module
255-
case (Some(c), _) => c
256-
case _ => symbol
262+
case _ => symbol
257263
}
258264

259265
def disimbiguate(symbol_path: String, symbol: Symbol): String = {
@@ -379,7 +385,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
379385
if (is_global) {
380386
symbolPathsMap += key
381387
}
382-
println(symbol_path, range, symbol.owner.flags, is_global)
388+
println(symbol_path, range, symbol.owner.flags, is_global, iterateParent(symbol))
383389
occurrences =
384390
occurrences :+
385391
s.SymbolOccurrence(
@@ -389,14 +395,24 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
389395
)
390396
}
391397

392-
val reservedFunctions: List[String] = "apply" :: "unapply" :: Nil
398+
val reservedFunctions: List[String] = Nil
393399
def addOccurenceTree(tree: Tree,
394400
type_symbol: s.SymbolOccurrence.Role,
395401
range: s.Range,
396402
force_add: Boolean = false): Unit = {
397403
if (type_symbol != s.SymbolOccurrence.Role.DEFINITION && reservedFunctions
398404
.contains(tree.symbol.name))
399405
return
406+
/*println(tree.isUserCreated, iterateParent(tree.symbol), force_add)
407+
408+
val children: List[Position] =
409+
ChildTraverser.getChildren(tree)(reflect.rootContext).map(_.pos)
410+
println("#####", tree.pos.start, tree.pos.end)
411+
if (tree.symbol.pos.exists) {
412+
println("#####", tree.symbol.pos.start, tree.symbol.pos.end, tree, tree.symbol.name)
413+
414+
}
415+
children.foreach(p => println(p.start, p.end))*/
400416
if (tree.isUserCreated || (force_add && !(!tree.isUserCreated && iterateParent(
401417
tree.symbol) == "java/lang/Object#`<init>`()."))) {
402418
addOccurence(tree.symbol, type_symbol, range)
@@ -405,10 +421,18 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
405421
def addOccurenceTypeTree(typetree: TypeTree,
406422
type_symbol: s.SymbolOccurrence.Role,
407423
range: s.Range): Unit = {
424+
println(typetree)
408425
if (typetree.isUserCreated) {
409426
addOccurence(typetree.symbol, type_symbol, range)
410427
}
411428
}
429+
def addOccurencePatternTree(tree: Pattern,
430+
type_symbol: s.SymbolOccurrence.Role,
431+
range: s.Range): Unit = {
432+
if (tree.isUserCreated) {
433+
addOccurence(tree.symbol, type_symbol, range)
434+
}
435+
}
412436
def addOccurenceId(parent_path: String, id: Id): Unit = {
413437
val symbol_path = Symbols.Global(parent_path, d.Term(id.name))
414438
occurrences =
@@ -490,15 +514,16 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
490514
selectors: List[ImportSelector]): Unit = {
491515
selectors.foreach(selector =>
492516
selector match {
493-
case SimpleSelector(id) => {
517+
case SimpleSelector(id) if id.name != "_" => {
494518
addOccurenceId(parent_path, id)
495519
}
496-
case RenameSelector(id, _) => {
520+
case RenameSelector(id, _) if id.name != "_" => {
497521
addOccurenceId(parent_path, id)
498522
}
499-
case OmitSelector(id) => {
523+
case OmitSelector(id) if id.name != "_" => {
500524
addOccurenceId(parent_path, id)
501525
}
526+
case _ =>
502527
})
503528
}
504529

@@ -526,6 +551,10 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
526551
range)
527552
super.traverseTypeTree(typetree)
528553
}
554+
case TypeTree.Inferred() => {
555+
val typetree = extractTypeTree(tree)
556+
addOccurenceTypeTree(typetree, s.SymbolOccurrence.Role.REFERENCE, posToRange(typetree.pos).get)
557+
}
529558
case _ =>
530559
super.traverseTypeTree(tree)
531560
}
@@ -534,8 +563,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
534563
override def traversePattern(tree: Pattern)(implicit ctx: Context): Unit = {
535564
tree match {
536565
case Pattern.Bind(name, _) => {
537-
addOccurence(
538-
tree.symbol,
566+
addOccurencePatternTree(tree,
539567
s.SymbolOccurrence.Role.REFERENCE,
540568
s.Range(tree.symbol.pos.startLine,
541569
tree.symbol.pos.startColumn,
@@ -567,47 +595,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
567595
super.traverseTree(tree)
568596
}
569597
case ClassDef(classname, constr, parents, selfopt, statements) => {
570-
println("\n")
571-
val resolvedClassSymbol = tree.symbol.asClass.companionClass
572-
val resolvedObjectSymbol = tree.symbol.asClass.companionModule
573-
println(tree.symbol.flags)
574-
if (resolvedClassSymbol != None && resolvedClassSymbol.get.flags.isCase) {
575-
// case class
576-
if (resolvedClassSymbol.get == tree.symbol) {
577-
println("YES")
578-
// we first add the class to the symbol list
579-
addOccurenceTree(tree,
580-
s.SymbolOccurrence.Role.DEFINITION,
581-
range(tree, tree.symbol.pos, tree.symbol.name))
582598

583-
fittedInitClassRange = Some(
584-
s.Range(constr.symbol.pos.startLine,
585-
constr.symbol.pos.startColumn,
586-
constr.symbol.pos.endLine,
587-
constr.symbol.pos.endColumn))
588-
589-
traverseTree(constr)
590-
fittedInitClassRange = None
591-
} else {
592-
println("NO")
593-
}
594-
} else if (tree.symbol.flags.isObject && tree.symbol.flags.isCase) {
595-
println("YES object")
596-
// we first add the class to the symbol list
597-
addOccurenceTree(tree,
598-
s.SymbolOccurrence.Role.DEFINITION,
599-
range(tree, tree.symbol.pos, tree.symbol.name))
600-
601-
fittedInitClassRange = Some(
602-
s.Range(constr.symbol.pos.startLine,
603-
constr.symbol.pos.startColumn,
604-
constr.symbol.pos.endLine,
605-
constr.symbol.pos.endColumn))
606-
607-
traverseTree(constr)
608-
fittedInitClassRange = None
609-
println("NO object")
610-
} else {
611599
// we first add the class to the symbol list
612600
addOccurenceTree(tree,
613601
s.SymbolOccurrence.Role.DEFINITION,
@@ -669,7 +657,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
669657
}
670658

671659
statements.foreach(traverseTree)
672-
}
660+
673661
}
674662
case IsDefinition(cdef) => {
675663

@@ -740,8 +728,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
740728
}
741729
addOccurenceTree(tree,
742730
s.SymbolOccurrence.Role.REFERENCE,
743-
range,
744-
true)
731+
range)
745732
super.traverseTree(tree)
746733
}
747734

semanticdb/test/dotty/semanticdb/Tests.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,16 @@ class Tests {
195195
//@Test def testMethodUsages(): Unit = checkFile("example/MethodUsages.scala")
196196
//def testObjects(): Unit = checkFile("example/Objects.scala")
197197
//@Test def testOverrides(): Unit = checkFile("example/Overrides.scala")
198-
//WIP @Test def testPrefixes(): Unit = checkFile("example/Prefixes.scala")
198+
@Test def testPrefixes(): Unit = checkFile("example/Prefixes.scala")
199199
//@Test def testSelfs(): Unit = checkFile("example/Selfs.scala")
200200
//@Test def testSelfUse(): Unit = checkFile("example/SelfUse.scala")
201-
//WIP @Test def testSynthetic(): Unit = checkFile("example/Synthetic.scala")
201+
//@Test def testSynthetic(): Unit = checkFile("example/Synthetic.scala")
202202
//WIP @Test def testTraits(): Unit = checkFile("example/Traits.scala")
203-
//WIP @Test def testTypes(): Unit = checkFile("example/Types.scala")
203+
//@Test def testTypes(): Unit = checkFile("example/Types.scala")
204204
//@Test def testVals(): Unit = checkFile("example/Vals.scala")
205205
//@Test def testDependantModule(): Unit = checkFile("example/DependantModule.scala")
206206
//@Test def testNew(): Unit = checkFile("example/New.scala")
207207
//@Test def testIgnoredSymbol(): Unit = checkFile("example/IgnoredSymbol.scala")
208-
@Test def testCase(): Unit = checkFile("example/Case.scala")
208+
//@Test def testCase(): Unit = checkFile("example/Case.scala")
209209
//@Test def testApply(): Unit = checkFile("example/Apply.scala")
210210
}

0 commit comments

Comments
 (0)