Skip to content

Commit

Permalink
feature: collect overridden symbols in Scala toplevel mtags
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Sep 1, 2023
1 parent f4eb439 commit 488efe5
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 102 deletions.
18 changes: 14 additions & 4 deletions mtags/src/main/scala/scala/meta/internal/mtags/Mtags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ final class Mtags(implicit rc: ReportContext) {
addLines(language, input.text)
mtags
.index()
.textDocument
.occurrences
.iterator
.filterNot(_.symbol.isPackage)
Expand All @@ -55,8 +56,9 @@ final class Mtags(implicit rc: ReportContext) {
JavaMtags
.index(input, includeMembers = true)
.index()
.textDocument
} else if (language.isScala) {
ScalaMtags.index(input, dialect).index()
ScalaMtags.index(input, dialect).index().textDocument
} else {
TextDocument()
}
Expand Down Expand Up @@ -91,11 +93,11 @@ object Mtags {
.toList
}

def allToplevels(
def allToplevelsEnriched(
input: Input.VirtualFile,
dialect: Dialect,
includeMembers: Boolean = true
)(implicit rc: ReportContext = EmptyReportContext): TextDocument = {
)(implicit rc: ReportContext = EmptyReportContext): EnrichedTextDocument = {
input.toLanguage match {
case Language.JAVA =>
new JavaMtags(input, includeMembers = true).index()
Expand All @@ -104,9 +106,17 @@ object Mtags {
new ScalaToplevelMtags(input, true, includeMembers, dialect)
mtags.index()
case _ =>
TextDocument()
JustDocument(TextDocument())
}
}

def allToplevels(
input: Input.VirtualFile,
dialect: Dialect,
includeMembers: Boolean = true
)(implicit rc: ReportContext = EmptyReportContext): TextDocument =
allToplevelsEnriched(input, dialect, includeMembers).textDocument

def toplevels(
input: Input.VirtualFile,
dialect: Dialect = dialects.Scala213
Expand Down
48 changes: 29 additions & 19 deletions mtags/src/main/scala/scala/meta/internal/mtags/MtagsIndexer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ import scala.meta.internal.semanticdb.Scala._
import scala.meta.internal.semanticdb.SymbolInformation.Kind
import scala.meta.internal.{semanticdb => s}

trait MtagsIndexer {
trait GenericMtagsIndexer[T <: EnrichedTextDocument] {
def language: Language
def indexRoot(): Unit
def input: Input.VirtualFile
def index(): s.TextDocument = {
protected def documentToResult(doc: s.TextDocument): T
def index(): T = {
indexRoot()
s.TextDocument(
uri = input.path,
text = input.text,
language = language,
occurrences = names.result(),
symbols = symbols.result()
documentToResult(
s.TextDocument(
uri = input.path,
text = input.text,
language = language,
occurrences = names.result(),
symbols = symbols.result()
)
)
}
// This method is intentionally non-final to allow accessing this stream directly without building a s.TextDocument.
Expand Down Expand Up @@ -64,8 +67,8 @@ trait MtagsIndexer {
)
}
}
def term(name: String, pos: m.Position, kind: Kind, properties: Int, overriddenSymbols: List[(String, m.Position)] = List.empty): String =
addSignature(Descriptor.Term(name), pos, kind, properties, overriddenSymbols)
def term(name: String, pos: m.Position, kind: Kind, properties: Int): String =
addSignature(Descriptor.Term(name), pos, kind, properties)
def term(name: Term.Name, kind: Kind, properties: Int): String =
addSignature(Descriptor.Term(name.value), name.pos, kind, properties)
def tparam(name: Name, kind: Kind, properties: Int): String =
Expand Down Expand Up @@ -122,8 +125,8 @@ trait MtagsIndexer {
properties
)
}
def tpe(name: String, pos: m.Position, kind: Kind, properties: Int, overriddenSymbols: List[(String, m.Position)] = List.empty): String =
addSignature(Descriptor.Type(name), pos, kind, properties, overriddenSymbols)
def tpe(name: String, pos: m.Position, kind: Kind, properties: Int): String =
addSignature(Descriptor.Type(name), pos, kind, properties)
def tpe(name: Name, kind: Kind, properties: Int): String =
addSignature(Descriptor.Type(name.value), name.pos, kind, properties)
def pkg(name: String, pos: m.Position): String = {
Expand All @@ -141,8 +144,7 @@ trait MtagsIndexer {
signature: Descriptor,
definition: m.Position,
kind: s.SymbolInformation.Kind,
properties: Int,
overriddenSymbols: List[(String, m.Position)] = List.empty
properties: Int
): String = {
val previousOwner = currentOwner
currentOwner = symbol(signature)
Expand All @@ -156,16 +158,12 @@ trait MtagsIndexer {
syntax,
role
)
val encodedOverriddenSymbols = overriddenSymbols.map{
case (simpleName, pos) => UnresolvedOverriddenSymbol(simpleName, pos.start)
}
val info = s.SymbolInformation(
symbol = syntax,
language = language,
kind = kind,
properties = properties,
displayName = signature.name.value,
overriddenSymbols = encodedOverriddenSymbols
displayName = signature.name.value
)
visitOccurrence(occ, info, previousOwner)
syntax
Expand All @@ -175,3 +173,15 @@ trait MtagsIndexer {
Symbols.Global(Symbols.RootPackage, signature)
else Symbols.Global(currentOwner, signature)
}

trait EnrichedTextDocument {
def textDocument: s.TextDocument
}

case class JustDocument(textDocument: s.TextDocument)
extends EnrichedTextDocument

trait MtagsIndexer extends GenericMtagsIndexer[JustDocument] {
protected def documentToResult(doc: s.TextDocument): JustDocument =
JustDocument(doc)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package scala.meta.internal.mtags

sealed trait OverriddenSymbol
case class UnresolvedOverriddenSymbol(name: String, pos: Int)
extends OverriddenSymbol
case class ResolvedOverriddenSymbol(symbol: String) extends OverriddenSymbol
Loading

0 comments on commit 488efe5

Please sign in to comment.