Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/client/extensionActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -184,6 +184,7 @@ async function activateLegacy(ext: ExtensionState, startupStopWatch: StopWatch):
serviceManager.get<ITerminalAutoActivation>(ITerminalAutoActivation).register();

await registerPythonStartup(ext.context);
await registerBasicRepl(ext.context);

serviceManager.get<ICodeExecutionManager>(ICodeExecutionManager).registerCommands();

Expand Down
11 changes: 1 addition & 10 deletions src/client/terminals/codeExecution/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {

public async normalizeLines(
code: string,
replType: ReplType,
_replType: ReplType,
wholeFileContent?: string,
resource?: Uri,
): Promise<string> {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/client/terminals/pythonStartup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ export async function registerPythonStartup(context: ExtensionContext): Promise<
}),
);
}

export async function registerBasicRepl(context: ExtensionContext): Promise<void> {
// TODO: Configurable by setting
context.environmentVariableCollection.replace('PYTHON_BASIC_REPL', '1');
}
4 changes: 2 additions & 2 deletions src/test/terminals/codeExecution/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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();
});

Expand Down
10 changes: 9 additions & 1 deletion src/test/terminals/shellIntegration/pythonStartup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 registerBasicRepl(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,
Expand Down