Skip to content

Commit

Permalink
Handle upcoming mill embedded BSP and fix mill BSP install
Browse files Browse the repository at this point in the history
  • Loading branch information
joan38 committed Oct 27, 2020
1 parent e1eba99 commit 5c60b7a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jetbrains.bsp.project.importing

import com.intellij.openapi.vfs.VirtualFile
import scala.io.Source
import scala.sys.process._
import scala.util.Try

object MillProjectImportProvider {
private val buildFile = "build.sc"

def canImport(workspace: VirtualFile): Boolean = {
workspace match {
case null => false
case directory if directory.isDirectory =>
lazy val bspBuiltIn = directory.getChildren.exists { vBuildScript =>
!vBuildScript.isDirectory && vBuildScript.getName == "mill" &&
Source.fromInputStream(vBuildScript.getInputStream)
.getLines()
.exists(!_.matches("""^.*(0\.8\.0|0\.7.+|0\.6.+)$"""))
} && Try(Process("./mill mill.bsp.BSP/install", workspace.toNioPath.toFile).!!).isSuccess

// Legacy support for Mill =< 0.8.0
lazy val buildWithBspPlugin = directory.getChildren.exists { vBuildScript =>
!vBuildScript.isDirectory && vBuildScript.getName == "build.sc" &&
Source.fromInputStream(vBuildScript.getInputStream)
.getLines()
.contains("import $ivy.`com.lihaoyi::mill-contrib-bsp:$MILL_VERSION`")
} && Try(Process("./mill -i mill.contrib.BSP/install", workspace.toNioPath.toFile).!!).isSuccess

bspBuiltIn || buildWithBspPlugin
case file => file.getName == buildFile
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import org.jetbrains.annotations.Nls
import org.jetbrains.bsp.{BspBundle, BspUtil}
import org.jetbrains.bsp.project.importing.BspSetupConfigStep.ConfigSetupTask
import org.jetbrains.bsp.project.importing.bspConfigSteps._
import org.jetbrains.bsp.project.importing.setup.{BspConfigSetup, FastpassConfigSetup, MillConfigSetup, NoConfigSetup, SbtConfigSetup}
import org.jetbrains.bsp.project.importing.setup.{BspConfigSetup, FastpassConfigSetup, NoConfigSetup, SbtConfigSetup}
import org.jetbrains.bsp.protocol.BspConnectionConfig
import org.jetbrains.bsp.settings.BspProjectSettings._
import org.jetbrains.plugins.scala.build.IndicatorReporter
import org.jetbrains.plugins.scala.project.Version
import org.jetbrains.sbt.SbtUtil._
import org.jetbrains.sbt.project.{MillProjectImportProvider, SbtProjectImportProvider}
import org.jetbrains.sbt.project.SbtProjectImportProvider

object bspConfigSteps {

Expand Down Expand Up @@ -103,9 +103,6 @@ object bspConfigSteps {
builder.setPreImportConfig(NoPreImport)
// server config to be set in next step
SbtConfigSetup(workspace)
case bspConfigSteps.MillSetup =>
builder.setPreImportConfig(NoPreImport)
MillConfigSetup(workspace)
case bspConfigSteps.FastpassSetup =>
builder.setPreImportConfig(NoPreImport)
val bspWorkspace = FastpassConfigSetup.computeBspWorkspace(workspace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import org.jetbrains.bsp._
import org.jetbrains.bsp.protocol.BspConnectionConfig
import org.jetbrains.bsp.settings.BspProjectSettings._
import org.jetbrains.bsp.settings._
import org.jetbrains.sbt.project.{MillProjectImportProvider, SbtProjectImportProvider}
import org.jetbrains.sbt.project.SbtProjectImportProvider

class BspProjectImportBuilder
extends AbstractExternalProjectImportBuilder[BspImportControl](
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 5c60b7a

Please sign in to comment.