Skip to content

Commit 1d031dd

Browse files
committed
Address review comments
1 parent b7a3e8c commit 1d031dd

File tree

3 files changed

+87
-74
lines changed

3 files changed

+87
-74
lines changed
Lines changed: 79 additions & 0 deletions
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

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ project and its dependencies on their classpath.
3131

3232
![](../../images/worksheets/worksheet-run.png "Run worksheet")
3333

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+
3439
Note that the worksheet are fully integrated with the rest of Dotty IDE: While
3540
typing, errors are shown, completions are suggested, and you can use all the
3641
other features of Dotty IDE such as go to definition, find all references, etc.
@@ -40,77 +45,6 @@ other features of Dotty IDE such as go to definition, find all references, etc.
4045
Implementation details
4146
======================
4247

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-
```
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

0 commit comments

Comments
 (0)