From c7b80e39f600774238f28f541331f57b49b1392f Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 25 Jun 2025 16:12:07 -0700 Subject: [PATCH 1/3] Disable PyREPL --- src/client/extensionActivation.ts | 3 ++- src/client/terminals/codeExecution/helper.ts | 9 --------- src/client/terminals/pythonStartup.ts | 5 +++++ .../terminals/shellIntegration/pythonStartup.test.ts | 8 ++++++++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/client/extensionActivation.ts b/src/client/extensionActivation.ts index 8330d5010f7a..8fae9d5131ff 100644 --- a/src/client/extensionActivation.ts +++ b/src/client/extensionActivation.ts @@ -53,7 +53,7 @@ import { DebuggerTypeName } from './debugger/constants'; import { StopWatch } from './common/utils/stopWatch'; import { registerReplCommands, registerReplExecuteOnEnter, registerStartNativeReplCommand } from './repl/replCommands'; import { registerTriggerForTerminalREPL } from './terminals/codeExecution/terminalReplWatcher'; -import { registerPythonStartup } from './terminals/pythonStartup'; +import { registerBasicRepl, registerPythonStartup } from './terminals/pythonStartup'; import { registerPixiFeatures } from './pythonEnvironments/common/environmentManagers/pixi'; import { registerCustomTerminalLinkProvider } from './terminals/pythonStartupLinkProvider'; import { registerEnvExtFeatures } from './envExt/api.internal'; @@ -184,6 +184,7 @@ async function activateLegacy(ext: ExtensionState, startupStopWatch: StopWatch): serviceManager.get(ITerminalAutoActivation).register(); await registerPythonStartup(ext.context); + await registerBasicRepl(ext.context); serviceManager.get(ICodeExecutionManager).registerCommands(); diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index 31a626207bc4..902619bf1344 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -124,15 +124,6 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { const lineOffset = object.nextBlockLineno - activeEditor!.selection.start.line - 1; await this.moveToNextBlock(lineOffset, activeEditor); } - // For new _pyrepl for Python3.13 and above, we need to send code via bracketed paste mode. - if (object.attach_bracket_paste && replType === ReplType.terminal) { - let trimmedNormalized = object.normalized.replace(/\n$/, ''); - if (trimmedNormalized.endsWith(':\n')) { - // In case where statement is unfinished via :, truncate so auto-indentation lands nicely. - trimmedNormalized = trimmedNormalized.replace(/\n$/, ''); - } - return `\u001b[200~${trimmedNormalized}\u001b[201~`; - } return parse(object.normalized); } catch (ex) { diff --git a/src/client/terminals/pythonStartup.ts b/src/client/terminals/pythonStartup.ts index 28878713a8db..1a2576dce772 100644 --- a/src/client/terminals/pythonStartup.ts +++ b/src/client/terminals/pythonStartup.ts @@ -36,3 +36,8 @@ export async function registerPythonStartup(context: ExtensionContext): Promise< }), ); } + +export async function registerBasicRepl(context: ExtensionContext): Promise { + // TODO: Configurable by setting + context.environmentVariableCollection.replace('PYTHON_BASIC_REPL', '1'); +} diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index 45535d0ceecc..ae778b820905 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -135,6 +135,14 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { globalEnvironmentVariableCollection.verify((c) => c.delete('PYTHONSTARTUP'), TypeMoq.Times.once()); }); + test('PYTHON_BASIC_REPL is set when registerBasicRepl is called', async () => { + await registerPythonStartup(context.object); + globalEnvironmentVariableCollection.verify( + (c) => c.replace('PYTHON_BASIC_REPL', '1', TypeMoq.It.isAny()), + TypeMoq.Times.once(), + ); + }); + test('Ensure registering terminal link calls registerTerminalLinkProvider', async () => { const registerTerminalLinkProviderStub = sinon.stub( pythonStartupLinkProvider, From b68ebd87423dcb841dc8e4db239efc572e2b81ce Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 25 Jun 2025 16:23:47 -0700 Subject: [PATCH 2/3] underscore _replType for now --- src/client/terminals/codeExecution/helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index 902619bf1344..26ebe35aae43 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -55,7 +55,7 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { public async normalizeLines( code: string, - replType: ReplType, + _replType: ReplType, wholeFileContent?: string, resource?: Uri, ): Promise { From 02b909adb618864b0123fb58b8b5872e6828efa9 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 25 Jun 2025 16:42:20 -0700 Subject: [PATCH 3/3] tests --- src/test/terminals/codeExecution/helper.test.ts | 4 ++-- src/test/terminals/shellIntegration/pythonStartup.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/terminals/codeExecution/helper.test.ts b/src/test/terminals/codeExecution/helper.test.ts index a43c5f8746ed..b7e0d1617884 100644 --- a/src/test/terminals/codeExecution/helper.test.ts +++ b/src/test/terminals/codeExecution/helper.test.ts @@ -137,7 +137,7 @@ suite('Terminal - Code Execution Helper', async () => { editor.setup((e) => e.document).returns(() => document.object); }); - test('normalizeLines should handle attach_bracket_paste correctly', async () => { + test('normalizeLines with BASIC_REPL does not attach bracketed paste mode', async () => { configurationService .setup((c) => c.getSettings(TypeMoq.It.isAny())) .returns({ @@ -163,7 +163,7 @@ suite('Terminal - Code Execution Helper', async () => { const result = await helper.normalizeLines('print("Looks like you are on 3.13")', ReplType.terminal); - expect(result).to.equal(`\u001b[200~print("Looks like you are on 3.13")\u001b[201~`); + expect(result).to.equal(`print("Looks like you are on 3.13")`); jsonParseStub.restore(); }); diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index ae778b820905..3c755adf0d9b 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -16,7 +16,7 @@ import { } from 'vscode'; import { assert } from 'chai'; import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis'; -import { registerPythonStartup } from '../../../client/terminals/pythonStartup'; +import { registerBasicRepl, registerPythonStartup } from '../../../client/terminals/pythonStartup'; import { IExtensionContext } from '../../../client/common/types'; import * as pythonStartupLinkProvider from '../../../client/terminals/pythonStartupLinkProvider'; import { CustomTerminalLinkProvider } from '../../../client/terminals/pythonStartupLinkProvider'; @@ -136,7 +136,7 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { }); test('PYTHON_BASIC_REPL is set when registerBasicRepl is called', async () => { - await registerPythonStartup(context.object); + await registerBasicRepl(context.object); globalEnvironmentVariableCollection.verify( (c) => c.replace('PYTHON_BASIC_REPL', '1', TypeMoq.It.isAny()), TypeMoq.Times.once(),