Skip to content

Commit 5ff5141

Browse files
committed
Support new Scala3 modifiers in SemanticDB
now we distinguish implicit and given in SemanticDB - Proposal to add new properties to SemanticDB schema - scalameta/scalameta#2439 - Generated scala code copied from - tanishiking/semanticdb-for-scala3#2
1 parent 121ae5a commit 5ff5141

File tree

5 files changed

+128
-49
lines changed

5 files changed

+128
-49
lines changed

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ class ExtractSemanticDB extends Phase:
281281
val (endLine, endCol) = lineCol(span.end)
282282
Some(Range(startLine, startCol, endLine, endCol))
283283

284-
285284
private def registerSymbol(sym: Symbol, symkinds: Set[SymbolKind])(using Context): Unit =
286285
val sname = sym.symbolName
287286
val isLocal = sname.isLocal

compiler/src/dotty/tools/dotc/semanticdb/PPrint.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class SymbolInfomationPrinter (symtab: PrinterSymtab):
4949
if info.isPrimary then sb.append("primary ")
5050
if info.isEnum then sb.append("enum ")
5151
if info.isDefault then sb.append("default ")
52+
if info.isGiven then sb.append("given ")
53+
if info.isInline then sb.append("inline ")
54+
if info.isOpen then sb.append("open ")
55+
if info.isTransparent then sb.append("transparent ")
56+
if info.isInfix then sb.append("infix ")
57+
if info.isOpaque then sb.append("opaque ")
5258
info.kind match
5359
case LOCAL => sb.append("local ")
5460
case FIELD => sb.append("field ")

compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,20 @@ object Scala3:
293293
props |= SymbolInformation.Property.STATIC.value
294294
if sym.is(Enum) then
295295
props |= SymbolInformation.Property.ENUM.value
296+
if sym.is(Given) then
297+
props |= SymbolInformation.Property.GIVEN.value
298+
if sym.is(Inline) then
299+
props |= SymbolInformation.Property.INLINE.value
300+
if sym.is(Open) then
301+
props |= SymbolInformation.Property.OPEN.value
302+
if sym.is(Open) then
303+
props |= SymbolInformation.Property.OPEN.value
304+
if sym.is(Transparent) then
305+
props |= SymbolInformation.Property.TRANSPARENT.value
306+
if sym.is(Infix) then
307+
props |= SymbolInformation.Property.INFIX.value
308+
if sym.is(Opaque) then
309+
props |= SymbolInformation.Property.OPAQUE.value
296310
props
297311

298312
def symbolAccess(kind: SymbolInformation.Kind)(using Context, SemanticSymbolBuilder): Access =
@@ -375,6 +389,12 @@ object Scala3:
375389
def isStatic: Boolean = (info.properties & SymbolInformation.Property.STATIC.value) != 0
376390
def isEnum: Boolean = (info.properties & SymbolInformation.Property.ENUM.value) != 0
377391
def isDefault: Boolean = (info.properties & SymbolInformation.Property.DEFAULT.value) != 0
392+
def isGiven: Boolean = (info.properties & SymbolInformation.Property.GIVEN.value) != 0
393+
def isInline: Boolean = (info.properties & SymbolInformation.Property.INLINE.value) != 0
394+
def isOpen: Boolean = (info.properties & SymbolInformation.Property.OPEN.value) != 0
395+
def isTransparent: Boolean = (info.properties & SymbolInformation.Property.TRANSPARENT.value) != 0
396+
def isInfix: Boolean = (info.properties & SymbolInformation.Property.INFIX.value) != 0
397+
def isOpaque: Boolean = (info.properties & SymbolInformation.Property.OPAQUE.value) != 0
378398

379399
def isUnknownKind: Boolean = info.kind.isUnknownKind
380400
def isLocal: Boolean = info.kind.isLocal

