Skip to content

Commit 78f9298

Browse files
committed
make my code cleaner
1 parent fdca3c1 commit 78f9298

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/client/common/terminal/service.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { useEnvExtension } from '../../envExt/api.internal';
2525
import { ensureTerminalLegacy } from '../../envExt/api.legacy';
2626
import { sleep } from '../utils/async';
2727
import { isWindows } from '../utils/platform';
28-
import { getActiveInterpreter } from '../../repl/replUtils';
28+
import { getPythonMinorVersion } from '../../repl/replUtils';
2929

3030
@injectable()
3131
export class TerminalService implements ITerminalService, Disposable {
@@ -110,16 +110,12 @@ export class TerminalService implements ITerminalService, Disposable {
110110
const config = getConfiguration('python');
111111
const pythonrcSetting = config.get<boolean>('terminal.shellIntegration.enabled');
112112

113-
let minorVersion: number | undefined;
114-
// Need to check for if Python version is >= 3.13 since we have turned off SI on python side.
115-
// Because we are not sending explicit commandline info to core, it will inject ^C. (We want to avoid)
116-
if (this.options && this.options.resource) {
117-
const pythonVersion = await getActiveInterpreter(
118-
this.options.resource,
119-
this.serviceContainer.get<IInterpreterService>(IInterpreterService),
120-
);
121-
minorVersion = pythonVersion?.version?.minor;
122-
}
113+
const minorVersion = this.options?.resource
114+
? await getPythonMinorVersion(
115+
this.options.resource,
116+
this.serviceContainer.get<IInterpreterService>(IInterpreterService),
117+
)
118+
: undefined;
123119

124120
if ((isPythonShell && !pythonrcSetting) || (isPythonShell && isWindows()) || (minorVersion ?? 0) >= 13) {
125121
// If user has explicitly disabled SI for Python, use sendText for inside Terminal REPL.

src/client/repl/replUtils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,17 @@ export function getTabNameForUri(uri: Uri): string | undefined {
118118

119119
return undefined;
120120
}
121+
122+
/**
123+
* Function that will return the minor version of current active Python interpreter.
124+
*/
125+
export async function getPythonMinorVersion(
126+
uri: Uri | undefined,
127+
interpreterService: IInterpreterService,
128+
): Promise<number | undefined> {
129+
if (uri) {
130+
const pythonVersion = await getActiveInterpreter(uri, interpreterService);
131+
return pythonVersion?.version?.minor;
132+
}
133+
return undefined;
134+
}

0 commit comments

Comments
 (0)