Skip to content

Commit 1b4b69c

Browse files
committed
Decouple saving and running the worksheet
- Do not automatically save the worksheet when the run command is executed. - Make it possible to save the worksheet without running it (by setting the configuration value dotty.runWorksheetOnSave to false)
1 parent 97c63aa commit 1b4b69c

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

vscode-dotty/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@
4040
]
4141
}
4242
],
43+
"configuration": {
44+
"type": "object",
45+
"title": "Dotty configuration",
46+
"properties": {
47+
"dotty.runWorksheetOnSave": {
48+
"type": "boolean",
49+
"default": true,
50+
"description": "If true, saving a worksheet will also run it"
51+
}
52+
}
53+
},
4354
"commands": [
4455
{
4556
"command": "dotty.worksheet.run",

vscode-dotty/src/worksheet.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ class Worksheet {
4444
* removes redundant blank lines that have been inserted by a previous
4545
* run.
4646
*/
47-
prepareForRunning(): void {
47+
prepareRun(): void {
4848
this.removeRedundantBlankLines().then(_ => this.reset())
4949
}
5050

5151
/**
5252
* Run the worksheet in `document`, display a progress bar during the run.
5353
*/
5454
run(): Thenable<{}> {
55+
this.prepareRun()
5556
return vscode.window.withProgress({
5657
location: vscode.ProgressLocation.Notification,
5758
title: "Run the worksheet",
@@ -214,12 +215,13 @@ export class WorksheetProvider implements Disposable {
214215
const worksheet = this.worksheetFor(event.document)
215216
if (worksheet) {
216217
// Block file saving until the worksheet is ready to be run.
217-
worksheet.prepareForRunning()
218+
worksheet.prepareRun()
218219
}
219220
}),
220221
vscode.workspace.onDidSaveTextDocument(document => {
222+
const runWorksheetOnSave = vscode.workspace.getConfiguration("dotty").get("runWorksheetOnSave")
221223
const worksheet = this.worksheetFor(document)
222-
if (worksheet) {
224+
if (runWorksheetOnSave && worksheet) {
223225
return worksheet.run()
224226
}
225227
}),
@@ -264,28 +266,13 @@ export class WorksheetProvider implements Disposable {
264266

265267
/**
266268
* The VSCode command executed when the user select `Run worksheet`.
267-
*
268-
* We check whether the buffer is dirty, and if it is, we save it. Running the worksheet will then be
269-
* triggered by file save.
270-
* If the buffer is clean, we do the necessary preparation for worksheet (compute margin,
271-
* remove blank lines, etc.) and check if the buffer has been changed by that. If it is, we save
272-
* and the run will be triggered by file save.
273-
* If the buffer is still clean, call `Worksheet#run`.
274269
*/
275270
private runWorksheetCommand() {
276271
const editor = vscode.window.activeTextEditor
277272
if (editor) {
278-
const document = editor.document
279-
const worksheet = this.worksheetFor(document)
273+
const worksheet = this.worksheetFor(editor.document)
280274
if (worksheet) {
281-
if (document.isDirty) document.save() // This will trigger running the worksheet
282-
else {
283-
worksheet.prepareForRunning()
284-
if (document.isDirty) document.save() // This will trigger running the worksheet
285-
else {
286-
worksheet.run()
287-
}
288-
}
275+
worksheet.run()
289276
}
290277
}
291278
}

0 commit comments

Comments
 (0)