compiler/src/dotty/tools/dotc/semanticdb/SymbolInformation.scala

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ object SymbolInformation extends SemanticdbGeneratedMessageCompanion[dotty.tool
437437
def isPrimary: _root_.scala.Boolean = false
438438
def isEnum: _root_.scala.Boolean = false
439439
def isDefault: _root_.scala.Boolean = false
440+
def isGiven: _root_.scala.Boolean = false
441+
def isInline: _root_.scala.Boolean = false
442+
def isOpen: _root_.scala.Boolean = false
443+
def isTransparent: _root_.scala.Boolean = false
444+
def isInfix: _root_.scala.Boolean = false
445+
def isOpaque: _root_.scala.Boolean = false
440446

441447
final def asRecognized: _root_.scala.Option[dotty.tools.dotc.semanticdb.SymbolInformation.Property.Recognized] = if (isUnrecognized) _root_.scala.None else _root_.scala.Some(this.asInstanceOf[dotty.tools.dotc.semanticdb.SymbolInformation.Property.Recognized])
442448
}
@@ -549,10 +555,52 @@ object SymbolInformation extends SemanticdbGeneratedMessageCompanion[dotty.tool
549555
override def isDefault: _root_.scala.Boolean = true
550556
}
551557

558+
@SerialVersionUID(0L)
559+
case object GIVEN extends Property(65536) with Property.Recognized {
560+
val index = 15
561+
val name = "GIVEN"
562+
override def isGiven: _root_.scala.Boolean = true
563+
}
564+
565+
@SerialVersionUID(0L)
566+
case object INLINE extends Property(131072) with Property.Recognized {
567+
val index = 16
568+
val name = "INLINE"
569+
override def isInline: _root_.scala.Boolean = true
570+
}
571+
572+
@SerialVersionUID(0L)
573+
case object OPEN extends Property(262144) with Property.Recognized {
574+
val index = 17
575+
val name = "OPEN"
576+
override def isOpen: _root_.scala.Boolean = true
577+
}
578+
579+
@SerialVersionUID(0L)
580+
case object TRANSPARENT extends Property(524288) with Property.Recognized {
581+
val index = 18
582+
val name = "TRANSPARENT"
583+
override def isTransparent: _root_.scala.Boolean = true
584+
}
585+
586+
@SerialVersionUID(0L)
587+
case object INFIX extends Property(1048576) with Property.Recognized {
588+
val index = 19
589+
val name = "INFIX"
590+
override def isInfix: _root_.scala.Boolean = true
591+
}
592+
593+
@SerialVersionUID(0L)
594+
case object OPAQUE extends Property(2097152) with Property.Recognized {
595+
val index = 20
596+
val name = "OPAQUE"
597+
override def isOpaque: _root_.scala.Boolean = true
598+
}
599+
552600
@SerialVersionUID(0L)
553601
final case class Unrecognized(unrecognizedValue: _root_.scala.Int) extends Property(unrecognizedValue) with SemanticdbUnrecognizedEnum
554602

555-
lazy val values = scala.collection.immutable.Seq(UNKNOWN_PROPERTY, ABSTRACT, FINAL, SEALED, IMPLICIT, LAZY, CASE, COVARIANT, CONTRAVARIANT, VAL, VAR, STATIC, PRIMARY, ENUM, DEFAULT)
603+
lazy val values = scala.collection.immutable.Seq(UNKNOWN_PROPERTY, ABSTRACT, FINAL, SEALED, IMPLICIT, LAZY, CASE, COVARIANT, CONTRAVARIANT, VAL, VAR, STATIC, PRIMARY, ENUM, DEFAULT, GIVEN, INLINE, OPEN, TRANSPARENT, INFIX, OPAQUE)
556604
def fromValue(__value: _root_.scala.Int): Property = __value match {
557605
case 0 => UNKNOWN_PROPERTY
558606
case 4 => ABSTRACT
@@ -569,6 +617,12 @@ object SymbolInformation extends SemanticdbGeneratedMessageCompanion[dotty.tool
569617
case 8192 => PRIMARY
570618
case 16384 => ENUM
571619
case 32768 => DEFAULT
620+
case 65536 => GIVEN
621+
case 131072 => INLINE
622+
case 262144 => OPEN
623+
case 524288 => TRANSPARENT
624+
case 1048576 => INFIX
625+
case 2097152 => OPAQUE
572626
case __other => Unrecognized(__other)
573627
}
574628

0 commit comments

Comments
 (0)