Skip to content

Commit e622ebe

Browse files
committed
add link to sbt and maven tutorials, reintroduce IDE sections
1 parent cbe69b8 commit e622ebe

File tree

1 file changed

+70
-14
lines changed

1 file changed

+70
-14
lines changed

_overviews/getting-started/install-scala.md

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ string to standard output.
164164
To run the program, execute `scala run hello.scala` command from a terminal, within the `<project-dir>` directory. The file will be compiled and executed, with console output
165165
similar to following:
166166
```
167-
$ scala run hello.scala
167+
$ scala run hello.scala
168168
Compiling project (Scala {{site.scala-3-version}}, JVM (20))
169169
Compiled project (Scala {{site.scala-3-version}}, JVM (20))
170170
Hello, World!
@@ -187,7 +187,7 @@ the content of the `name` argument.
187187

188188
To pass the arguments when executing the program, put them after `--`:
189189
```
190-
$ scala run hello.scala -- Gabriel
190+
$ scala run hello.scala -- Gabriel
191191
Compiling project (Scala {{site.scala-3-version}}, JVM (20))
192192
Compiled project (Scala {{site.scala-3-version}}, JVM (20))
193193
Hello, Gabriel!
@@ -216,7 +216,7 @@ sequence of paths.
216216

217217
Execute the program. The dependency will be automatically downloaded. The execution should result in a similar output:
218218
```
219-
$ scala run counter.scala
219+
$ scala run counter.scala
220220
Compiling project (Scala {{site.scala-3-version}}, JVM (20))
221221
Compiled project (Scala {{site.scala-3-version}}, JVM (20))
222222
4
@@ -246,44 +246,100 @@ You can execute code interactively using the REPL provided by the `scala` comman
246246
$ scala
247247
Welcome to Scala {{site.scala-3-version}} (20-ea, Java OpenJDK 64-Bit Server VM).
248248
Type in expressions for evaluation. Or try :help.
249-
250-
scala>
249+
250+
scala>
251251
```
252252

253253
Write a line of code to be executed and press enter.
254254
```
255255
scala> println("Hello, World!")
256256
Hello, World!
257-
258-
scala>
257+
258+
scala>
259259
```
260260

261261
The result will be printed immediately after executing the line. You can declare values:
262262
```
263263
scala> val i = 1
264264
val i: Int = 1
265-
266-
scala>
265+
266+
scala>
267267
```
268268

269269
A new value of type `Int` has been created. If you provide an expression that can be evaluated, its result will be stored in an automatically created value.
270270
```
271271
scala> i + 3
272272
val res0: Int = 4
273-
274-
scala>
273+
274+
scala>
275275
```
276276
You can exit the REPL with `:exit`.
277277

278-
### Next steps
278+
## Using an IDE
279+
280+
> You can read a short summary of Scala IDEs on [a dedicated page](/getting-started/scala-ides.html).
281+
282+
Let's use an IDE to open the code we wrote above. The most popular ones are [IntelliJ](https://www.jetbrains.com/idea/) and
283+
[VSCode](https://scalameta.org/metals/docs/editors/vscode).
284+
They both offer rich IDE features, but you can still use [many other editors](https://scalameta.org/metals/docs/editors/overview.html).
285+
286+
### Prepare the project
287+
288+
First, remove all the using directives, and put them in a single file `project.scala` in the `<project-dir>` directory.
289+
This makes it easier to import as a project in an IDE:
290+
291+
```scala
292+
//> using scala {{site.scala-3-version}}
293+
//> using toolkit 0.5.0
294+
```
295+
296+
> Optionally, you can re-initialise the necessary IDE files from within the `<project-dir>` directory with the command `scala setup-ide .`, but these files will already exist if you have previously run the project with the Scala CLI `run` command.
279297
280-
Now that you have tasted a little bit of Scala, you can either explore the language itself, or learn how to set up a project using the
281-
sbt and an IDE using the tutorials below. If you want to familiarize yourself with the language more, consider checking out:
298+
### Using IntelliJ
299+
300+
1. Download and install [IntelliJ Community Edition](https://www.jetbrains.com/help/idea/installation-guide.html)
301+
1. Install the Scala plugin by following [the instructions on how to install IntelliJ plugins](https://www.jetbrains.com/help/idea/discover-intellij-idea-for-scala.html)
302+
1. Open the `<project-dir>` directory, which should be imported automatically as a BSP project.
303+
304+
### Using VSCode with Metals
305+
306+
1. Download [VSCode](https://code.visualstudio.com/Download)
307+
1. Install the Metals extension from [the Marketplace](https://marketplace.visualstudio.com/items?itemName=scalameta.metals)
308+
1. Next, open the `<project-dir>` directory in VSCode. Metals should activate and begin importing the project automatically.
309+
310+
### Play with the source code
311+
312+
View these three files in your IDE:
313+
314+
- _project.scala_
315+
- _hello.scala_
316+
- _counter.scala_
317+
318+
You should notice the benefits of an IDE, such as syntax highlighting, and smart code interactions.
319+
For example you can place the cursor over any part of the code, such as `os.pwd` in _counter.scala_ and documentation for the method will appear.
320+
321+
When you run your project in the next step, the configuration in _project.scala_ will be used to run the code in the other source files.
322+
323+
### Run the code
324+
325+
If you’re comfortable using your IDE, you can run the code in _counter.scala_ from your IDE.
326+
Attached to the `countFiles` method should be a prompt button. Click it to run the method. This should run without issue.
327+
The `hello` method in _hello.scala_ needs arguments however, so will require extra configuration via the IDE to provide the argument.
328+
329+
Otherwise, you can run either application from the IDE's built-in terminal as described in above sections.
330+
331+
## Next steps
332+
333+
Now that you have tasted a little bit of Scala, you can further explore the language itself, consider checking out:
282334

283335
* [The Scala Book](/scala3/book/introduction.html) (see the Scala 2 version [here](/overviews/scala-book/introduction.html)), which provides a set of short lessons introducing Scala’s main features.
284336
* [The Tour of Scala](/tour/tour-of-scala.html) for bite-sized introductions to Scala's features.
285337
* [Learning Resources](/learn.html), which includes online interactive tutorials and courses.
286338
* [Our list of some popular Scala books](/books.html).
287339

340+
There are also other tutorials for other build-tools you can use with Scala:
341+
* [Getting Started with Scala and sbt](/getting-started/sbt-track/getting-started-with-scala-and-sbt-on-the-command-line.html)
342+
* [Using Scala and Maven](/tutorials/scala-with-maven.html)
343+
288344
## Getting Help
289345
There are a multitude of mailing lists and real-time chat rooms in case you want to quickly connect with other Scala users. Check out our [community](https://scala-lang.org/community/) page for a list of these resources, and for where to reach out for help.

0 commit comments

Comments
 (0)