Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buigfix: given scala toplevel mtags #5247

Merged
merged 2 commits into from May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion metals-bench/src/main/scala/bench/MetalsBench.scala
Expand Up @@ -6,6 +6,7 @@ import scala.tools.nsc.interactive.Global

import scala.meta.dialects
import scala.meta.interactive.InteractiveSemanticdb
import scala.meta.internal.metals.EmptyReportContext
import scala.meta.internal.metals.JdkSources
import scala.meta.internal.metals.logging.MetalsLogger
import scala.meta.internal.mtags.Mtags
Expand Down Expand Up @@ -148,7 +149,7 @@ class MetalsBench {
@Benchmark
@BenchmarkMode(Array(Mode.SingleShotTime))
def indexSources(): Unit = {
val index = OnDemandSymbolIndex.empty()
val index = OnDemandSymbolIndex.empty()(EmptyReportContext)
fullClasspath.entries.foreach(entry =>
index.addSourceJar(entry, dialects.Scala213)
)
Expand Down
Expand Up @@ -13,6 +13,7 @@ import scala.meta.internal.metals.Buffers
import scala.meta.internal.metals.BuildTargets
import scala.meta.internal.metals.DefinitionProvider
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.metals.ReportContext
import scala.meta.internal.metals.ScalaVersionSelector
import scala.meta.internal.metals.SemanticdbFeatureProvider
import scala.meta.internal.mtags.GlobalSymbolIndex
Expand Down Expand Up @@ -46,7 +47,7 @@ final class ImplementationProvider(
definitionProvider: DefinitionProvider,
trees: Trees,
scalaVersionSelector: ScalaVersionSelector,
)(implicit ec: ExecutionContext)
)(implicit ec: ExecutionContext, rc: ReportContext)
extends SemanticdbFeatureProvider {
import ImplementationProvider._

Expand Down
Expand Up @@ -75,7 +75,7 @@ class Compilers(
trees: Trees,
mtagsResolver: MtagsResolver,
sourceMapper: SourceMapper,
)(implicit ec: ExecutionContextExecutorService)
)(implicit ec: ExecutionContextExecutorService, rc: ReportContext)
extends Cancelable {
val plugins = new CompilerPlugins()

Expand Down
Expand Up @@ -66,7 +66,7 @@ final class DefinitionProvider(
saveDefFileToDisk: Boolean,
sourceMapper: SourceMapper,
workspaceSearch: WorkspaceSymbolProvider,
)(implicit ec: ExecutionContext) {
)(implicit ec: ExecutionContext, rc: ReportContext) {

val destinationProvider = new DestinationProvider(
index,
Expand Down
Expand Up @@ -79,7 +79,7 @@ final case class Indexer(
symbolDocs: Docstrings,
scalaVersionSelector: ScalaVersionSelector,
sourceMapper: SourceMapper,
) {
)(implicit rc: ReportContext) {

private implicit def ec: ExecutionContextExecutorService = executionContext

Expand Down
Expand Up @@ -24,7 +24,8 @@ class MetalsSymbolSearch(
docs: Docstrings,
wsp: WorkspaceSymbolProvider,
defn: DefinitionProvider,
) extends SymbolSearch {
)(implicit rc: ReportContext)
extends SymbolSearch {
// A cache for definitionSourceToplevels.
// The key is an absolute path to the dependency source file, and
// the value is the list of symbols that the file contains.
Expand Down
Expand Up @@ -30,7 +30,8 @@ class StandaloneSymbolSearch(
saveSymbolFileToDisk: Boolean,
sourceMapper: SourceMapper,
workspaceFallback: Option[SymbolSearch] = None,
) extends SymbolSearch {
)(implicit rc: ReportContext)
extends SymbolSearch {

private val dependencySourceCache =
new TrieMap[AbsolutePath, ju.List[String]]()
Expand Down Expand Up @@ -131,7 +132,7 @@ object StandaloneSymbolSearch {
buildTargets: BuildTargets,
saveSymbolFileToDisk: Boolean,
sourceMapper: SourceMapper,
): StandaloneSymbolSearch = {
)(implicit rc: ReportContext): StandaloneSymbolSearch = {
val (sourcesWithExtras, classpathWithExtras) =
addScalaAndJava(
scalaVersion,
Expand Down Expand Up @@ -162,7 +163,7 @@ object StandaloneSymbolSearch {
buildTargets: BuildTargets,
saveSymbolFileToDisk: Boolean,
sourceMapper: SourceMapper,
): StandaloneSymbolSearch = {
)(implicit rc: ReportContext): StandaloneSymbolSearch = {
val (sourcesWithExtras, classpathWithExtras) =
addScalaAndJava(scalaVersion, Nil, Nil, userConfig().javaHome)

Expand Down
Expand Up @@ -104,6 +104,7 @@ class WorkspaceLspService(
) extends ScalaLspService {
import serverInputs._
implicit val ex: ExecutionContextExecutorService = ec
implicit val rc: ReportContext = LoggerReportContext
private val cancelables = new MutableCancelable()

private val clientConfig =
Expand Down
Expand Up @@ -32,7 +32,8 @@ class WorkspaceSearchVisitor(
token: CancelChecker,
index: GlobalSymbolIndex,
saveClassFileToDisk: Boolean,
) extends SymbolSearchVisitor {
)(implicit rc: ReportContext)
extends SymbolSearchVisitor {
private val fromWorkspace = new ju.ArrayList[l.SymbolInformation]()
private val fromClasspath = new ju.ArrayList[l.SymbolInformation]()
private val bufferedClasspath = new ju.ArrayList[(String, String)]()
Expand Down
Expand Up @@ -29,7 +29,7 @@ final class WorkspaceSymbolProvider(
bucketSize: Int = CompressedPackageIndex.DefaultBucketSize,
classpathSearchIndexer: ClasspathSearch.Indexer =
ClasspathSearch.Indexer.default,
) {
)(implicit rc: ReportContext) {
val inWorkspace: TrieMap[Path, WorkspaceSymbolsIndex] =
TrieMap.empty[Path, WorkspaceSymbolsIndex]

Expand Down
Expand Up @@ -26,7 +26,8 @@ class MetalsTreeViewProvider(
getFolderTreeViewProviders: () => List[FolderTreeViewProvider],
languageClient: MetalsLanguageClient,
sh: ScheduledExecutorService,
) extends TreeViewProvider {
)(implicit rc: ReportContext)
extends TreeViewProvider {
private val ticks =
TrieMap.empty[String, ScheduledFuture[_]]

Expand Down
Expand Up @@ -28,7 +28,7 @@ import scala.meta.pc.SymbolDocumentation
*
* Handles both javadoc and scaladoc.
*/
class Docstrings(index: GlobalSymbolIndex) {
class Docstrings(index: GlobalSymbolIndex)(implicit rc: ReportContext) {
val cache = new TrieMap[String, SymbolDocumentation]()
private val logger = Logger.getLogger(classOf[Docstrings].getName)

Expand Down Expand Up @@ -141,5 +141,7 @@ class Docstrings(index: GlobalSymbolIndex) {
}

object Docstrings {
def empty: Docstrings = new Docstrings(OnDemandSymbolIndex.empty())
def empty(implicit rc: ReportContext): Docstrings = new Docstrings(
OnDemandSymbolIndex.empty()
)
}
Expand Up @@ -44,7 +44,7 @@ object SemanticdbDefinition {
includeMembers: Boolean
)(
fn: SemanticdbDefinition => Unit
): Unit = {
)(implicit rc: ReportContext): Unit = {
input.toLanguage match {
case Language.SCALA =>
val mtags = new ScalaToplevelMtags(
Expand Down
12 changes: 8 additions & 4 deletions mtags/src/main/scala/scala/meta/internal/mtags/Mtags.scala
Expand Up @@ -3,12 +3,14 @@ package scala.meta.internal.mtags
import scala.meta.Dialect
import scala.meta.dialects
import scala.meta.inputs.Input
import scala.meta.internal.metals.EmptyReportContext
import scala.meta.internal.metals.ReportContext
import scala.meta.internal.mtags.ScalametaCommonEnrichments._
import scala.meta.internal.semanticdb.Language
import scala.meta.internal.semanticdb.Scala._
import scala.meta.internal.semanticdb.TextDocument

final class Mtags {
final class Mtags(implicit rc: ReportContext) {
def totalLinesOfCode: Long = javaLines + scalaLines
def totalLinesOfScala: Long = scalaLines
def totalLinesOfJava: Long = javaLines
Expand Down Expand Up @@ -73,7 +75,9 @@ final class Mtags {
}
}
object Mtags {
def index(input: Input.VirtualFile, dialect: Dialect): TextDocument = {
def index(input: Input.VirtualFile, dialect: Dialect)(implicit
rc: ReportContext = EmptyReportContext
): TextDocument = {
new Mtags().index(input.toLanguage, input, dialect)
}

Expand All @@ -90,7 +94,7 @@ object Mtags {
def allToplevels(
input: Input.VirtualFile,
dialect: Dialect
): TextDocument = {
)(implicit rc: ReportContext = EmptyReportContext): TextDocument = {
input.toLanguage match {
case Language.JAVA =>
new JavaMtags(input, includeMembers = true).index()
Expand All @@ -105,7 +109,7 @@ object Mtags {
def toplevels(
input: Input.VirtualFile,
dialect: Dialect = dialects.Scala213
): List[String] = {
)(implicit rc: ReportContext = EmptyReportContext): List[String] = {
new Mtags().toplevels(input, dialect)
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ import scala.util.control.NonFatal
import scala.meta.Dialect
import scala.meta.dialects
import scala.meta.internal.io.{ListFiles => _}
import scala.meta.internal.metals.ReportContext
import scala.meta.io.AbsolutePath

/**
Expand All @@ -28,7 +29,8 @@ final class OnDemandSymbolIndex(
dialectBuckets: TrieMap[Dialect, SymbolIndexBucket],
onError: PartialFunction[Throwable, Unit],
toIndexSource: AbsolutePath => AbsolutePath
) extends GlobalSymbolIndex {
)(implicit rc: ReportContext)
extends GlobalSymbolIndex {
val mtags = new Mtags
var indexedSources = 0L
def close(): Unit = {
Expand Down Expand Up @@ -150,7 +152,7 @@ object OnDemandSymbolIndex {
throw e
},
toIndexSource: AbsolutePath => AbsolutePath = identity
): OnDemandSymbolIndex = {
)(implicit rc: ReportContext): OnDemandSymbolIndex = {
new OnDemandSymbolIndex(TrieMap.empty, onError, toIndexSource)
}

Expand Down