Skip to content

Commit

Permalink
Provided dummy def millDiscover and implicit RootModule.Info to m…
Browse files Browse the repository at this point in the history
…ake IDEs not display errors (com-lihaoyi#3558)

IntelliJ/VSCode can't see the generated code so they think that these
things are missing, but they're not. Rather than changing
IntelliJ/VSCode, for now we just provide dummy definitions that get
overriden by the codegen but are enough to make the IDEs happy

Before, we see errors in `extends RootModule` because of the missing
implicit `RootModule.Info`, and errors on the `object` as a whole
because of the missing `def millDiscover`:

<img width="976" alt="Screenshot 2024-09-16 at 1 20 54 PM"
src="https://github.com/user-attachments/assets/85b1d86a-de34-4622-bd1b-36428bfbc9bc">

After, those two errors are gone, although the "need override keyword"
errors remain:

<img width="976" alt="Screenshot 2024-09-16 at 1 19 35 PM"
src="https://github.com/user-attachments/assets/5b91acdd-02bd-4ede-bf3d-85b2b236ec9d">

Eventually we may have dedicated IDE support, but for now this hacks
around one of the more visible IDE issues
  • Loading branch information
lihaoyi authored Sep 16, 2024
1 parent 1ede694 commit 78b9d62
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion main/src/mill/main/RootModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mill.main

import mill.api.internal
import mill.define.{BaseModule, Ctx, Caller, Discover, Module, Segments}
import scala.annotation.compileTimeOnly

/**
* Used to mark a module in your `build.mill` as a top-level module, so it's
Expand All @@ -22,11 +23,25 @@ abstract class RootModule()(implicit
millModuleLine0,
millFile0,
Caller(null)
) with mill.main.MainModule
) with mill.main.MainModule {

// Dummy `millDiscover` defined but never actually used and overriden by codegen.
// Provided for IDEs to think that one is available and not show errors in
// build.mill/package.mill even though they can't see the codegen
def millDiscover: Discover = sys.error("RootModule#millDiscover must be overriden")
}

@internal
object RootModule {
case class Info(millSourcePath0: os.Path, discover: Discover)
object Info {
// Dummy `RootModule.Info` available in implicit scope but never actually used.
// as it is provided by the codegen. Defined for IDEs to think that one is available
// and not show errors in build.mill/package.mill even though they can't see the codegen
@compileTimeOnly("RootModule can only be instantiated in a build.mill or package.mill file")
implicit def dummyInfo: Info = sys.error("implicit RootModule.Info must be provided")
}

case class SubFolderInfo(value: Seq[String])

abstract class Subfolder()(implicit
Expand Down

0 comments on commit 78b9d62

Please sign in to comment.