Jelajahi Sumber

Merge pull request #6059 from ian-r-rose/restart-run-all-for-file

Fix restart and run all for text files with a code console.
Jason Grout 6 tahun lalu
induk
melakukan
fde4625d86
1 mengubah file dengan 13 tambahan dan 15 penghapusan
  1. 13 15
      packages/fileeditor-extension/src/index.ts

+ 13 - 15
packages/fileeditor-extension/src/index.ts

@@ -735,24 +735,22 @@ function activate(
     menu.runMenu.codeRunners.add({
       tracker,
       noun: 'Code',
-      isEnabled: current => {
-        let found = false;
-        consoleTracker.forEach(console => {
-          if (console.console.session.path === current.context.path) {
-            found = true;
-          }
-        });
-        return found;
-      },
+      isEnabled: current =>
+        !!consoleTracker.find(c => c.session.path === current.context.path),
       run: () => commands.execute(CommandIDs.runCode),
       runAll: () => commands.execute(CommandIDs.runAllCode),
       restartAndRunAll: current => {
-        return current.context.session.restart().then(restarted => {
-          if (restarted) {
-            void commands.execute(CommandIDs.runAllCode);
-          }
-          return restarted;
-        });
+        const console = consoleTracker.find(
+          console => console.session.path === current.context.path
+        );
+        if (console) {
+          return console.session.restart().then(restarted => {
+            if (restarted) {
+              void commands.execute(CommandIDs.runAllCode);
+            }
+            return restarted;
+          });
+        }
       }
     } as IRunMenu.ICodeRunner<IDocumentWidget<FileEditor>>);
   }