Skip to content

Commit

Permalink
Clean up documentation about and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejG604 committed Jan 19, 2023
1 parent 212da79 commit 7a3695d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 36 deletions.
19 changes: 3 additions & 16 deletions INTERNALS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ The other modules are either:
These are:
- `bloop-rifle`: starts a Bloop server if needed, connects to it via nailgun, opens a BSP server to it, …
- `runner`: simple app that starts a main class, catches any exception it throws and pretty-prints it.
- `stubs`: empty classes, so that lines such as `import $ivy.$`, left after full blown `import $ivy`s are processed, compile fine (about to be removed?)
- `test-runner`: finds test frameworks, test suites, and runs them
- `tasty-lib`: edits file names in `.tasty` files

Expand Down Expand Up @@ -56,29 +55,17 @@ We roughly go from user inputs to byte code through 3 classes:
Most commands
- take the arguments passed on the command-line: we have an `Array[String]`
- check whether each of them is a `.scala` file, an `.sc` file, a directory, …: we get an `Inputs` instance
- reads the directories, the `.scala` / `.sc` files, processes `import $ivy` in them: we get a `Sources` instance
- reads the directories, the `.scala` / `.sc` files: we get a `Sources` instance
- compile those sources: we get a `Build` instance
- do something with the build output (run it, run tests, package it, …)

In watch mode, we loop over the last 3 steps (`Inputs` is computed only once, the rest is re-computed upon file change).

## Source pre-processing

Some input files cannot be passed as is to scalac, because:
- they contain `import $ivy`s
- they are scripts (`.sc` files), which contain top-level statements
Some input files cannot be passed as is to scalac, if they are scripts (`.sc` files), which contain top-level statements

The `import $ivy` gets replaced like
```scala
import $ivy.`org:name:ver`, something.else._
```
becomes
```scala
import $ivy.$ , something.else._
```
(We just do the same as Ammonite.)

Scripts gets wrapped. If the script `a/b/foo.sc` contains
Scripts get wrapped. If the script `a/b/foo.sc` contains
```scala
val n = 2
```
Expand Down
11 changes: 4 additions & 7 deletions website/docs/guides/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,12 @@ The reference documentation lists [all available using directives](/docs/referen

### Special imports

Dependencies can be added right from `.scala` and `.sc` files, using the same
syntax as Ammonite and Metals worksheets:
Dependencies can be added right from `.scala` and `.sc` files with [`using` directives](#using-directives):

```scala compile
import $dep.`com.lihaoyi::upickle:1.4.0`
import $ivy.`com.lihaoyi::pprint:0.6.6`
//> using lib "com.lihaoyi::upickle:1.4.0"
//> using lib "com.lihaoyi::pprint:0.6.6"
import ujson._
```

Both `import $ivy` and `import $dep` are accepted, and are equivalent. Note that this syntax
might be deprecated - and then removed - in the future. It's recommended to add dependencies
with [`using` directives](#using-directives).
Both `import $ivy` and `import $dep` are not supported.
14 changes: 4 additions & 10 deletions website/docs/guides/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ To check if dependencies in using directives are up-to-date, use `dependency-upd
```scala title=Hello.scala
//> using lib "com.lihaoyi::os-lib:0.7.8"
//> using lib "com.lihaoyi::utest:0.7.10"
import $ivy.`com.lihaoyi::geny:0.6.5`
import $dep.`com.lihaoyi::pprint:0.6.6`

object Hello extends App {
println("Hello World")
Expand All @@ -97,10 +95,8 @@ scala-cli dependency-update Hello.scala

```text
Updates
* com.lihaoyi 0.7.8 -> 0.8.1
* com.lihaoyi 0.7.10 -> 0.8.0
* com.lihaoyi 0.6.5 -> 0.7.1
* com.lihaoyi 0.6.6 -> 0.7.3
* com.lihaoyi::os-lib:0.7.8 -> 0.8.1
* com.lihaoyi::utest:0.7.10 -> 0.8.0
To update all dependencies run:
scala-cli dependency-update --all
```
Expand All @@ -116,10 +112,8 @@ scala-cli dependency-update Hello.scala --all
```

```text
Updated dependency os-lib: 0.7.8 -> 0.9.0
Updated dependency utest: 0.7.10 -> 0.8.1
Updated dependency geny: 0.6.5 -> 1.0.0
Updated dependency pprint: 0.6.6 -> 0.8.1
Updated dependency to: com.lihaoyi::os-lib:0.8.1
Updated dependency to: com.lihaoyi::utest:0.8.0
```

</ChainedSnippets>
Expand Down
5 changes: 2 additions & 3 deletions website/docs/guides/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ Some source code files that Scala CLI accepts cannot be passed as-is to `scalac`
This is the case for:
- `.sc` files, which can contain top-level definitions not accepted by `scalac`
- `.scala` files that have uncommented `using` directives
- `.sc` or `.scala` files with `import $ivy` statements

In all of those cases, Scala CLI parses the top of those files, and looks for `import $ivy` or `using` directives.
It then replaces those with either dummy imports (for the `import $ivy` statements) or space characters (for non-commented `using` directives).
In all of those cases, Scala CLI parses the top of those files, and looks for `using` directives.
It then replaces the non-commented `using` directives with space characters.

As described in [Scripts](scripts.md), `.sc` files are also "wrapped" in an `object`, and a `main` class is added to them, so that `.sc` files can be run as-is, and can access arguments via a special `args` variable.

Expand Down

0 comments on commit 7a3695d

Please sign in to comment.