Skip to content

Commit dc11862

Browse files
committed
add ReplType for terminal and native
1 parent 3e30f9d commit dc11862

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

src/client/repl/replCommands.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import { registerCommand } from '../common/vscodeApis/commandApis';
1818
import { sendTelemetryEvent } from '../telemetry';
1919
import { EventName } from '../telemetry/constants';
20+
import { ReplType } from './types';
2021

2122
/**
2223
* Register Start Native REPL command in the command palette
@@ -69,7 +70,11 @@ export async function registerReplCommands(
6970
if (activeEditor && activeEditor.document) {
7071
wholeFileContent = activeEditor.document.getText();
7172
}
72-
const normalizedCode = await executionHelper.normalizeLines(code!, wholeFileContent);
73+
const normalizedCode = await executionHelper.normalizeLines(
74+
code!,
75+
ReplType.native,
76+
wholeFileContent,
77+
);
7378
await nativeRepl.sendToNativeRepl(normalizedCode);
7479
}
7580
}

src/client/repl/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
export enum ReplType {
7+
terminal = 'terminal',
8+
native = 'native',
9+
}

src/client/terminals/codeExecution/codeExecutionManager.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
CreateEnvironmentCheckKind,
2222
triggerCreateEnvironmentCheckNonBlocking,
2323
} from '../../pythonEnvironments/creation/createEnvironmentTrigger';
24+
import { ReplType } from '../../repl/types';
2425

2526
@injectable()
2627
export class CodeExecutionManager implements ICodeExecutionManager {
@@ -149,7 +150,11 @@ export class CodeExecutionManager implements ICodeExecutionManager {
149150
if (activeEditor && activeEditor.document) {
150151
wholeFileContent = activeEditor.document.getText();
151152
}
152-
const normalizedCode = await codeExecutionHelper.normalizeLines(codeToExecute!, wholeFileContent);
153+
const normalizedCode = await codeExecutionHelper.normalizeLines(
154+
codeToExecute!,
155+
ReplType.terminal,
156+
wholeFileContent,
157+
);
153158
if (!normalizedCode || normalizedCode.trim().length === 0) {
154159
return;
155160
}

src/client/terminals/codeExecution/helper.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { traceError } from '../../logging';
2323
import { IConfigurationService, Resource } from '../../common/types';
2424
import { sendTelemetryEvent } from '../../telemetry';
2525
import { EventName } from '../../telemetry/constants';
26+
import { ReplType } from '../../repl/types';
2627

2728
@injectable()
2829
export class CodeExecutionHelper implements ICodeExecutionHelper {
@@ -52,7 +53,12 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {
5253
this.activeResourceService = this.serviceContainer.get<IActiveResourceService>(IActiveResourceService);
5354
}
5455

55-
public async normalizeLines(code: string, wholeFileContent?: string, resource?: Uri): Promise<string> {
56+
public async normalizeLines(
57+
code: string,
58+
replType: ReplType,
59+
wholeFileContent?: string,
60+
resource?: Uri,
61+
): Promise<string> {
5662
try {
5763
if (code.trim().length === 0) {
5864
return '';
@@ -119,7 +125,7 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {
119125
await this.moveToNextBlock(lineOffset, activeEditor);
120126
}
121127
// For new _pyrepl for Python3.13 and above, we need to send code via bracketed paste mode.
122-
if (object.attach_bracket_paste) {
128+
if (object.attach_bracket_paste && replType === ReplType.terminal) {
123129
let trimmedNormalized = object.normalized.replace(/\n$/, '');
124130
if (trimmedNormalized.endsWith(':\n')) {
125131
// In case where statement is unfinished via :, truncate so auto-indentation lands nicely.

src/client/terminals/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { Event, Terminal, TextEditor, Uri } from 'vscode';
55
import { IDisposable, Resource } from '../common/types';
6+
import { ReplType } from '../repl/types';
67

78
export const ICodeExecutionService = Symbol('ICodeExecutionService');
89

@@ -15,7 +16,7 @@ export interface ICodeExecutionService {
1516
export const ICodeExecutionHelper = Symbol('ICodeExecutionHelper');
1617

1718
export interface ICodeExecutionHelper {
18-
normalizeLines(code: string, wholeFileContent?: string): Promise<string>;
19+
normalizeLines(code: string, replType: ReplType, wholeFileContent?: string, resource?: Uri): Promise<string>;
1920
getFileToExecute(): Promise<Uri | undefined>;
2021
saveFileIfDirty(file: Uri): Promise<Resource>;
2122
getSelectedTextToExecute(textEditor: TextEditor): Promise<string | undefined>;

0 commit comments

Comments
 (0)