Skip to content

Standalone using directives library #2443

Description

@tgodzik

Is your feature request related to a problem? Please describe.
During the last tooling summit we discussed how multiple tools could support and reuse the using directives. This led us to a conclusion that we need a separate directives library similar to @alexarchambault efforts on that front and continuing his work.

Describe the solution you'd like

Main points of that library would be:

  • it should we have scala native and js, Scala 3 and Scala 2.13
  • the most common directives should be implemented right from the start, most likely anything that is not behind --power in Scala CLI. This doesn't mean each tool will have to support them, they can still decide to ignore them or report an error. So ideally we would define a parser and the rules it should follow, very roughly:
  • it should be easy for any tool to add their own directives such as ammonite.version or all the directives behind --power in Scala CLI
  • defaults should not have aliases, but the tool might want to add them to preserve compatibility (most likely Scala CLI)
    -we should allow some basic types and parsing errors

Very very roughly:

class Parser (rules: Directive*) { def parse(path: Path): List[DirectiveValue] = ??? }
class Directive[T](name: String, helpMessage: String, validation: T => Boolean)
class DirectiveValue[T](origin: Directive[T], value: T)
val parser = new Parser(
  StandardDirectives.scalaVersion,
  StandardDirectives.dependency.withAliases("dep", "lib"),
  new Directive[String]("ammonite.version", "help", validationMethod = (value: String) => value.contains(".") )
)
values = parser.parse(Paths.get("./Hello.scala"))

Additionally:

  • directives should have positions, these can be used for automatic fixes etc.
  • we should warn about directives which are not known (or error, this could be a setting of the parser)

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Bonus point
No macros.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestusing directivesIssues tied with using directives.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions