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

Add support for adding library dependencies via imports. #333

Merged
merged 4 commits into from
May 13, 2020

Conversation

olafurpg
Copy link
Member

@olafurpg olafurpg commented May 9, 2020

Previously, mdoc users could not dynamically add new library
dependencies to a document. The library classpath was static and could
only be updated through the --classpath command-line argument.

Now, it's possible for users to dynamically add new dependencies via
imports similar to how it works in Ammonite.

import $dep.`org.scalameta::scalameta:4.3.10`, scala.meta._
q"val x = 42"

The $ivy prefix is treated as an alias for $dep to preserve
compatibility with Ammonite. However, I went with $dep as the primary
syntax instead of $ivy because these imports support both Ivy and
Maven patterns. Maybe we can get Ammonite to also support $dep.

TODOs:

  • expose dependency information in EvaluatedWorksheet (required for Metals)
  • add support to configure scalac options via imports
  • compile errors from $file imports
  • cyclic dependencies in $file imports
  • conflicting package names from $file imports when the same file is imported from two different packages

@olafurpg olafurpg force-pushed the deps branch 3 times, most recently from 1d8ac01 to c1e3352 Compare May 11, 2020 22:40
Olafur Pall Geirsson added 4 commits May 13, 2020 19:08
Previously, mdoc users could not dynamically add new library
dependencies to a document.  The library classpath was static and could
only be updated through the `--classpath` command-line argument.

Now, it's possible for users to dynamically add new dependencies via
imports similar to how it works in Ammonite.

```scala
import $dep.`org.scalameta::scalameta:4.3.10`, scala.meta._
q"val x = 42"
```

The `$ivy` prefix is treated as an alias for `$dep` to preserve
compatibility with Ammonite. However, I went with `$dep` as the primary
syntax instead of `$ivy` because these imports support both Ivy and
Maven patterns. Maybe we can get Ammonite to also support `$dep`.
Previously, it was not possible to configure Scala compiler options via
imports. Now, users can customize the compiler options like this
````md
```scala mdoc
import $scalac.`-Wunused:imports -Xfatal-warnings`
import scala.util.Try
println(42)
```
````
and get a compile error.
Previously, it was only possible to import from pre-compiled
dependencies from the build via --classpath or via magic `$dep` imports.
Now, it's also possible to write re-usable `*.sc` script files and
import them from markdown files.
@olafurpg olafurpg marked this pull request as ready for review May 13, 2020 19:18
@olafurpg olafurpg merged commit 7a74f60 into scalameta:master May 13, 2020
@olafurpg olafurpg deleted the deps branch May 13, 2020 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant