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

Exclude folders bsp #3329

Merged
merged 30 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d43aff2
adding SyntheticRootBspBuildTargetData
pawelsadlo Aug 1, 2024
4407915
adding topLevelBuildRopt param to BspServer, BspWorker, State
pawelsadlo Aug 1, 2024
a058b18
add syntheticRootBspBuildTarget to State
pawelsadlo Aug 1, 2024
45d1d9e
extract makeBuildTarget to Utils, create outputPaths
pawelsadlo Aug 1, 2024
7526305
extract makeBuildTarget to Utils, create outputPaths
pawelsadlo Aug 1, 2024
ce5c96e
filter synthetic module from bspClient requests
pawelsadlo Aug 1, 2024
22e7874
change completableTasks, handle syntheticRootmodule
pawelsadlo Aug 1, 2024
a695dba
fixing name
pawelsadlo Aug 1, 2024
5ef1b67
extract SyntheticRootBspBuildTargetData creation logic to companion o…
pawelsadlo Aug 1, 2024
870acf5
docs
pawelsadlo Aug 1, 2024
c0207b5
moving syntheticRootBspBuildTarget creation logic to companion object
pawelsadlo Aug 1, 2024
d547e34
fixing agg
pawelsadlo Aug 1, 2024
613eb59
format
pawelsadlo Aug 1, 2024
5786d81
Merge branch 'main' into exclude-folders-bsp
pawelsadlo Aug 1, 2024
0107574
format
pawelsadlo Aug 1, 2024
fde6910
Merge remote-tracking branch 'ps_mill/exclude-folders-bsp' into exclu…
pawelsadlo Aug 1, 2024
2ade14a
format
pawelsadlo Aug 1, 2024
392280b
Update SyntheticRootBspBuildTargetData.scala
pawelsadlo Aug 1, 2024
a0e8162
review suggestions
pawelsadlo Aug 4, 2024
445d76d
Merge remote-tracking branch 'ps_mill/exclude-folders-bsp' into exclu…
pawelsadlo Aug 4, 2024
6dee463
Update Utils.scala
lihaoyi Aug 5, 2024
ce1e933
top level ignored folders only
lihaoyi Aug 22, 2024
94a01c9
.
lihaoyi Aug 22, 2024
800c87b
Merge branch 'main' into 3329
lihaoyi Aug 22, 2024
7a6e3b3
.
lihaoyi Aug 22, 2024
2533d49
.
lihaoyi Aug 22, 2024
3172101
.
lihaoyi Aug 22, 2024
ea37b64
.
lihaoyi Aug 22, 2024
362981f
Merge branch 'main' into 3329
lihaoyi Aug 22, 2024
1c8ad5f
.
lihaoyi Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bsp/src/mill/bsp/BspContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ private[mill] class BspContext(

override def rawOutputStream: PrintStream = systemStreams.out
}

