@@ -44,14 +44,15 @@ class Worksheet {
44
44
* removes redundant blank lines that have been inserted by a previous
45
45
* run.
46
46
*/
47
- prepareForRunning ( ) : void {
47
+ prepareRun ( ) : void {
48
48
this . removeRedundantBlankLines ( ) . then ( _ => this . reset ( ) )
49
49
}
50
50
51
51
/**
52
52
* Run the worksheet in `document`, display a progress bar during the run.
53
53
*/
54
54
run ( ) : Thenable < { } > {
55
+ this . prepareRun ( )
55
56
return vscode . window . withProgress ( {
56
57
location : vscode . ProgressLocation . Notification ,
57
58
title : "Run the worksheet" ,
@@ -214,12 +215,13 @@ export class WorksheetProvider implements Disposable {
214
215
const worksheet = this . worksheetFor ( event . document )
215
216
if ( worksheet ) {
216
217
// Block file saving until the worksheet is ready to be run.
217
- worksheet . prepareForRunning ( )
218
+ worksheet . prepareRun ( )
218
219
}
219
220
} ) ,
220
221
vscode . workspace . onDidSaveTextDocument ( document => {
222
+ const runWorksheetOnSave = vscode . workspace . getConfiguration ( "dotty" ) . get ( "runWorksheetOnSave" )
221
223
const worksheet = this . worksheetFor ( document )
222
- if ( worksheet ) {
224
+ if ( runWorksheetOnSave && worksheet ) {
223
225
return worksheet . run ( )
224
226
}
225
227
} ) ,
@@ -264,28 +266,13 @@ export class WorksheetProvider implements Disposable {
264
266
265
267
/**
266
268
* 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`.
274
269
*/
275
270
private runWorksheetCommand ( ) {
276
271
const editor = vscode . window . activeTextEditor
277
272
if ( editor ) {
278
- const document = editor . document
279
- const worksheet = this . worksheetFor ( document )
273
+ const worksheet = this . worksheetFor ( editor . document )
280
274
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 ( )
289
276
}
290
277
}
291
278
}
0 commit comments