-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #5380: Add documentation for worksheet mode #5465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
layout: doc-page | ||
title: "Worksheet Mode - Implementation details" | ||
--- | ||
|
||
In brief, the worksheets extend the Language Server Protocol and rely on the | ||
Dotty REPL to evaluate code. | ||
|
||
## Evaluation | ||
Each of the individual expressions and statements of the worksheet is extracted | ||
and passed to the Dotty REPL. After the REPL has finished evaluating one unit of | ||
input, it emits a special delimiter that indicates the end of the output for | ||
this input. (See `dotty.tools.languageserver.worksheet.InputStreamConsumer`) | ||
|
||
This process continues until all input has been evaluated. | ||
|
||
The Dotty REPL is run in a separate JVM. The `Evaluator` (see | ||
`dotty.tools.languageserver.worksheet.Evaluator`) will re-use a JVM if the | ||
configuration of the project hasn't changed. | ||
|
||
## Communication with the client | ||
The worksheets extend the Language Server Protocol and add one request and one | ||
notification. | ||
|
||
### Run worksheet request | ||
The worksheet run request is sent from the client to the server to request that | ||
the server runs a given worksheet and streams the result. | ||
|
||
*Request:* | ||
|
||
- method: `worksheet/run` | ||
- params: `WorksheetRunParams` defined as follows: | ||
```typescript | ||
interface WorksheetRunParams { | ||
/** | ||
* The worksheet to evaluate. | ||
*/ | ||
textDocument: VersionedTextDocumentIdentifier; | ||
} | ||
``` | ||
|
||
*Response:* | ||
|
||
- result: `WorksheetRunResult` defined as follows: | ||
```typescript | ||
interface WorksheetRunResult { | ||
/** | ||
* Indicates whether evaluation was successful. | ||
*/ | ||
success: boolean; | ||
} | ||
``` | ||
|
||
### Worksheet output notification | ||
The worksheet output notification is sent from the server to the client to | ||
indicate that worksheet execution has produced some output. | ||
|
||
*Notification:* | ||
|
||
- method: `worksheet/publishOutput` | ||
- params: `WorksheetRunOutput` defined as follows: | ||
```typescript | ||
interface WorksheetRunOutput { | ||
/** | ||
* The worksheet that produced this output. | ||
*/ | ||
textDocument: VersionedTextDocumentIdentifier; | ||
|
||
/** | ||
* The line number of the expression that produced this output. | ||
*/ | ||
line: int; | ||
|
||
/** | ||
* The output that has been produced. | ||
*/ | ||
content: string; | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
layout: doc-page | ||
title: "Worksheet mode with Dotty IDE" | ||
--- | ||
|
||
A worksheet is a Scala file that is evaluated on save, and the result of each | ||
expression is shown in a column to the right of your program. Worksheets are | ||
like a REPL session on steroids, and enjoy 1st class editor support: completion, | ||
hyperlinking, interactive errors-as-you-type, etc. Worksheet use the extension | ||
`.sc`. | ||
|
||
How to use the worksheets | ||
========================= | ||
The only supported client for the Worksheet mode is [Visual Studio | ||
Code](https://code.visualstudio.com/). | ||
|
||
To use the worksheets, start Dotty IDE by [following the | ||
instruction]("./ide-support.html") and create a new file `MyWorksheet.sc` and | ||
write some code: | ||
|
||
```scala | ||
val xyz = 123 | ||
println("Hello, worksheets!") | ||
456 + xyz | ||
``` | ||
|
||
On top of the buffer, the message `Run this worksheet` appears. Click it to | ||
evaluate the code of the worksheet. Each line of output is printed on the right | ||
of the expression that produced it. The worksheets run with the classes of your | ||
project and its dependencies on their classpath. | ||
|
||
 | ||
|
||
By default, the worksheets are also run when the file is saved. This can be | ||
configured in VSCode preferences: | ||
|
||
 | ||
|
||
Note that the worksheet are fully integrated with the rest of Dotty IDE: While | ||
typing, errors are shown, completions are suggested, and you can use all the | ||
other features of Dotty IDE such as go to definition, find all references, etc. | ||
|
||
 | ||
|
||
Implementation details | ||
Duhemm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
====================== | ||
|
||
The implementation details of the worksheet mode and the information necessary to add support for | ||
other clients are available in [Worksheet mode - Implementation | ||
details](worksheet-mode-implementation-details.html). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.