BspWorker(os.pwd, home, log).flatMap { worker =>
val workspace = os.pwd
BspWorker(workspace, home, log).flatMap { worker =>
os.makeDir.all(home / Constants.bspDir)
worker.startBspServer(
workspace,
streams,
logStream.getOrElse(streams.err),
home / Constants.bspDir,
Expand Down
1 change: 1 addition & 0 deletions bsp/src/mill/bsp/BspWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.net.URL

private trait BspWorker {
def startBspServer(
topLevelBuildRoot: os.Path,
streams: SystemStreams,
logStream: PrintStream,
logDir: os.Path,
Expand Down
2 changes: 2 additions & 0 deletions bsp/worker/src/mill/bsp/worker/BspWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import scala.concurrent.{Await, CancellationException, Promise}
private class BspWorkerImpl() extends BspWorker {

override def startBspServer(
topLevelBuildRoot: os.Path,
streams: SystemStreams,
logStream: PrintStream,
logDir: os.Path,
Expand All @@ -23,6 +24,7 @@ private class BspWorkerImpl() extends BspWorker {

val millServer =
new MillBuildServer(
topLevelProjectRoot = topLevelBuildRoot,
bspVersion = Constants.bspProtocolVersion,
serverVersion = BuildInfo.millVersion,
serverName = Constants.serverName,
Expand Down
179 changes: 63 additions & 116 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
@@ -1,87 +1,31 @@
package mill.bsp.worker

import ch.epfl.scala.bsp4j.{
BuildClient,
BuildServer,
BuildServerCapabilities,
BuildTarget,
BuildTargetCapabilities,
BuildTargetIdentifier,
CleanCacheParams,
CleanCacheResult,
CompileParams,
CompileProvider,
CompileResult,
DebugProvider,
DebugSessionAddress,
DebugSessionParams,
DependencyModule,
DependencyModulesItem,
DependencyModulesParams,
DependencyModulesResult,
DependencySourcesItem,
DependencySourcesParams,
DependencySourcesResult,
InitializeBuildParams,
InitializeBuildResult,
InverseSourcesParams,
InverseSourcesResult,
LogMessageParams,
MessageType,
OutputPathItem,
OutputPathItemKind,
OutputPathsItem,
OutputPathsParams,
OutputPathsResult,
ReadParams,
ResourcesItem,
ResourcesParams,
ResourcesResult,
RunParams,
RunProvider,
RunResult,
SourceItem,
SourceItemKind,
SourcesItem,
SourcesParams,
SourcesResult,
StatusCode,
TaskFinishDataKind,
TaskFinishParams,
TaskId,
TaskStartDataKind,
TaskStartParams,
TestParams,
TestProvider,
TestResult,
TestTask,
WorkspaceBuildTargetsResult
}
import ch.epfl.scala.bsp4j
import ch.epfl.scala.bsp4j._
import com.google.gson.JsonObject
import mill.T
import mill.api.{DummyTestReporter, Result, Strict}
import mill.bsp.BspServerResult
import mill.bsp.worker.Utils.{makeBuildTarget, outputPaths, sanitizeUri}
import mill.define.Segment.Label
import mill.define.{Args, Discover, ExternalModule, Task}
import mill.eval.Evaluator
import mill.eval.Evaluator.TaskResult
import mill.main.MainModule
import mill.scalalib.{JavaModule, SemanticDbJavaModule, TestModule}
import mill.scalalib.bsp.{BspModule, JvmBuildTarget, ScalaBuildTarget}
import mill.runner.MillBuildRootModule
import mill.scalalib.bsp.{BspModule, JvmBuildTarget, ScalaBuildTarget}
import mill.scalalib.{JavaModule, SemanticDbJavaModule, TestModule}

import java.io.PrintStream
import java.util.concurrent.CompletableFuture
import scala.concurrent.Promise
import scala.jdk.CollectionConverters._
import scala.reflect.ClassTag
import scala.util.{Failure, Success, Try}
import Utils.sanitizeUri
import mill.bsp.BspServerResult
import mill.eval.Evaluator.TaskResult

import scala.util.chaining.scalaUtilChainingOps
import scala.util.control.NonFatal
import scala.util.{Failure, Success, Try}
private class MillBuildServer(
topLevelProjectRoot: os.Path,
bspVersion: String,
serverVersion: String,
serverName: String,
Expand Down Expand Up @@ -110,7 +54,7 @@ private class MillBuildServer(
if (statePromise.isCompleted) statePromise = Promise[State]() // replace the promise
evaluatorsOpt.foreach { evaluators =>
statePromise.success(
new State(evaluators, debug)
new State(topLevelProjectRoot, evaluators, debug)
)
}
}
Expand Down Expand Up @@ -246,30 +190,13 @@ private class MillBuildServer(
}

val bt = m.bspBuildTarget
val buildTarget = new BuildTarget(
id,
bt.tags.asJava,
bt.languageIds.asJava,
depsIds.asJava,
new BuildTargetCapabilities().tap { it =>
it.setCanCompile(bt.canCompile)
it.setCanTest(bt.canTest)
it.setCanRun(bt.canRun)
it.setCanDebug(bt.canDebug)
}
)

bt.displayName.foreach(buildTarget.setDisplayName)
bt.baseDirectory.foreach(p => buildTarget.setBaseDirectory(sanitizeUri(p)))
makeBuildTarget(id, depsIds, bt, data)

for ((dataKind, data) <- data) {
buildTarget.setDataKind(dataKind)
buildTarget.setData(data)
}

buildTarget

}(new WorkspaceBuildTargetsResult(_))
} { case (targets, state) =>
new WorkspaceBuildTargetsResult(
(targets.asScala ++ state.syntheticRootBspBuildTarget.map(_.target)).asJava
)
}

override def workspaceReload(): CompletableFuture[Object] =
completableNoState("workspaceReload", false) {
Expand Down Expand Up @@ -316,8 +243,10 @@ private class MillBuildServer(
}
) {
case (ev, state, id, module, items) => new SourcesItem(id, items.asJava)
} {
new SourcesResult(_)
} { case (sourceItems, state) =>
new SourcesResult(
(sourceItems.asScala.toSeq ++ state.syntheticRootBspBuildTarget.map(_.synthSources)).asJava
)
}

}
Expand Down Expand Up @@ -387,8 +316,8 @@ private class MillBuildServer(

val cp = (resolveDepsSources ++ unmanagedClasspath).map(sanitizeUri).toSeq ++ buildSources
new DependencySourcesItem(id, cp.asJava)
} {
new DependencySourcesResult(_)
} { x =>
new DependencySourcesResult(x._1)
}

/**
Expand Down Expand Up @@ -426,8 +355,8 @@ private class MillBuildServer(
new DependencyModule(s"unmanaged-${dep.path.last}", "")
}
new DependencyModulesItem(id, (deps ++ unmanged).iterator.toSeq.asJava)
} {
new DependencyModulesResult(_)
} { x =>
new DependencyModulesResult(x._1)
}

override def buildTargetResources(p: ResourcesParams): CompletableFuture[ResourcesResult] =
Expand All @@ -443,14 +372,17 @@ private class MillBuildServer(
val resourcesUrls = resources.map(_.path).filter(os.exists).map(sanitizeUri)
new ResourcesItem(id, resourcesUrls.asJava)

} {
new ResourcesResult(_)
} { x =>
new ResourcesResult(x._1)
}

// TODO: if the client wants to give compilation arguments and the module
// already has some from the build file, what to do?
override def buildTargetCompile(p: CompileParams): CompletableFuture[CompileResult] =
completable(s"buildTargetCompile ${p}") { state =>
p.setTargets(p.getTargets.asScala.filterNot(
state.syntheticRootBspBuildTarget.map(_.id).contains
).toList.asJava)
val params = TaskParameters.fromCompileParams(p)
val taskId = params.hashCode()
val compileTasksEvs = params.getTargets.distinct.map(state.bspModulesById).map {
Expand Down Expand Up @@ -483,29 +415,33 @@ private class MillBuildServer(
override def buildTargetOutputPaths(params: OutputPathsParams)
: CompletableFuture[OutputPathsResult] =
completable(s"buildTargetOutputPaths ${params}") { state =>
val synthOutpaths = for {
synthTarget <- state.syntheticRootBspBuildTarget
if params.getTargets.contains(synthTarget.id)
baseDir <- synthTarget.bt.baseDirectory
} yield new OutputPathsItem(synthTarget.id, outputPaths(baseDir / "out", baseDir, topLevelProjectRoot).asJava)

val items = for {
target <- params.getTargets.asScala
(module, ev) <- state.bspModulesById.get(target)
} yield {
val items =
if (module.millOuterCtx.external) List(
new OutputPathItem(
// Spec says, a directory must end with a forward slash
sanitizeUri(ev.externalOutPath) + "/",
OutputPathItemKind.DIRECTORY
)
)
else List(
new OutputPathItem(
// Spec says, a directory must end with a forward slash
sanitizeUri(ev.outPath) + "/",
OutputPathItemKind.DIRECTORY
)
)
val items = {
module match {
case external if external.millOuterCtx.external =>
outputPaths(
ev.externalOutPath,
module.bspBuildTarget.baseDirectory.get,
topLevelProjectRoot
)
case _ =>
outputPaths(ev.outPath, module.bspBuildTarget.baseDirectory.get, topLevelProjectRoot)
}
}

new OutputPathsItem(target, items.asJava)
}

new OutputPathsResult(items.asJava)
new OutputPathsResult((items ++ synthOutpaths).asJava)
}

override def buildTargetRun(runParams: RunParams): CompletableFuture[RunResult] =
Expand Down Expand Up @@ -536,6 +472,9 @@ private class MillBuildServer(

override def buildTargetTest(testParams: TestParams): CompletableFuture[TestResult] =
completable(s"buildTargetTest ${testParams}") { state =>
testParams.setTargets(testParams.getTargets.asScala.toSeq.filterNot(
state.syntheticRootBspBuildTarget.map(_.id).contains
).toList.asJava)
val millBuildTargetIds = state
.rootModules
.map { case m: BspModule => state.bspIdByModule(m) }
Expand Down Expand Up @@ -627,6 +566,9 @@ private class MillBuildServer(
override def buildTargetCleanCache(cleanCacheParams: CleanCacheParams)
: CompletableFuture[CleanCacheResult] =
completable(s"buildTargetCleanCache ${cleanCacheParams}") { state =>
cleanCacheParams.setTargets(cleanCacheParams.getTargets.asScala.toSeq.filterNot(
state.syntheticRootBspBuildTarget.map(_.id).contains
).toList.asJava)
val (msg, cleaned) =
cleanCacheParams.getTargets.asScala.foldLeft((
"",
Expand Down Expand Up @@ -675,6 +617,9 @@ private class MillBuildServer(
override def debugSessionStart(debugParams: DebugSessionParams)
: CompletableFuture[DebugSessionAddress] =
completable(s"debugSessionStart ${debugParams}") { state =>
debugParams.setTargets(debugParams.getTargets.asScala.toSeq.filterNot(
state.syntheticRootBspBuildTarget.map(_.id).contains
).toList.asJava)
throw new NotImplementedError("debugSessionStart endpoint is not implemented")
}

Expand All @@ -686,11 +631,13 @@ private class MillBuildServer(
hint: String,
targetIds: State => Seq[BuildTargetIdentifier],
tasks: PartialFunction[BspModule, Task[W]]
)(f: (Evaluator, State, BuildTargetIdentifier, BspModule, W) => T)(agg: java.util.List[T] => V)
: CompletableFuture[V] = {
)(f: (Evaluator, State, BuildTargetIdentifier, BspModule, W) => T)(agg: ((
java.util.List[T],
State
)) => V): CompletableFuture[V] = {
val prefix = hint.split(" ").head
completable(hint) { state: State =>
val ids = targetIds(state)
val ids = targetIds(state).filterNot(state.syntheticRootBspBuildTarget.map(_.id).contains)
val tasksSeq = ids.flatMap { id =>
val (m, ev) = state.bspModulesById(id)
tasks.lift.apply(m).map(ts => (ts, (ev, id)))
Expand Down Expand Up @@ -729,7 +676,7 @@ private class MillBuildServer(
}
}

agg(evaluated.flatten.toSeq.asJava)
pawelsadlo marked this conversation as resolved.
Show resolved Hide resolved
agg((evaluated.flatten.toSeq.asJava, state))
}
}

Expand Down
4 changes: 2 additions & 2 deletions bsp/worker/src/mill/bsp/worker/MillJavaBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private trait MillJavaBuildServer extends JavaBuildServer { this: MillBuildServe
classpath.iterator.toSeq.asJava,
sanitizeUri(classesPath.resolve(pathResolver))
)
} {
new JavacOptionsResult(_)
} { x =>
new JavacOptionsResult(x._1)
}
}
8 changes: 4 additions & 4 deletions bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ private trait MillJvmBuildServer extends JvmBuildServer { this: MillBuildServer
val classes = mainClass.toList ++ zincWorker.discoverMainClasses(compile)
item.setMainClasses(classes.map(new JvmMainClass(_, Nil.asJava)).asJava)
item
} {
agg
} { x =>
agg(x._1)
}
}

Expand All @@ -106,7 +106,7 @@ private trait MillJvmBuildServer extends JvmBuildServer { this: MillBuildServer
.map(_.resolve(pathResolver))
.map(sanitizeUri).toSeq.asJava
)
} {
new JvmCompileClasspathResult(_)
} { x =>
new JvmCompileClasspathResult(x._1)
}
}
Loading