You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _overviews/getting-started/install-scala.md
+70-14Lines changed: 70 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -164,7 +164,7 @@ string to standard output.
164
164
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
@@ -246,44 +246,100 @@ You can execute code interactively using the REPL provided by the `scala` comman
246
246
$ scala
247
247
Welcome to Scala {{site.scala-3-version}} (20-ea, Java OpenJDK 64-Bit Server VM).
248
248
Type in expressions for evaluation. Or try :help.
249
-
250
-
scala>
249
+
250
+
scala>
251
251
```
252
252
253
253
Write a line of code to be executed and press enter.
254
254
```
255
255
scala> println("Hello, World!")
256
256
Hello, World!
257
-
258
-
scala>
257
+
258
+
scala>
259
259
```
260
260
261
261
The result will be printed immediately after executing the line. You can declare values:
262
262
```
263
263
scala> val i = 1
264
264
val i: Int = 1
265
-
266
-
scala>
265
+
266
+
scala>
267
267
```
268
268
269
269
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.
270
270
```
271
271
scala> i + 3
272
272
val res0: Int = 4
273
-
274
-
scala>
273
+
274
+
scala>
275
275
```
276
276
You can exit the REPL with `:exit`.
277
277
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
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
+
//>usingscala{{site.scala-3-version}}
293
+
//>usingtoolkit0.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.
279
297
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.
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:
282
334
283
335
*[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.
284
336
*[The Tour of Scala](/tour/tour-of-scala.html) for bite-sized introductions to Scala's features.
285
337
*[Learning Resources](/learn.html), which includes online interactive tutorials and courses.
286
338
*[Our list of some popular Scala books](/books.html).
287
339
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
+
288
344
## Getting Help
289
345
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