Skip to content

Commit b7a3e8c

Browse files
committed
Fix #5380: Add documentation for worksheet mode
1 parent 2d23cba commit b7a3e8c

File tree

5 files changed

+120
-1
lines changed

5 files changed

+120
-1
lines changed

docs/docs/usage/ide-support.md

Lines changed: 2 additions & 1 deletion
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

docs/docs/usage/worksheet-mode.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
Note that the worksheet are fully integrated with the rest of Dotty IDE: While
35+
typing, errors are shown, completions are suggested, and you can use all the
36+
other features of Dotty IDE such as go to definition, find all references, etc.
37+
38+
![](../../images/worksheets/worksheet-help.png "IDE features in the worksheet")
39+
40+
Implementation details
41+
======================
42+
43+
In overview, the worksheets extend the Language Server Protocol and rely on the
44+
Dotty REPL to evaluate code.
45+
46+
## Evaluation
47+
Each of the individual expressions and statements of the worksheet is extracted
48+
and passed to the Dotty REPL. After the REPL has finished evaluating one unit of
49+
input, it emits a special delimiter that indicates the end of the output for
50+
this input. (See `dotty.tools.languageserver.worksheet.InputStreamConsumer`)
51+
52+
This process continues until all input has been evaluated.
53+
54+
The Dotty REPL is run in a separate JVM. The `Evaluator` (see
55+
`dotty.tools.languageserver.worksheet.Evaluator`) will re-use a JVM if the
56+
configuration of the project hasn't changed.
57+
58+
## Communication with the client
59+
The worksheets extend the Language Server Protocol and add one request and one
60+
notification.
61+
62+
### Run worksheet request
63+
The worksheet run request is sent from the client to the server to request that
64+
the server runs a given worksheet and streams the result.
65+
66+
*Request:*
67+
68+
- method: `worksheet/run`
69+
- params: `WorksheetRunParams` defined as follows:
70+
```typescript
71+
interface WorksheetRunParams {
72+
/**
73+
* The worksheet to evaluate.
74+
*/
75+
textDocument: VersionedTextDocumentIdentifier;
76+
}
77+
```
78+
79+
*Response:*
80+
81+
- result: `WorksheetRunResult` defined as follows:
82+
```typescript
83+
interface WorksheetRunResult {
84+
/**
85+
* Indicates whether evaluation was successful.
86+
*/
87+
success: boolean;
88+
}
89+
```
90+
91+
### Worksheet output notification
92+
The worksheet output notification is sent from the server to the client to
93+
indicate that worksheet execution has produced some output.
94+
95+
*Notification:*
96+
97+
- method: `worksheet/publishOutput`
98+
- params: `WorksheetRunOutput` defined as follows:
99+
```typescript
100+
interface WorksheetRunOutput {
101+
/**
102+
* The worksheet that produced this output.
103+
*/
104+
textDocument: VersionedTextDocumentIdentifier;
105+
106+
/**
107+
* The line number of the expression that produced this output.
108+
*/
109+
line: int;
110+
111+
/**
112+
* The output that has been produced.
113+
*/
114+
content: string;
115+
}
116+
```
10.3 KB
Loading
19.2 KB
Loading

docs/sidebar.yml

Lines changed: 2 additions & 0 deletions
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)