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