Skip to content

Commit 3a3d5a3

Browse files
authored
Merge pull request #5465 from dotty-staging/update-ide-doc
Fix #5380: Add documentation for worksheet mode
2 parents 07aaaf9 + 1d031dd commit 3a3d5a3

7 files changed

+133
-1
lines changed

docs/docs/usage/ide-support.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ Status
3434
- Type information on hover
3535
- Go to definition (in the current project)
3636
- Find all references
37+
- Documentation on hover
38+
- [Worksheet mode](worksheet-mode.html)
3739

3840
## Partially working features:
3941
- Completion
4042
- Renaming
4143
- Go to definition in external projects
4244

4345
## Unimplemented features:
44-
- Documentation on hover
4546
- Formatting code (requires integrating with scalafmt)
4647
- Quick fixes (probably by integrating with scalafix)
4748

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
layout: doc-page
3+
title: "Worksheet Mode - Implementation details"
4+
---
5+
6+
In brief, the worksheets extend the Language Server Protocol and rely on the
7+
Dotty REPL to evaluate code.
8+
9+
## Evaluation
10+
Each of the individual expressions and statements of the worksheet is extracted
11+
and passed to the Dotty REPL. After the REPL has finished evaluating one unit of
12+
input, it emits a special delimiter that indicates the end of the output for
13+
this input. (See `dotty.tools.languageserver.worksheet.InputStreamConsumer`)
14+
15+
This process continues until all input has been evaluated.
16+
17+
The Dotty REPL is run in a separate JVM. The `Evaluator` (see
18+
`dotty.tools.languageserver.worksheet.Evaluator`) will re-use a JVM if the
19+
configuration of the project hasn't changed.
20+
21+
## Communication with the client
22+
The worksheets extend the Language Server Protocol and add one request and one
23+
notification.
24+
25+
### Run worksheet request
26+
The worksheet run request is sent from the client to the server to request that
27+
the server runs a given worksheet and streams the result.
28+
29+
*Request:*
30+
31+
- method: `worksheet/run`
32+
- params: `WorksheetRunParams` defined as follows:
33+
```typescript
34+
interface WorksheetRunParams {
35+
/**
36+
* The worksheet to evaluate.
37+
*/
38+
textDocument: VersionedTextDocumentIdentifier;
39+
}
40+
```
41+
42+
*Response:*
43+
44+
- result: `WorksheetRunResult` defined as follows:
45+
```typescript
46+
interface WorksheetRunResult {
47+
/**
48+
* Indicates whether evaluation was successful.
49+
*/
50+
success: boolean;
51+
}
52+
```
53+
54+
### Worksheet output notification
55+
The worksheet output notification is sent from the server to the client to
56+
indicate that worksheet execution has produced some output.
57+
58+
*Notification:*
59+
60+
- method: `worksheet/publishOutput`
61+
- params: `WorksheetRunOutput` defined as follows:
62+
```typescript
63+
interface WorksheetRunOutput {
64+
/**
65+
* The worksheet that produced this output.
66+
*/
67+
textDocument: VersionedTextDocumentIdentifier;
68+
69+
/**
70+
* The line number of the expression that produced this output.
71+
*/
72+
line: int;
73+
74+
/**
75+
* The output that has been produced.
76+
*/
77+
content: string;
78+
}
79+
```

docs/docs/usage/worksheet-mode.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
layout: doc-page
3+
title: "Worksheet mode with Dotty IDE"
4+
---
5+
6+
A worksheet is a Scala file that is evaluated on save, and the result of each
7+
expression is shown in a column to the right of your program. Worksheets are
8+
like a REPL session on steroids, and enjoy 1st class editor support: completion,
9+
hyperlinking, interactive errors-as-you-type, etc. Worksheet use the extension
10+
`.sc`.
11+
12+
How to use the worksheets
13+
=========================
14+
The only supported client for the Worksheet mode is [Visual Studio
15+
Code](https://code.visualstudio.com/).
16+
17+
To use the worksheets, start Dotty IDE by [following the
18+
instruction]("./ide-support.html") and create a new file `MyWorksheet.sc` and
19+
write some code:
20+
21+
```scala
22+
val xyz = 123
23+
println("Hello, worksheets!")
24+
456 + xyz
25+
```
26+
27+
On top of the buffer, the message `Run this worksheet` appears. Click it to
28+
evaluate the code of the worksheet. Each line of output is printed on the right
29+
of the expression that produced it. The worksheets run with the classes of your
30+
project and its dependencies on their classpath.
31+
32+
![](../../images/worksheets/worksheet-run.png "Run worksheet")
33+
34+
By default, the worksheets are also run when the file is saved. This can be
35+
configured in VSCode preferences:
36+
37+
![](../../images/worksheets/config-autorun.png "Configure run on save")
38+
39+
Note that the worksheet are fully integrated with the rest of Dotty IDE: While
40+
typing, errors are shown, completions are suggested, and you can use all the
41+
other features of Dotty IDE such as go to definition, find all references, etc.
42+
43+
![](../../images/worksheets/worksheet-help.png "IDE features in the worksheet")
44+
45+
Implementation details
46+
======================
47+
48+
The implementation details of the worksheet mode and the information necessary to add support for
49+
other clients are available in [Worksheet mode - Implementation
50+
details](worksheet-mode-implementation-details.html).
33.6 KB
Loading
10.3 KB
Loading
19.2 KB
Loading

docs/sidebar.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ sidebar:
99
url: docs/usage/sbt-projects.html
1010
- title: IDE support for Dotty
1111
url: docs/usage/ide-support.html
12+
- title: Worksheet mode in Dotty IDE
13+
url: docs/usage/worksheet-mode.html
1214
- title: cbt-projects
1315
url: docs/usage/cbt-projects.html
1416
- title: Dottydoc

0 commit comments

Comments
 (0)