Skip to content

Commit

Permalink
multi file logging + test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Mar 28, 2023
1 parent 6693bb9 commit fe12683
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 118 deletions.
2 changes: 1 addition & 1 deletion metals-bench/src/main/scala/bench/PcBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class PcBenchmark {
}

def newPC(search: SymbolSearch = newSearch()): PresentationCompiler = {
new ScalaPresentationCompiler("root")
new ScalaPresentationCompiler()
.withSearch(search)
.newInstance("", classpath.asJava, Nil.asJava)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class Compilers(
trees: Trees,
mtagsResolver: MtagsResolver,
sourceMapper: SourceMapper,
workspaceId: String,
)(implicit ec: ExecutionContextExecutorService)
extends Cancelable {
val plugins = new CompilerPlugins()
Expand Down Expand Up @@ -1016,7 +1015,7 @@ class Compilers(
): PresentationCompiler = {
val pc: PresentationCompiler =
mtags match {
case MtagsBinaries.BuildIn => new ScalaPresentationCompiler(workspaceId)
case MtagsBinaries.BuildIn => new ScalaPresentationCompiler()
case artifacts: MtagsBinaries.Artifacts =>
embedded.presentationCompiler(artifacts, classpath)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ class MetalsLspService(
fileWatchFilter,
params => {
didChangeWatchedFiles(params)
initTreeView()
},
)
)
Expand All @@ -262,11 +261,13 @@ class MetalsLspService(
Cancelable.empty,
)
)
private def onBuildChanged =

private val onBuildChanged =
BatchedFunction.fromFuture[AbsolutePath, BuildChange](
onBuildChangedUnbatched
)
def pauseables: Pauseable = Pauseable.fromPausables(

val pauseables: Pauseable = Pauseable.fromPausables(
onBuildChanged ::
parseTrees ::
compilations.pauseables
Expand Down Expand Up @@ -375,7 +376,6 @@ class MetalsLspService(
time,
report => {
didCompileTarget(report)
initTreeView()
compilers.didCompile(report)
},
onBuildTargetDidCompile = { target =>
Expand All @@ -390,7 +390,6 @@ class MetalsLspService(
},
onBuildTargetDidChangeFunc = params => {
maybeQuickConnectToBuildServer(params)
initTreeView()
},
)

Expand Down Expand Up @@ -626,7 +625,6 @@ class MetalsLspService(
trees,
mtagsResolver,
sourceMapper,
folderId,
)
)

Expand Down Expand Up @@ -738,7 +736,7 @@ class MetalsLspService(

var httpServer: Option[MetalsHttpServer] = None

def treeView =
val treeView =
new MetalsTreeFolderViewProvider(
folderId,
() => folder,
Expand Down Expand Up @@ -782,15 +780,11 @@ class MetalsLspService(
tables,
doctor,
() => {
val res = slowConnectToBuildServer(forceImport = true)
initTreeView()
res
slowConnectToBuildServer(forceImport = true)
},
bspConnector,
() => {
val res = quickConnectToBuildServer()
initTreeView()
res
quickConnectToBuildServer()
},
)
private val findTextInJars: FindTextInDependencyJars =
Expand Down Expand Up @@ -2091,6 +2085,7 @@ class MetalsLspService(
case None =>
Future.successful(BuildChange.None)
}
_ = initTreeView()
} yield result)
.recover { case NonFatal(e) =>
disconnectOldBuildServer()
Expand Down Expand Up @@ -2276,9 +2271,7 @@ class MetalsLspService(
): Future[BuildChange] = {
val isBuildChange = paths.exists(buildTools.isBuildRelated(folder, _))
if (isBuildChange) {
val res = slowConnectToBuildServer(forceImport = false)
initTreeView()
res
slowConnectToBuildServer(forceImport = false)
} else {
Future.successful(BuildChange.None)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import scala.concurrent.ExecutionContextExecutorService
import scala.concurrent.Future
import scala.concurrent.Promise
import scala.concurrent.duration.Duration
import scala.util.Success
import scala.util.control.NonFatal

import scala.meta.internal.builds.BuildTools
Expand Down Expand Up @@ -120,47 +119,56 @@ class WorkspaceLspService(
@volatile
private var userConfig: UserConfiguration = initialUserConfig

val statusBar: StatusBar = new StatusBar(
languageClient,
time,
progressTicks,
clientConfig,
)

private val shellRunner = register {
new ShellRunner(languageClient, () => userConfig, time, statusBar)
}

var focusedDocument: Option[AbsolutePath] = None
private val recentlyFocusedFiles = new ActiveFiles(time)

val folderServices: List[MetalsLspService] = folders
.withFilter { case Folder(uri, _, _) =>
!BuildTools.default(uri).isEmpty
}
.map { case Folder(uri, id, name) =>
new MetalsLspService(
ec,
sh,
serverInputs,
languageClient,
initializeParams,
clientConfig,
() => userConfig,
statusBar,
() => focusedDocument,
shellRunner,
timerProvider,
initTreeView,
uri,
id,
name,
)
}
private val timerProvider: TimerProvider = new TimerProvider(time)

assert(folderServices.nonEmpty)
val folderServices: List[MetalsLspService] = {
def createService(folder: Folder) =
folder match {
case Folder(uri, id, name) =>
new MetalsLspService(
ec,
sh,
serverInputs,
languageClient,
initializeParams,
clientConfig,
() => userConfig,
statusBar,
() => focusedDocument,
shellRunner,
timerProvider,
initTreeView,
uri,
id,
name,
)
}

val statusBar: StatusBar = new StatusBar(
languageClient,
time,
progressTicks,
clientConfig,
)
val res = folders
.withFilter { case Folder(uri, _, _) =>
!BuildTools.default(uri).isEmpty
}
.map(createService)

private val timerProvider: TimerProvider = new TimerProvider(time)
if (res.isEmpty) List(createService(folders.head))
else res
}

assert(folderServices.nonEmpty)

val treeView: TreeViewProvider =
if (clientConfig.isTreeViewProvider) {
Expand Down Expand Up @@ -262,13 +270,8 @@ class WorkspaceLspService(
def foreachSeq[A](
f: MetalsLspService => Future[A],
ignoreValue: Boolean = false,
withF: Option[() => Unit] = None,
): CompletableFuture[Object] = {
val res0 = Future.sequence(folderServices.map(f))
val res = withF match {
case Some(f) => res0.andThen { case Success(_) => f() }
case None => res0
}
val res = Future.sequence(folderServices.map(f))
if (ignoreValue) res.ignoreValue.asJavaObject
else res.asJavaObject
}
Expand Down Expand Up @@ -570,8 +573,6 @@ class WorkspaceLspService(
}
}

// def withTreeViewInit() {}

override def windowStateDidChange(params: WindowStateDidChangeParams): Unit =
if (params.focused) {
folderServices.foreach(_.unpause())
Expand Down Expand Up @@ -602,20 +603,18 @@ class WorkspaceLspService(
foreachSeq(_.indexSources(), ignoreValue = true)
case ServerCommands.RestartBuildServer() =>
folderServices.find(_.isBloop()).foreach(_.shutDownBloop())
foreachSeq(_.autoConnectToBuildServer(), withF = Some(initTreeView))
foreachSeq(_.autoConnectToBuildServer())
case ServerCommands.GenerateBspConfig() =>
foreachSeq(
_.generateBspConfig(),
ignoreValue = true,
withF = Some(initTreeView),
)
case ServerCommands.ImportBuild() =>
foreachSeq(
_.slowConnectToBuildServer(forceImport = true),
withF = Some(initTreeView),
_.slowConnectToBuildServer(forceImport = true)
)
case ServerCommands.ConnectBuildServer() =>
foreachSeq(_.quickConnectToBuildServer(), withF = Some(initTreeView))
foreachSeq(_.quickConnectToBuildServer())
case ServerCommands.DisconnectBuildServer() =>
foreachSeq(_.disconnectOldBuildServer(), ignoreValue = true)
case ServerCommands.DecodeFile(uri) =>
Expand Down Expand Up @@ -650,7 +649,7 @@ class WorkspaceLspService(
.asJava
}.asJavaObject
case ServerCommands.BspSwitch() =>
foreachSeq(_.switchBspServer(), withF = Some(initTreeView))
foreachSeq(_.switchBspServer())
case ServerCommands.OpenIssue() =>
Future
.successful(Urls.openBrowser(githubNewIssueUrlCreator.buildUrl()))
Expand Down Expand Up @@ -733,7 +732,7 @@ class WorkspaceLspService(
folderServices.map(_.findMainClassAndItsBuildTarget(params))
)
.flatMap { list =>
list.filter(_._2.isEmpty) match {
list.filter(_._2.nonEmpty) match {
case (service, buildTargets) :: Nil =>
service.startMainClass(buildTargets, params)
case list =>
Expand Down Expand Up @@ -773,7 +772,7 @@ class WorkspaceLspService(
folderServices.map(_.findTestClassAndItsBuildTarget(params))
)
.flatMap { list =>
list.filter(_._2.isEmpty) match {
list.filter(_._2.nonEmpty) match {
case (service, buildTargets) :: Nil =>
service.startTestSuiteForResolved(buildTargets, params)
case list =>
Expand Down Expand Up @@ -1038,7 +1037,6 @@ class WorkspaceLspService(
Future // TODO:: we should probably have only one http server
// and remove this ---v
.sequence(folderServices.map(_.initialized(this)))
.andThen { case Success(_) => treeView.init() }
.ignoreValue
}
}
Expand Down Expand Up @@ -1115,6 +1113,7 @@ class WorkspaceLspService(
}
} else Future.unit
}

}
// TODO:: delete id, uri is enough
case class Folder(uri: AbsolutePath, id: String, visibleName: Option[String])
Loading

0 comments on commit fe12683

Please sign in to comment.