-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #858 from alexarchambault/bsp-workspace-reload
Add support for BSP workspace/reload (reworked version of #852)
- Loading branch information
Showing
22 changed files
with
655 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
modules/build/src/main/scala/scala/build/bsp/BloopSession.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package scala.build.bsp | ||
|
||
import com.swoval.files.PathWatchers | ||
|
||
import java.util.concurrent.atomic.AtomicReference | ||
|
||
import scala.build.compiler.BloopCompiler | ||
import scala.build.{Build, Inputs} | ||
|
||
final class BloopSession( | ||
val inputs: Inputs, | ||
val remoteServer: BloopCompiler, | ||
val bspServer: BspServer, | ||
val watcher: Build.Watcher | ||
) { | ||
def resetDiagnostics(localClient: BspClient): Unit = | ||
for (targetId <- bspServer.targetIds) | ||
inputs.flattened().foreach { | ||
case f: Inputs.SingleFile => | ||
localClient.resetDiagnostics(f.path, targetId) | ||
case _: Inputs.Virtual => | ||
} | ||
def dispose(): Unit = { | ||
watcher.dispose() | ||
remoteServer.shutdown() | ||
} | ||
|
||
def registerWatchInputs(): Unit = | ||
inputs.elements.foreach { | ||
case elem: Inputs.OnDisk => | ||
val eventFilter: PathWatchers.Event => Boolean = { event => | ||
val newOrDeletedFile = | ||
event.getKind == PathWatchers.Event.Kind.Create || | ||
event.getKind == PathWatchers.Event.Kind.Delete | ||
lazy val p = os.Path(event.getTypedPath.getPath.toAbsolutePath) | ||
lazy val relPath = p.relativeTo(elem.path) | ||
lazy val isHidden = relPath.segments.exists(_.startsWith(".")) | ||
def isScalaFile = relPath.last.endsWith(".sc") || relPath.last.endsWith(".scala") | ||
def isJavaFile = relPath.last.endsWith(".java") | ||
newOrDeletedFile && !isHidden && (isScalaFile || isJavaFile) | ||
} | ||
val watcher0 = watcher.newWatcher() | ||
watcher0.register(elem.path.toNIO, Int.MaxValue) | ||
watcher0.addObserver { | ||
Build.onChangeBufferedObserver { event => | ||
if (eventFilter(event)) | ||
watcher.schedule() | ||
} | ||
} | ||
case _ => | ||
} | ||
} | ||
|
||
object BloopSession { | ||
|
||
final class Reference { | ||
private val ref = new AtomicReference[BloopSession](null) | ||
def get(): BloopSession = { | ||
val session = ref.get() | ||
if (session == null) | ||
sys.error("BSP server not initialized yet") | ||
session | ||
} | ||
def getAndNullify(): Option[BloopSession] = | ||
Option(ref.getAndSet(null)) | ||
def update(former: BloopSession, newer: BloopSession, ifError: String): Unit = | ||
if (!ref.compareAndSet(former, newer)) | ||
sys.error(ifError) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.