-
Notifications
You must be signed in to change notification settings - Fork 128
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
New using directive syntax #546
Conversation
6967cfa
to
3203ebc
Compare
fb87f23
to
6920d8f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't review the core of the changes yet, but I wish the git history was clearer: as of now, this mixes various unrelated changes (refactorings, new using directive syntax, changes in the build), so I'd rather not squash-and-merge, but I wouldn't want to merge with a merge commit either to avoid "reformating" or "address CI failures" commits (which don't really make sense on their own, when later bisecting issues for example).
project/deps.sc
Outdated
Seq( | ||
coursier.Repositories.sonatype("snapshots"), | ||
// Uncomment for local development | ||
coursier.MavenRepository(s"file://${System.getProperty("user.home")}/.m2/repository") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, my bad
scala-cli
Outdated
@@ -17,7 +17,7 @@ if [ ! -x "$LAUNCHER_DIR/scala" ]; then | |||
echo "native-image launcher not built yet." 1>&2 | |||
echo "In order to build it, go in $DIR, and run" 1>&2 | |||
echo 1>&2 | |||
echo " ./mill cli.nativeImage" 1>&2 | |||
echo " ./mill copyTo cli.nativeImage out/cli/nativeImage/dest/scala" 1>&2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just ./mill cli.nativeImage
should be enough. We should change LAUNCHER_DIR
if the native image doesn't land there.
|
||
Until `using` directives becomes a part of the Scala specification, this is the only way that guarantees that your code will work well with IDEs, code formatters, and other tools. | ||
::: | ||
|
||
Within one file, only one flavor of using directives can be used. The keyword-base syntax (`using scala "3"`) has precedence over special comments (`//> using scala "3"`) and deprecated, plain comments (`// using scala "3"`) has lowest priority. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within one file, only one flavor of using directives can be used. The keyword-base syntax (`using scala "3"`) has precedence over special comments (`//> using scala "3"`) and deprecated, plain comments (`// using scala "3"`) has lowest priority. | |
Within one file, only one flavor of using directives can be used. The keyword-based syntax (`using scala "3"`) has precedence over special comments (`//> using scala "3"`) and deprecated, plain comments (`// using scala "3"`) has lowest priority. |
|
||
Until `using` directives becomes a part of the Scala specification, this is the only way that guarantees that your code will work well with IDEs, code formatters, and other tools. | ||
::: | ||
|
||
Within one file, only one flavor of using directives can be used. The keyword-base syntax (`using scala "3"`) has precedence over special comments (`//> using scala "3"`) and deprecated, plain comments (`// using scala "3"`) has lowest priority. | ||
|
||
For now `using` and `@using` can be mixed within given syntax however we strongly suggest to does not use deprecated `@using`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
For now `using` and `@using` can be mixed within given syntax however we strongly suggest to does not use deprecated `@using`. | |
For now `using` and `@using` can be mixed within a given syntax however we strongly suggest not to use deprecated `@using`. |
``` | ||
## Deprecated syntax | ||
|
||
As a part of `0.0.x` series we experimented with different syntax for using directives. Based on the feedback and discussions with Scala compiler teams we decided to deprecated `@using` (using annotations) and `// using` (using within plain import). Those syntaxes will work as a part of of `0.1.x` series and we will result with an error since `0.2.x`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
As a part of `0.0.x` series we experimented with different syntax for using directives. Based on the feedback and discussions with Scala compiler teams we decided to deprecated `@using` (using annotations) and `// using` (using within plain import). Those syntaxes will work as a part of of `0.1.x` series and we will result with an error since `0.2.x`. | |
As a part of `0.0.x` series we experimented with different syntaxes for using directives. Based on feedback and discussions with the Scala compiler team, we decided to deprecate `@using` (using annotations) and `// using` (using within plain comment). Those syntaxes will keep working in the `0.1.x` series and will result in an error starting from `0.2.x`. |
|
||
As a part of `0.0.x` series we experimented with different syntax for using directives. Based on the feedback and discussions with Scala compiler teams we decided to deprecated `@using` (using annotations) and `// using` (using within plain import). Those syntaxes will work as a part of of `0.1.x` series and we will result with an error since `0.2.x`. | ||
|
||
Scala CLI produces a warnings if any of the syntaxes above is used: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scala CLI produces a warnings if any of the syntaxes above is used: | |
Scala CLI produces warnings if any of the syntaxes above is used: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(It seems some *.semanticdb
are committed too.)
@@ -135,40 +143,42 @@ final class BspImpl( | |||
buildChangedTest | |||
) | |||
|
|||
(mainScope, testScope) | |||
// ala a a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
// ala a a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah,I needed to force recompilation :/
notifyBuildChange(actualLocalServer) | ||
|
||
Build.buildOnce( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Independently of the changes of this PR, it seems both Build.buildOnce
calls should have been wrapped in a value { … }
:/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking how it goes in #557.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can wrap it but let me know if value { }
works
cause: Throwable = null | ||
) extends Exception(message, cause) | ||
) extends Exception(message, cause) with Diagnostic { | ||
override def severity: Severity = Severity.Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need to put a severity here… This might lead to methods returning Either[BuildException, T]
to return a Left(ex)
with ex.severity == Severity.Warning
, which doesn't make sense (exceptions on the left here are implicitly assumed to be plain errors). The severity field makes "invalid states representable".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've put severity here just to be able to process BuildException
and diagnostics using the same code and hence I need to fix severity here. I can change it to final def
to make sure nobody will treat Exception as warnings.
@@ -1,6 +1,13 @@ | |||
package scala.build.preprocessing | |||
|
|||
import _root_.com.virtuslab.using_directives.custom.utils.ast.UsingDefs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT
import _root_.com.virtuslab.using_directives.custom.utils.ast.UsingDefs | |
import com.virtuslab.using_directives.custom.utils.ast.UsingDefs |
case class Warn(messagePattern: String, line: Int, index: Int) extends Check { | ||
def test(diags: Seq[Diagnostic]): Boolean = { | ||
val matching = diags.filter(_.positions.collect { | ||
case Position.File(_, (l, c), _) if l == line && index == c => l |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT
case Position.File(_, (l, c), _) if l == line && index == c => l | |
case Position.File(_, (`line`, `index`), _) => line |
(That said, I often forget about matching with backticks myself, so there might be other cases in the code base where we can do the same…)
def test(diags: Seq[Diagnostic]): Boolean = { | ||
val matching = diags.filter(_.positions.collect { | ||
case Position.File(_, (l, c), _) if l == line && index == c => l | ||
}.nonEmpty) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the .collect { … }.nonEmpty
can be changed to .exists { case Position.File(…) => …; case _ => false }
?
matching.map(_.message).collect { | ||
case Regex() => true | ||
}.nonEmpty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
matching.map(_.message).collect { | |
case Regex() => true | |
}.nonEmpty | |
matching.map(_.message).exists { | |
case Regex() => true | |
case _ => false | |
} |
6920d8f
to
a3dedfd
Compare
@alexarchambault I updated the commit structure so it should be easier to review. I can also separate 202f37a to different PR since all those changes are basically replacing |
a3dedfd
to
975cd30
Compare
bloopServer | ||
).left.map(_ -> scope) | ||
|
||
value(doBuildOnce(preBuild.mainScope, Scope.Main)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use for-comprehensions as long as we have problems with left-types mismatch in EitherCps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
Deprecate using directives in plain comments and usign annotation style.
df15e2a
to
0162676
Compare
// coursier.MavenRepository( | ||
// (os.Path(System.getProperty("user.home")) / ".m2" / "repository") | ||
// .toNIO.toUri.toASCIIString | ||
// ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC you can add MavenLocal repo with: coursier.LocalRepositories.Dangerous.maven2Local
|
||
Until `using` directives becomes a part of the Scala specification, this is the only way that guarantees that your code will work well with IDEs, code formatters, and other tools. | ||
::: | ||
|
||
Within one file, only one flavor of using directives can be used. The keyword-based syntax (`using scala "3"`) has precedence over special comments (`//> using scala "3"`) and deprecated, plain comments (`// using scala "3"`) has lowest priority. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within one file, only one flavor of using directives can be used. The keyword-based syntax (`using scala "3"`) has precedence over special comments (`//> using scala "3"`) and deprecated, plain comments (`// using scala "3"`) has lowest priority. | |
Within one file, only one flavor of using directives can be used. The keyword-based syntax (`using scala "3"`) has precedence over special comments (`//> using scala "3"`). The deprecated, plain comments (`// using scala "3"`) have lowest priority. |
//> using scala 2.13 | ||
//> using target scala-js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did I omit a moment when we allowed strings without quotes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do not check examples if compile file, a good catch, I've open a new issue for that: #575
I will also include fixes in a followup PR.
//> using scala 2.13 | ||
//> using target scala-native |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
@@ -95,7 +95,7 @@ Using directives syntax is still experimental and may change in future versions | |||
So when we will have: | |||
|
|||
```scala title=version.scala | |||
// using scala 2.12.5 | |||
//> using scala 2.12.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
@@ -1,6 +1,6 @@ | |||
// File was generated from based on docs/cookbooks/scala-versions.md, do not edit manually! | |||
|
|||
// using scala 2.12.5 | |||
//> using scala 2.12.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
This PR changes the syntax of using directives. Following syntax is supported:
using foo bar
withusing
keyword//> using scala "3"
or/*> using scala "#"
using
keyword within a comment with special indicator>
Following syntax is deprecated:
@using scala 3
,// @using scala 3
- with@using
global annotation// using scala "3"
,/* using scala "3"*/
- within a comment within special indicator.Deprecated syntaxes result in a warning and will be supported within the next minor release:
0.1.x
and results in error within0.2.x
.Warnings are also working within BSP.
cc @julienrf