-
-
Notifications
You must be signed in to change notification settings - Fork 347
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
Support an alternative to $
-imports
#3062
Comments
FTR, here is my mentioned proposal. @lefou wrote on Sept 8, 2003:
|
I think support for a minimal required version would be nice. Mill should fail if it does not match. //> using mill.minVersion 0.11.8 |
+1 for moving away from the $ivy imports. I tripped over this a few times with IntelliJ, where it decided to 'clean up' imports and messed up the $ivy imports. |
A tip: Recently I have discovered, if you place the |
I am also in favour of this - it would mean no custom parser needed for the scala 3 port (unless we would keep the old way specifically for deprecation messages) |
I'd like to preserve magic imports for backwards compatibility, at least for the first scala 3 release. It's fine to break stuff in a breaking release, but leaving the ivy imports in place for at least one or two releases should help smoothen the migration considerably Long term I think we should consider alternatives to magic imports, but let's decouple it from the Scala 3 upgrade |
We could introduce using directives and deprecate imports in |
Possible, but I would like to spend a bit more time exploring the design space for this area. directives work great to replace ivy imports, are kind of awkward to replace file imports. It's plausible we could find some solution, e.g. by making file imports go away by auto discovering files, but that may require other changes e.g. changing the file extension from .sc to .mill to avoid picking up random scripts. And I think there's some interesting stuff we could do with a more structured JSON/YAML header format, which could precisely match our JSON serialization format and generalize to arbitrary configs in a way that directives dont That's not to say I think we should never do dirextives, but from a timeline perspective I think we should not couple it to the Scala 3 upgrade, as this area will take more time to work out the details |
@lihaoyi Could you elaborate on the difficulties you see with |
Regarding the more complex encoding like JSON/YAML. I think this was discussed for using directives many times, finally it was dropped because of complexity. There is still no good editor support for such file headers. And as a result it's harder to properly edit, format and get the header right. In contrast, the current using directives are simple key value pairs and that's all. Everything else is parsing the value, which is analog to e.g. how CLI args work or sysprops or env values. I also envision to use a simple //> using mill.version 0.12.0 and want to parse this from Also, it works for scala-cli, which doesn't want to be a build tool yet its rich building capabilities are completely controlled via this simple format. We pick users up with something they're already familiar with or which is easy to learn. |
We inherited the various
$
-imports likeimport $ivy
orimport $file
from Ammonite. It turns out, the Scala compiler isn't very fond of us using the$
symbol in object and class names and newer versions starting from3.4.0
enforce this more strictly.See also:
$
symbol classfile scala/scala3#19702I think a nice alternative to these magic imports could be something similar as the using directives as known from Scala CLI.
From a compiler perspective, they are just comments, so we don't need to mangle scripts just for the sake of replacing directives with something regular. Something we needed to do before with the
$
-imports.My preferred usage would look like this:
But since my proposal to make them tool/context specific wasn't accepted, the "standard" way to support tool specific key-value pair would be to encode the tool/context in the key. It would look like this:
The pros for following this standard would be, that IDEs, formatter and syntax highlighters might handle them better. (Which is already the case at the time of writing this. GitHub renders my first example just grey, but the second nicely colored.)
The text was updated successfully, but these errors were encountered: