From 4cda7c3fad906f5a7a76286866ada03c0deda1ca Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Wed, 15 May 2024 13:23:26 -0400 Subject: [PATCH] Introduce new setting (#1353) --- package.json | 7 ++++++- src/extension/executors/runner/index.ts | 8 ++++++-- src/extension/executors/task.ts | 4 +++- src/utils/configuration.ts | 6 ++++++ tests/extension/__snapshots__/configuration.test.ts.snap | 1 + tests/extension/configuration.test.ts | 5 +++++ 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index bfec59365..37adc43ad 100644 --- a/package.json +++ b/package.json @@ -700,6 +700,11 @@ "default": 10, "markdownDescription": "Default number of rows in notebook terminal" }, + "runme.terminal.closeOnSuccess": { + "type": "boolean", + "default": true, + "markdownDescription": "If set to 'true', integrated terminal panel is being closed upon successful completion of cell/task." + }, "runme.actions.openViewInEditor": { "type": "string", "default": "split", @@ -1118,4 +1123,4 @@ "yaml": "^2.3.2", "zod": "^3.22.2" } -} +} \ No newline at end of file diff --git a/src/extension/executors/runner/index.ts b/src/extension/executors/runner/index.ts index 83063da73..4baad600a 100644 --- a/src/extension/executors/runner/index.ts +++ b/src/extension/executors/runner/index.ts @@ -26,7 +26,10 @@ import { import { IRunnerEnvironment } from '../../runner/environment' import { getAnnotations, getCellRunmeId, getTerminalByCell } from '../../utils' import { postClientMessage } from '../../../utils/messaging' -import { isNotebookTerminalEnabledForCell } from '../../../utils/configuration' +import { + getCloseTerminalOnSuccess, + isNotebookTerminalEnabledForCell, +} from '../../../utils/configuration' import { ITerminalState } from '../../terminal/terminalState' import { toggleTerminal } from '../../commands' import { @@ -367,7 +370,8 @@ export const executeRunner: IKernelRunner = async ({ /** * only close terminal if execution passed and desired by user */ - if (e.exitCode === 0 && closeTerminalOnSuccess && !background) { + const closeIt = getCloseTerminalOnSuccess() && closeTerminalOnSuccess + if (e.exitCode === 0 && closeIt && !background) { closeTerminalByEnvID(RUNME_ID) } }) diff --git a/src/extension/executors/task.ts b/src/extension/executors/task.ts index 0a855e2ed..0348b4640 100644 --- a/src/extension/executors/task.ts +++ b/src/extension/executors/task.ts @@ -17,6 +17,7 @@ import { getAnnotations, getTerminalRunmeId } from '../utils' import { PLATFORM_OS, ENV_STORE } from '../constants' import { DEFAULT_PROMPT_ENV } from '../../constants' import { ResolveProgramRequest_Mode } from '../grpc/runner/v1' +import { getCloseTerminalOnSuccess } from '../../utils/configuration' import { getCmdShellSeq, @@ -136,7 +137,8 @@ export const taskExecutor: IKernelExecutor = async (executor) => { /** * only close terminal if execution passed and desired by user */ - if (e.exitCode === 0 && annotations.closeTerminalOnSuccess) { + const closeIt = getCloseTerminalOnSuccess() && annotations.closeTerminalOnSuccess + if (e.exitCode === 0 && closeIt) { closeTerminalByEnvID(RUNME_ID) } diff --git a/src/utils/configuration.ts b/src/utils/configuration.ts index 485184222..10966207a 100644 --- a/src/utils/configuration.ts +++ b/src/utils/configuration.ts @@ -47,6 +47,7 @@ const notebookTerminalSchema = { cursorWidth: z.number().min(1).optional(), smoothScrollDuration: z.number().optional(), scrollback: z.number().optional(), + closeOnSuccess: z.boolean().default(true), } const configurationSchema = { @@ -274,6 +275,10 @@ const isNotebookTerminalEnabledForCell = (cell: NotebookCell): boolean => { : isNotebookTerminalFeatureEnabled('nonInteractive') } +const getCloseTerminalOnSuccess = () => { + return getRunmeTerminalConfigurationValue('closeOnSuccess', true) +} + const getCodeLensEnabled = (): boolean => { return getCodeLensConfigurationValue('enable', true) } @@ -411,6 +416,7 @@ export { getActionsOpenViewInEditor, getBinaryPath, getCLIUseIntegratedRunme, + getCloseTerminalOnSuccess, getCodeLensEnabled, getCodeLensPasteIntoTerminalNewline, getNotebookExecutionOrder, diff --git a/tests/extension/__snapshots__/configuration.test.ts.snap b/tests/extension/__snapshots__/configuration.test.ts.snap index 062fb37de..566151577 100644 --- a/tests/extension/__snapshots__/configuration.test.ts.snap +++ b/tests/extension/__snapshots__/configuration.test.ts.snap @@ -3,6 +3,7 @@ exports[`Configuration > should get nullish from font family 1`] = ` { "backgroundTask": true, + "closeOnSuccess": true, "cursorBlink": undefined, "cursorStyle": "bar", "cursorWidth": undefined, diff --git a/tests/extension/configuration.test.ts b/tests/extension/configuration.test.ts index 8c278ebf4..9a9588ca6 100644 --- a/tests/extension/configuration.test.ts +++ b/tests/extension/configuration.test.ts @@ -16,6 +16,7 @@ import { getCodeLensPasteIntoTerminalNewline, getCLIUseIntegratedRunme, getNotebookExecutionOrder, + getCloseTerminalOnSuccess, } from '../../src/utils/configuration' import { SERVER_PORT } from '../../src/constants' import { RunmeIdentity } from '../../src/extension/grpc/serializerTypes' @@ -142,6 +143,10 @@ suite('Configuration', () => { ).toStrictEqual(RunmeIdentity.CELL) }) + test('getCloseTerminalOnSuccess should return true by default', () => { + expect(getCloseTerminalOnSuccess()).toStrictEqual(true) + }) + test('getCodeLensEnabled should return true by default', () => { expect(getCodeLensEnabled()).toStrictEqual(true) })