Skip to content

Commit

Permalink
Support new Scala3 modifiers in SemanticDB
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tanishiking committed Aug 10, 2021
1 parent 121ae5a commit 5ff5141
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ class ExtractSemanticDB extends Phase:
val (endLine, endCol) = lineCol(span.end)
Some(Range(startLine, startCol, endLine, endCol))


private def registerSymbol(sym: Symbol, symkinds: Set[SymbolKind])(using Context): Unit =
val sname = sym.symbolName
val isLocal = sname.isLocal
Expand Down
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/semanticdb/PPrint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class SymbolInfomationPrinter (symtab: PrinterSymtab):
if info.isPrimary then sb.append("primary ")
if info.isEnum then sb.append("enum ")
if info.isDefault then sb.append("default ")
if info.isGiven then sb.append("given ")
if info.isInline then sb.append("inline ")
if info.isOpen then sb.append("open ")
if info.isTransparent then sb.append("transparent ")
if info.isInfix then sb.append("infix ")
if info.isOpaque then sb.append("opaque ")
info.kind match
case LOCAL => sb.append("local ")
case FIELD => sb.append("field ")
Expand Down
20 changes: 20 additions & 0 deletions compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@ object Scala3:
props |= SymbolInformation.Property.STATIC.value
if sym.is(Enum) then
props |= SymbolInformation.Property.ENUM.value
if sym.is(Given) then
props |= SymbolInformation.Property.GIVEN.value
if sym.is(Inline) then
props |= SymbolInformation.Property.INLINE.value
if sym.is(Open) then
props |= SymbolInformation.Property.OPEN.value
if sym.is(Open) then
props |= SymbolInformation.Property.OPEN.value
if sym.is(Transparent) then
props |= SymbolInformation.Property.TRANSPARENT.value
if sym.is(Infix) then
props |= SymbolInformation.Property.INFIX.value
if sym.is(Opaque) then
props |= SymbolInformation.Property.OPAQUE.value
props

def symbolAccess(kind: SymbolInformation.Kind)(using Context, SemanticSymbolBuilder): Access =
Expand Down Expand Up @@ -375,6 +389,12 @@ object Scala3:
def isStatic: Boolean = (info.properties & SymbolInformation.Property.STATIC.value) != 0
def isEnum: Boolean = (info.properties & SymbolInformation.Property.ENUM.value) != 0
def isDefault: Boolean = (info.properties & SymbolInformation.Property.DEFAULT.value) != 0
def isGiven: Boolean = (info.properties & SymbolInformation.Property.GIVEN.value) != 0
def isInline: Boolean = (info.properties & SymbolInformation.Property.INLINE.value) != 0
def isOpen: Boolean = (info.properties & SymbolInformation.Property.OPEN.value) != 0
def isTransparent: Boolean = (info.properties & SymbolInformation.Property.TRANSPARENT.value) != 0
def isInfix: Boolean = (info.properties & SymbolInformation.Property.INFIX.value) != 0
def isOpaque: Boolean = (info.properties & SymbolInformation.Property.OPAQUE.value) != 0

def isUnknownKind: Boolean = info.kind.isUnknownKind
def isLocal: Boolean = info.kind.isLocal
Expand Down
56 changes: 55 additions & 1 deletion compiler/src/dotty/tools/dotc/semanticdb/SymbolInformation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ object SymbolInformation extends SemanticdbGeneratedMessageCompanion[dotty.tool
def isPrimary: _root_.scala.Boolean = false
def isEnum: _root_.scala.Boolean = false
def isDefault: _root_.scala.Boolean = false
def isGiven: _root_.scala.Boolean = false
def isInline: _root_.scala.Boolean = false
def isOpen: _root_.scala.Boolean = false
def isTransparent: _root_.scala.Boolean = false
def isInfix: _root_.scala.Boolean = false
def isOpaque: _root_.scala.Boolean = false

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])
}
Expand Down Expand Up @@ -549,10 +555,52 @@ object SymbolInformation extends SemanticdbGeneratedMessageCompanion[dotty.tool
override def isDefault: _root_.scala.Boolean = true
}

@SerialVersionUID(0L)
case object GIVEN extends Property(65536) with Property.Recognized {
val index = 15
val name = "GIVEN"
override def isGiven: _root_.scala.Boolean = true
}

@SerialVersionUID(0L)
case object INLINE extends Property(131072) with Property.Recognized {
val index = 16
val name = "INLINE"
override def isInline: _root_.scala.Boolean = true
}

@SerialVersionUID(0L)
case object OPEN extends Property(262144) with Property.Recognized {
val index = 17
val name = "OPEN"
override def isOpen: _root_.scala.Boolean = true
}

@SerialVersionUID(0L)
case object TRANSPARENT extends Property(524288) with Property.Recognized {
val index = 18
val name = "TRANSPARENT"
override def isTransparent: _root_.scala.Boolean = true
}

@SerialVersionUID(0L)
case object INFIX extends Property(1048576) with Property.Recognized {
val index = 19
val name = "INFIX"
override def isInfix: _root_.scala.Boolean = true
}

@SerialVersionUID(0L)
case object OPAQUE extends Property(2097152) with Property.Recognized {
val index = 20
val name = "OPAQUE"
override def isOpaque: _root_.scala.Boolean = true
}

@SerialVersionUID(0L)
final case class Unrecognized(unrecognizedValue: _root_.scala.Int) extends Property(unrecognizedValue) with SemanticdbUnrecognizedEnum

lazy val values = scala.collection.immutable.Seq(UNKNOWN_PROPERTY, ABSTRACT, FINAL, SEALED, IMPLICIT, LAZY, CASE, COVARIANT, CONTRAVARIANT, VAL, VAR, STATIC, PRIMARY, ENUM, DEFAULT)
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)
def fromValue(__value: _root_.scala.Int): Property = __value match {
case 0 => UNKNOWN_PROPERTY
case 4 => ABSTRACT
Expand All @@ -569,6 +617,12 @@ object SymbolInformation extends SemanticdbGeneratedMessageCompanion[dotty.tool
case 8192 => PRIMARY
case 16384 => ENUM
case 32768 => DEFAULT
case 65536 => GIVEN
case 131072 => INLINE
case 262144 => OPEN
case 524288 => TRANSPARENT
case 1048576 => INFIX
case 2097152 => OPAQUE
case __other => Unrecognized(__other)
}

Expand Down
Loading

0 comments on commit 5ff5141

Please sign in to comment.