From faebdb6d4668a08132ace6556e64a6e0821e003c Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 25 Oct 2023 23:14:14 -0700 Subject: [PATCH 01/31] detect user is on file with deprecated Python code --- pythonFiles/normalizeSelection.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index 7ace42daa901..46db3982f339 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -3,11 +3,22 @@ import ast import json +import os +import pathlib import re import sys import textwrap from typing import Iterable +script_dir = pathlib.Path( + "User/anthonykim/Desktop/vscode-python/pythonFiles/lib/python" +) +sys.path.append(os.fspath(script_dir)) +import debugpy + +debugpy.connect(5678) +debugpy.breakpoint() + def split_lines(source): """ @@ -150,8 +161,16 @@ def traverse_file(wholeFileContent, start_line, end_line, was_highlighted): or a multiline dictionary, or differently styled multi-line list comprehension, etc. Then call the normalize_lines function to normalize our smartly selected code block. """ + parsed_file_content = None + + try: + parsed_file_content = ast.parse(wholeFileContent) + except Exception as old_python_code: + # Handle case where user is attempting to run code where file contains deprecated Python code. + # Somehow have to let typescript side know and show warning message. (TODO) + print(old_python_code) + return - parsed_file_content = ast.parse(wholeFileContent) smart_code = "" should_run_top_blocks = [] From 14f9b64646a18ca0fbc770ac44cace9e042a3d2b Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 25 Oct 2023 23:50:57 -0700 Subject: [PATCH 02/31] send warning message if smart send deprecated py --- pythonFiles/normalizeSelection.py | 21 +++++++++++-------- src/client/terminals/codeExecution/helper.ts | 8 +++---- .../codeExecution/terminalCodeExecution.ts | 20 +++++++++++++++--- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index 46db3982f339..a381ea55e58f 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -10,14 +10,14 @@ import textwrap from typing import Iterable -script_dir = pathlib.Path( - "User/anthonykim/Desktop/vscode-python/pythonFiles/lib/python" -) -sys.path.append(os.fspath(script_dir)) -import debugpy +# script_dir = pathlib.Path( +# "User/anthonykim/Desktop/vscode-python/pythonFiles/lib/python" +# ) +# sys.path.append(os.fspath(script_dir)) +# import debugpy -debugpy.connect(5678) -debugpy.breakpoint() +# debugpy.connect(5678) +# debugpy.breakpoint() def split_lines(source): @@ -168,8 +168,11 @@ def traverse_file(wholeFileContent, start_line, end_line, was_highlighted): except Exception as old_python_code: # Handle case where user is attempting to run code where file contains deprecated Python code. # Somehow have to let typescript side know and show warning message. (TODO) - print(old_python_code) - return + # print(old_python_code) + return { + "normalized_smart_result": "deprecated", + "which_line_next": 0, + } smart_code = "" should_run_top_blocks = [] diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index 058c78e332a3..2f27c5f0cce5 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -105,10 +105,10 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { const result = await normalizeOutput.promise; const object = JSON.parse(result); - if (activeEditor?.selection) { - const lineOffset = object.nextBlockLineno - activeEditor!.selection.start.line - 1; - await this.moveToNextBlock(lineOffset, activeEditor); - } + // if (activeEditor?.selection) { + // const lineOffset = object.nextBlockLineno - activeEditor!.selection.start.line - 1; + // await this.moveToNextBlock(lineOffset, activeEditor); + // } return parse(object.normalized); } catch (ex) { diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 50270c3586c4..39b1d722fff4 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -5,12 +5,15 @@ import { inject, injectable } from 'inversify'; import * as path from 'path'; -import { Disposable, Uri } from 'vscode'; +import { Disposable, l10n, Uri } from 'vscode'; import { IWorkspaceService } from '../../common/application/types'; +import { Commands } from '../../common/constants'; import '../../common/extensions'; import { IPlatformService } from '../../common/platform/types'; import { ITerminalService, ITerminalServiceFactory } from '../../common/terminal/types'; import { IConfigurationService, IDisposableRegistry, Resource } from '../../common/types'; +import { Common } from '../../common/utils/localize'; +import { showWarningMessage } from '../../common/vscodeApis/windowApis'; import { IInterpreterService } from '../../interpreter/contracts'; import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec'; import { ICodeExecutionService } from '../../terminals/types'; @@ -42,9 +45,20 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { if (!code || code.trim().length === 0) { return; } - + if (code == 'deprecated') { + // If user is trying to smart send deprecated code show warning + await showWarningMessage( + l10n.t( + `You are attempting to run Smart Send on Python file with deprecated code, please + turn off smart send if you wish to always run line by line or explicitly select code + to force run [logs](command:${Commands.ViewOutput}) for more details.`, + ), + Common.learnMore, + ); + } else { + await this.getTerminalService(resource).sendText(code); + } await this.initializeRepl(resource); - await this.getTerminalService(resource).sendText(code); } public async initializeRepl(resource: Resource) { const terminalService = this.getTerminalService(resource); From e1d203fb9147ef7febfde679308d00f8e21ede9c Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 26 Oct 2023 00:55:06 -0700 Subject: [PATCH 03/31] add setting --- package.json | 6 ++++++ package.nls.json | 1 + pythonFiles/normalizeSelection.py | 6 +++++- src/client/common/configSettings.ts | 4 ++++ src/client/common/types.ts | 5 +++++ src/client/terminals/codeExecution/helper.ts | 8 ++++++++ .../terminals/codeExecution/terminalCodeExecution.ts | 3 ++- 7 files changed, 31 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 37a3a4a5d139..cc9cfa120fa7 100644 --- a/package.json +++ b/package.json @@ -699,6 +699,12 @@ "scope": "resource", "type": "array" }, + "python.REPL.EnableREPLSmartSend": { + "default": true, + "description": "%python.EnableREPLSmartSend.description%", + "scope": "resource", + "type": "boolean" + }, "python.testing.autoTestDiscoverOnSaveEnabled": { "default": true, "description": "%python.testing.autoTestDiscoverOnSaveEnabled.description%", diff --git a/package.nls.json b/package.nls.json index f328ee613ba9..9990f15ff84d 100644 --- a/package.nls.json +++ b/package.nls.json @@ -58,6 +58,7 @@ "python.missingPackage.severity.description": "Set severity of missing packages in requirements.txt or pyproject.toml", "python.pipenvPath.description": "Path to the pipenv executable to use for activation.", "python.poetryPath.description": "Path to the poetry executable.", + "python.EnableREPLSmartSend.description": "Toggle smart send for the Python REPL.", "python.tensorBoard.logDirectory.description": "Set this setting to your preferred TensorBoard log directory to skip log directory prompt when starting TensorBoard.", "python.tensorBoard.logDirectory.markdownDeprecationMessage": "Tensorboard support has been moved to the extension [Tensorboard extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.tensorboard). Instead use the setting `tensorBoard.logDirectory`.", "python.tensorBoard.logDirectory.deprecationMessage": "Tensorboard support has been moved to the extension Tensorboard extension. Instead use the setting `tensorBoard.logDirectory`.", diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index a381ea55e58f..eb696101cc36 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -289,7 +289,11 @@ def get_next_block_lineno(which_line_next): data = None which_line_next = 0 - if empty_Highlight and contents.get("smartSendExperimentEnabled"): + if ( + empty_Highlight + and contents.get("smartSendExperimentEnabled") + and contents.get("smartSendSettingsEnabled") + ): result = traverse_file( contents["wholeFileContent"], vscode_start_line, diff --git a/src/client/common/configSettings.ts b/src/client/common/configSettings.ts index f9c56d4992fe..dfb153fdb909 100644 --- a/src/client/common/configSettings.ts +++ b/src/client/common/configSettings.ts @@ -29,6 +29,7 @@ import { IInterpreterPathService, IInterpreterSettings, IPythonSettings, + IREPLSettings, ITensorBoardSettings, ITerminalSettings, Resource, @@ -114,6 +115,8 @@ export class PythonSettings implements IPythonSettings { public globalModuleInstallation = false; + public REPL!: IREPLSettings; + public experiments!: IExperiments; public languageServer: LanguageServerType = LanguageServerType.Node; @@ -363,6 +366,7 @@ export class PythonSettings implements IPythonSettings { activateEnvInCurrentTerminal: false, }; + this.REPL = systemVariables.resolveAny(pythonSettings.get('REPL'))!; const experiments = systemVariables.resolveAny(pythonSettings.get('experiments'))!; if (this.experiments) { Object.assign(this.experiments, experiments); diff --git a/src/client/common/types.ts b/src/client/common/types.ts index 742948a49652..fc156dd5a815 100644 --- a/src/client/common/types.ts +++ b/src/client/common/types.ts @@ -178,6 +178,7 @@ export interface IPythonSettings { readonly languageServerIsDefault: boolean; readonly defaultInterpreterPath: string; readonly tensorBoard: ITensorBoardSettings | undefined; + readonly REPL: IREPLSettings; register(): void; } @@ -197,6 +198,10 @@ export interface ITerminalSettings { readonly activateEnvInCurrentTerminal: boolean; } +export interface IREPLSettings { + readonly EnableREPLSmartSend: boolean; +} + export interface IExperiments { /** * Return `true` if experiments are enabled, else `false`. diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index 2f27c5f0cce5..ed03144eacb7 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -6,6 +6,7 @@ import { inject, injectable } from 'inversify'; import { l10n, Position, Range, TextEditor, Uri } from 'vscode'; import { + IActiveResourceService, IApplicationShell, ICommandManager, IDocumentManager, @@ -36,6 +37,8 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { private readonly commandManager: ICommandManager; + private activeResourceService: IActiveResourceService; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error TS6133: 'configSettings' is declared but its value is never read. private readonly configSettings: IConfigurationService; @@ -47,6 +50,7 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { this.interpreterService = serviceContainer.get(IInterpreterService); this.configSettings = serviceContainer.get(IConfigurationService); this.commandManager = serviceContainer.get(ICommandManager); + this.activeResourceService = this.serviceContainer.get(IActiveResourceService); } public async normalizeLines(code: string, wholeFileContent?: string, resource?: Uri): Promise { @@ -90,6 +94,9 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { const endLineVal = activeEditor?.selection?.end.line ?? 0; const emptyHighlightVal = activeEditor?.selection?.isEmpty ?? true; const smartSendExperimentEnabledVal = pythonSmartSendEnabled(this.serviceContainer); + const configuration = this.serviceContainer.get(IConfigurationService); + const pythonSettings = configuration.getSettings(this.activeResourceService.getActiveResource()); + const smartSendSettingsEnabledVal = pythonSettings.REPL.EnableREPLSmartSend; const input = JSON.stringify({ code, wholeFileContent, @@ -97,6 +104,7 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { endLine: endLineVal, emptyHighlight: emptyHighlightVal, smartSendExperimentEnabled: smartSendExperimentEnabledVal, + smartSendSettingsEnabled: smartSendSettingsEnabledVal, }); observable.proc?.stdin?.write(input); observable.proc?.stdin?.end(); diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 39b1d722fff4..ad38259be815 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -56,8 +56,9 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { Common.learnMore, ); } else { - await this.getTerminalService(resource).sendText(code); + // await this.getTerminalService(resource).sendText(code); } + await this.getTerminalService(resource).sendText(code); await this.initializeRepl(resource); } public async initializeRepl(resource: Resource) { From c5ced54787377b285ccb1a7ccb2b44c8b2fdcc53 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 26 Oct 2023 01:16:34 -0700 Subject: [PATCH 04/31] switch repl and code order to normal --- src/client/terminals/codeExecution/helper.ts | 8 ++++---- .../terminals/codeExecution/terminalCodeExecution.ts | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index ed03144eacb7..460e38e9b3dd 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -113,10 +113,10 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { const result = await normalizeOutput.promise; const object = JSON.parse(result); - // if (activeEditor?.selection) { - // const lineOffset = object.nextBlockLineno - activeEditor!.selection.start.line - 1; - // await this.moveToNextBlock(lineOffset, activeEditor); - // } + if (activeEditor?.selection) { + const lineOffset = object.nextBlockLineno - activeEditor!.selection.start.line - 1; + await this.moveToNextBlock(lineOffset, activeEditor); + } return parse(object.normalized); } catch (ex) { diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index ad38259be815..954b45833fb9 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -45,6 +45,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { if (!code || code.trim().length === 0) { return; } + await this.initializeRepl(resource); if (code == 'deprecated') { // If user is trying to smart send deprecated code show warning await showWarningMessage( @@ -56,10 +57,8 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { Common.learnMore, ); } else { - // await this.getTerminalService(resource).sendText(code); + await this.getTerminalService(resource).sendText(code); } - await this.getTerminalService(resource).sendText(code); - await this.initializeRepl(resource); } public async initializeRepl(resource: Resource) { const terminalService = this.getTerminalService(resource); From bc744337557a4d0b2e7ce0ce88c401bea1e813e4 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 26 Oct 2023 01:22:00 -0700 Subject: [PATCH 05/31] comply with linting error --- pythonFiles/normalizeSelection.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index eb696101cc36..ca6d97897735 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -3,22 +3,11 @@ import ast import json -import os -import pathlib import re import sys import textwrap from typing import Iterable -# script_dir = pathlib.Path( -# "User/anthonykim/Desktop/vscode-python/pythonFiles/lib/python" -# ) -# sys.path.append(os.fspath(script_dir)) -# import debugpy - -# debugpy.connect(5678) -# debugpy.breakpoint() - def split_lines(source): """ @@ -165,10 +154,9 @@ def traverse_file(wholeFileContent, start_line, end_line, was_highlighted): try: parsed_file_content = ast.parse(wholeFileContent) - except Exception as old_python_code: + except Exception: # Handle case where user is attempting to run code where file contains deprecated Python code. - # Somehow have to let typescript side know and show warning message. (TODO) - # print(old_python_code) + # Somehow have to let typescript side know and show warning message. return { "normalized_smart_result": "deprecated", "which_line_next": 0, From d0ad1fb9148274d6ed60af97386284ff1a11943c Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 13 Nov 2023 00:50:02 -0800 Subject: [PATCH 06/31] fix for test failing --- src/client/terminals/codeExecution/helper.ts | 10 ++++++++-- src/test/terminals/codeExecution/smartSend.test.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index 460e38e9b3dd..98a61f50c36d 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -94,9 +94,15 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { const endLineVal = activeEditor?.selection?.end.line ?? 0; const emptyHighlightVal = activeEditor?.selection?.isEmpty ?? true; const smartSendExperimentEnabledVal = pythonSmartSendEnabled(this.serviceContainer); + let smartSendSettingsEnabledVal = false; + const configuration = this.serviceContainer.get(IConfigurationService); - const pythonSettings = configuration.getSettings(this.activeResourceService.getActiveResource()); - const smartSendSettingsEnabledVal = pythonSettings.REPL.EnableREPLSmartSend; + if (configuration) { + const pythonSettings = configuration.getSettings(this.activeResourceService.getActiveResource()); + smartSendSettingsEnabledVal = pythonSettings.REPL.EnableREPLSmartSend; + } + // const pythonSettings = configuration.getSettings(this.activeResourceService.getActiveResource()); + // const smartSendSettingsEnabledVal = pythonSettings.REPL.EnableREPLSmartSend; const input = JSON.stringify({ code, wholeFileContent, diff --git a/src/test/terminals/codeExecution/smartSend.test.ts b/src/test/terminals/codeExecution/smartSend.test.ts index 8d70ab6e01e0..95a5aab64b3c 100644 --- a/src/test/terminals/codeExecution/smartSend.test.ts +++ b/src/test/terminals/codeExecution/smartSend.test.ts @@ -4,7 +4,12 @@ import { TextEditor, Selection, Position, TextDocument } from 'vscode'; import * as fs from 'fs-extra'; import { SemVer } from 'semver'; import { assert, expect } from 'chai'; -import { IApplicationShell, ICommandManager, IDocumentManager } from '../../../client/common/application/types'; +import { + IActiveResourceService, + IApplicationShell, + ICommandManager, + IDocumentManager, +} from '../../../client/common/application/types'; import { IProcessService, IProcessServiceFactory } from '../../../client/common/process/types'; import { IInterpreterService } from '../../../client/interpreter/contracts'; import { IConfigurationService, IExperimentService } from '../../../client/common/types'; @@ -35,6 +40,7 @@ suite('REPL - Smart Send', () => { let experimentService: TypeMoq.IMock; let processService: TypeMoq.IMock; + let activeResourceService: TypeMoq.IMock; let document: TypeMoq.IMock; const workingPython: PythonEnvironment = { @@ -64,6 +70,7 @@ suite('REPL - Smart Send', () => { serviceContainer = TypeMoq.Mock.ofType(); experimentService = TypeMoq.Mock.ofType(); processService = TypeMoq.Mock.ofType(); + activeResourceService = TypeMoq.Mock.ofType(); // eslint-disable-next-line @typescript-eslint/no-explicit-any processService.setup((x: any) => x.then).returns(() => undefined); From be70c447aca01e704c988abb539376090e4919b7 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 13 Nov 2023 00:52:33 -0800 Subject: [PATCH 07/31] comment out unused variables --- src/test/terminals/codeExecution/smartSend.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/terminals/codeExecution/smartSend.test.ts b/src/test/terminals/codeExecution/smartSend.test.ts index 95a5aab64b3c..d908825eadd0 100644 --- a/src/test/terminals/codeExecution/smartSend.test.ts +++ b/src/test/terminals/codeExecution/smartSend.test.ts @@ -5,7 +5,7 @@ import * as fs from 'fs-extra'; import { SemVer } from 'semver'; import { assert, expect } from 'chai'; import { - IActiveResourceService, + // IActiveResourceService, IApplicationShell, ICommandManager, IDocumentManager, @@ -40,7 +40,7 @@ suite('REPL - Smart Send', () => { let experimentService: TypeMoq.IMock; let processService: TypeMoq.IMock; - let activeResourceService: TypeMoq.IMock; + // let activeResourceService: TypeMoq.IMock; let document: TypeMoq.IMock; const workingPython: PythonEnvironment = { @@ -70,7 +70,7 @@ suite('REPL - Smart Send', () => { serviceContainer = TypeMoq.Mock.ofType(); experimentService = TypeMoq.Mock.ofType(); processService = TypeMoq.Mock.ofType(); - activeResourceService = TypeMoq.Mock.ofType(); + // activeResourceService = TypeMoq.Mock.ofType(); // eslint-disable-next-line @typescript-eslint/no-explicit-any processService.setup((x: any) => x.then).returns(() => undefined); From d0fd80d99473a0f1db3d1cfaeb02dac0b85e2358 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 13 Nov 2023 01:31:53 -0800 Subject: [PATCH 08/31] try adding configService and new REPL setting --- .../terminals/codeExecution/smartSend.test.ts | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/test/terminals/codeExecution/smartSend.test.ts b/src/test/terminals/codeExecution/smartSend.test.ts index d908825eadd0..e947a73a51bf 100644 --- a/src/test/terminals/codeExecution/smartSend.test.ts +++ b/src/test/terminals/codeExecution/smartSend.test.ts @@ -4,6 +4,7 @@ import { TextEditor, Selection, Position, TextDocument } from 'vscode'; import * as fs from 'fs-extra'; import { SemVer } from 'semver'; import { assert, expect } from 'chai'; +import { when } from 'ts-mockito'; import { // IActiveResourceService, IApplicationShell, @@ -12,7 +13,12 @@ import { } from '../../../client/common/application/types'; import { IProcessService, IProcessServiceFactory } from '../../../client/common/process/types'; import { IInterpreterService } from '../../../client/interpreter/contracts'; -import { IConfigurationService, IExperimentService } from '../../../client/common/types'; +import { + IConfigurationService, + IExperimentService, + IPythonSettings, + IREPLSettings, +} from '../../../client/common/types'; import { CodeExecutionHelper } from '../../../client/terminals/codeExecution/helper'; import { IServiceContainer } from '../../../client/ioc/types'; import { ICodeExecutionHelper } from '../../../client/terminals/types'; @@ -22,6 +28,7 @@ import { EnvironmentType, PythonEnvironment } from '../../../client/pythonEnviro import { PYTHON_PATH } from '../../common'; import { Architecture } from '../../../client/common/utils/platform'; import { ProcessService } from '../../../client/common/process/proc'; +import { PythonSettings } from '../../../client/common/configSettings'; const TEST_FILES_PATH = path.join(EXTENSION_ROOT_DIR, 'src', 'test', 'pythonFiles', 'terminalExec'); @@ -155,7 +162,28 @@ suite('REPL - Smart Send', () => { experimentService .setup((exp) => exp.inExperimentSync(TypeMoq.It.isValue(EnableREPLSmartSend.experiment))) .returns(() => true); - + // const settings = TypeMoq.Mock.ofType(); + // configurationService.setup((c) => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.); + configurationService + .setup((c) => c.getSettings(TypeMoq.It.isAny())) + .returns({ + REPL: { + EnableREPLSmartSend: true, + REPLSmartSend: true, + }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any); + // when(configurationService.getSettings()).thenReturn({ + // experiments: { + // enabled: false, + // optInto: [], + // optOutFrom: [], + // }, + // initialize: true, + // venvPath: 'path', + // pipenvPath: 'pipenv', + // // eslint-disable-next-line @typescript-eslint/no-explicit-any + // } as any); const activeEditor = TypeMoq.Mock.ofType(); const firstIndexPosition = new Position(0, 0); const selection = TypeMoq.Mock.ofType(); From 59805adf23741393aedf1e305f7e6814e6149ac2 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 13 Nov 2023 01:33:43 -0800 Subject: [PATCH 09/31] quit unused var warning --- src/test/terminals/codeExecution/smartSend.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/terminals/codeExecution/smartSend.test.ts b/src/test/terminals/codeExecution/smartSend.test.ts index e947a73a51bf..477820611adb 100644 --- a/src/test/terminals/codeExecution/smartSend.test.ts +++ b/src/test/terminals/codeExecution/smartSend.test.ts @@ -4,7 +4,7 @@ import { TextEditor, Selection, Position, TextDocument } from 'vscode'; import * as fs from 'fs-extra'; import { SemVer } from 'semver'; import { assert, expect } from 'chai'; -import { when } from 'ts-mockito'; +// import { when } from 'ts-mockito'; import { // IActiveResourceService, IApplicationShell, @@ -16,8 +16,8 @@ import { IInterpreterService } from '../../../client/interpreter/contracts'; import { IConfigurationService, IExperimentService, - IPythonSettings, - IREPLSettings, + // IPythonSettings, + // IREPLSettings, } from '../../../client/common/types'; import { CodeExecutionHelper } from '../../../client/terminals/codeExecution/helper'; import { IServiceContainer } from '../../../client/ioc/types'; @@ -28,7 +28,7 @@ import { EnvironmentType, PythonEnvironment } from '../../../client/pythonEnviro import { PYTHON_PATH } from '../../common'; import { Architecture } from '../../../client/common/utils/platform'; import { ProcessService } from '../../../client/common/process/proc'; -import { PythonSettings } from '../../../client/common/configSettings'; +// import { PythonSettings } from '../../../client/common/configSettings'; const TEST_FILES_PATH = path.join(EXTENSION_ROOT_DIR, 'src', 'test', 'pythonFiles', 'terminalExec'); From d911459b6566e114640c06ccedb2a95e978db11d Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 13 Nov 2023 02:27:24 -0800 Subject: [PATCH 10/31] add activeResourceService --- .../terminals/codeExecution/smartSend.test.ts | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/test/terminals/codeExecution/smartSend.test.ts b/src/test/terminals/codeExecution/smartSend.test.ts index 477820611adb..3db0d6b93f29 100644 --- a/src/test/terminals/codeExecution/smartSend.test.ts +++ b/src/test/terminals/codeExecution/smartSend.test.ts @@ -1,12 +1,12 @@ import * as TypeMoq from 'typemoq'; import * as path from 'path'; -import { TextEditor, Selection, Position, TextDocument } from 'vscode'; +import { TextEditor, Selection, Position, TextDocument, Uri } from 'vscode'; import * as fs from 'fs-extra'; import { SemVer } from 'semver'; import { assert, expect } from 'chai'; // import { when } from 'ts-mockito'; import { - // IActiveResourceService, + IActiveResourceService, IApplicationShell, ICommandManager, IDocumentManager, @@ -16,6 +16,7 @@ import { IInterpreterService } from '../../../client/interpreter/contracts'; import { IConfigurationService, IExperimentService, + IPythonSettings, // IPythonSettings, // IREPLSettings, } from '../../../client/common/types'; @@ -47,9 +48,11 @@ suite('REPL - Smart Send', () => { let experimentService: TypeMoq.IMock; let processService: TypeMoq.IMock; - // let activeResourceService: TypeMoq.IMock; + let activeResourceService: TypeMoq.IMock; let document: TypeMoq.IMock; + let pythonSettings: TypeMoq.IMock; + const workingPython: PythonEnvironment = { path: PYTHON_PATH, version: new SemVer('3.6.6-final'), @@ -77,8 +80,9 @@ suite('REPL - Smart Send', () => { serviceContainer = TypeMoq.Mock.ofType(); experimentService = TypeMoq.Mock.ofType(); processService = TypeMoq.Mock.ofType(); - // activeResourceService = TypeMoq.Mock.ofType(); - + activeResourceService = TypeMoq.Mock.ofType(); + pythonSettings = TypeMoq.Mock.ofType(); + const resource = Uri.parse('a'); // eslint-disable-next-line @typescript-eslint/no-explicit-any processService.setup((x: any) => x.then).returns(() => undefined); serviceContainer @@ -106,6 +110,14 @@ suite('REPL - Smart Send', () => { interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) .returns(() => Promise.resolve(workingPython)); + serviceContainer + .setup((c) => c.get(TypeMoq.It.isValue(IActiveResourceService))) + .returns(() => activeResourceService.object); + activeResourceService.setup((a) => a.getActiveResource()).returns(() => resource); + + pythonSettings.setup((s) => s.REPL).returns(() => ({ EnableREPLSmartSend: true, REPLSmartSend: true })); + + configurationService.setup((x) => x.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object); codeExecutionHelper = new CodeExecutionHelper(serviceContainer.object); document = TypeMoq.Mock.ofType(); @@ -162,8 +174,8 @@ suite('REPL - Smart Send', () => { experimentService .setup((exp) => exp.inExperimentSync(TypeMoq.It.isValue(EnableREPLSmartSend.experiment))) .returns(() => true); - // const settings = TypeMoq.Mock.ofType(); - // configurationService.setup((c) => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.); + // const settings = TypeMoq.Mock.ofType(); + // configurationService.setup((c) => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.object); configurationService .setup((c) => c.getSettings(TypeMoq.It.isAny())) .returns({ From a29ecdd5368f2449b13e349820b1817e2b9b505f Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 13 Nov 2023 14:27:37 -0800 Subject: [PATCH 11/31] clean up --- pythonFiles/normalizeSelection.py | 2 +- src/client/terminals/codeExecution/helper.ts | 4 +-- .../codeExecution/terminalCodeExecution.ts | 8 +++--- .../terminals/codeExecution/smartSend.test.ts | 25 +++---------------- 4 files changed, 8 insertions(+), 31 deletions(-) diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index ca6d97897735..3131b1dae590 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -156,7 +156,7 @@ def traverse_file(wholeFileContent, start_line, end_line, was_highlighted): parsed_file_content = ast.parse(wholeFileContent) except Exception: # Handle case where user is attempting to run code where file contains deprecated Python code. - # Somehow have to let typescript side know and show warning message. + # Let typescript side know and show warning message. return { "normalized_smart_result": "deprecated", "which_line_next": 0, diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index 98a61f50c36d..88417a2c9243 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -95,14 +95,12 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { const emptyHighlightVal = activeEditor?.selection?.isEmpty ?? true; const smartSendExperimentEnabledVal = pythonSmartSendEnabled(this.serviceContainer); let smartSendSettingsEnabledVal = false; - const configuration = this.serviceContainer.get(IConfigurationService); if (configuration) { const pythonSettings = configuration.getSettings(this.activeResourceService.getActiveResource()); smartSendSettingsEnabledVal = pythonSettings.REPL.EnableREPLSmartSend; } - // const pythonSettings = configuration.getSettings(this.activeResourceService.getActiveResource()); - // const smartSendSettingsEnabledVal = pythonSettings.REPL.EnableREPLSmartSend; + const input = JSON.stringify({ code, wholeFileContent, diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 954b45833fb9..2a11618f03da 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -12,7 +12,6 @@ import '../../common/extensions'; import { IPlatformService } from '../../common/platform/types'; import { ITerminalService, ITerminalServiceFactory } from '../../common/terminal/types'; import { IConfigurationService, IDisposableRegistry, Resource } from '../../common/types'; -import { Common } from '../../common/utils/localize'; import { showWarningMessage } from '../../common/vscodeApis/windowApis'; import { IInterpreterService } from '../../interpreter/contracts'; import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec'; @@ -50,11 +49,10 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { // If user is trying to smart send deprecated code show warning await showWarningMessage( l10n.t( - `You are attempting to run Smart Send on Python file with deprecated code, please - turn off smart send if you wish to always run line by line or explicitly select code - to force run [logs](command:${Commands.ViewOutput}) for more details.`, + `You are attempting to run Smart Send on Python file with deprecated Python code, please + turn off Smart Send if you wish to always run line by line or explicitly select code + to force run. [logs](command:${Commands.ViewOutput}) for more details.`, ), - Common.learnMore, ); } else { await this.getTerminalService(resource).sendText(code); diff --git a/src/test/terminals/codeExecution/smartSend.test.ts b/src/test/terminals/codeExecution/smartSend.test.ts index 3db0d6b93f29..de594033cd6c 100644 --- a/src/test/terminals/codeExecution/smartSend.test.ts +++ b/src/test/terminals/codeExecution/smartSend.test.ts @@ -4,7 +4,6 @@ import { TextEditor, Selection, Position, TextDocument, Uri } from 'vscode'; import * as fs from 'fs-extra'; import { SemVer } from 'semver'; import { assert, expect } from 'chai'; -// import { when } from 'ts-mockito'; import { IActiveResourceService, IApplicationShell, @@ -13,13 +12,7 @@ import { } from '../../../client/common/application/types'; import { IProcessService, IProcessServiceFactory } from '../../../client/common/process/types'; import { IInterpreterService } from '../../../client/interpreter/contracts'; -import { - IConfigurationService, - IExperimentService, - IPythonSettings, - // IPythonSettings, - // IREPLSettings, -} from '../../../client/common/types'; +import { IConfigurationService, IExperimentService, IPythonSettings } from '../../../client/common/types'; import { CodeExecutionHelper } from '../../../client/terminals/codeExecution/helper'; import { IServiceContainer } from '../../../client/ioc/types'; import { ICodeExecutionHelper } from '../../../client/terminals/types'; @@ -29,7 +22,6 @@ import { EnvironmentType, PythonEnvironment } from '../../../client/pythonEnviro import { PYTHON_PATH } from '../../common'; import { Architecture } from '../../../client/common/utils/platform'; import { ProcessService } from '../../../client/common/process/proc'; -// import { PythonSettings } from '../../../client/common/configSettings'; const TEST_FILES_PATH = path.join(EXTENSION_ROOT_DIR, 'src', 'test', 'pythonFiles', 'terminalExec'); @@ -174,8 +166,7 @@ suite('REPL - Smart Send', () => { experimentService .setup((exp) => exp.inExperimentSync(TypeMoq.It.isValue(EnableREPLSmartSend.experiment))) .returns(() => true); - // const settings = TypeMoq.Mock.ofType(); - // configurationService.setup((c) => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.object); + configurationService .setup((c) => c.getSettings(TypeMoq.It.isAny())) .returns({ @@ -185,17 +176,7 @@ suite('REPL - Smart Send', () => { }, // eslint-disable-next-line @typescript-eslint/no-explicit-any } as any); - // when(configurationService.getSettings()).thenReturn({ - // experiments: { - // enabled: false, - // optInto: [], - // optOutFrom: [], - // }, - // initialize: true, - // venvPath: 'path', - // pipenvPath: 'pipenv', - // // eslint-disable-next-line @typescript-eslint/no-explicit-any - // } as any); + const activeEditor = TypeMoq.Mock.ofType(); const firstIndexPosition = new Position(0, 0); const selection = TypeMoq.Mock.ofType(); From 924f9e8ef906114bd1dea181b205e21741d278ab Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 14 Nov 2023 13:21:09 -0800 Subject: [PATCH 12/31] respect deprecated --- pythonFiles/normalizeSelection.py | 9 ++++++--- src/client/terminals/codeExecution/helper.ts | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index 3131b1dae590..7608ce8860f6 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -290,9 +290,12 @@ def get_next_block_lineno(which_line_next): ) normalized = result["normalized_smart_result"] which_line_next = result["which_line_next"] - data = json.dumps( - {"normalized": normalized, "nextBlockLineno": result["which_line_next"]} - ) + if normalized == "deprecated": + data = json.dumps({"normalized": normalized}) + else: + data = json.dumps( + {"normalized": normalized, "nextBlockLineno": result["which_line_next"]} + ) else: normalized = normalize_lines(contents["code"]) data = json.dumps({"normalized": normalized}) diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index 88417a2c9243..43e3fbedd8d4 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -117,7 +117,12 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { const result = await normalizeOutput.promise; const object = JSON.parse(result); - if (activeEditor?.selection) { + if ( + activeEditor?.selection && + smartSendExperimentEnabledVal && + smartSendSettingsEnabledVal && + object.normalized !== 'deprecated' + ) { const lineOffset = object.nextBlockLineno - activeEditor!.selection.start.line - 1; await this.moveToNextBlock(lineOffset, activeEditor); } From fe80e9364fb4c1b7fe9a0694f149babb67e5d250 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 14 Nov 2023 13:58:39 -0800 Subject: [PATCH 13/31] make a button that leed to change setting --- .../terminals/codeExecution/terminalCodeExecution.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 2a11618f03da..5650c3682a71 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -16,7 +16,7 @@ import { showWarningMessage } from '../../common/vscodeApis/windowApis'; import { IInterpreterService } from '../../interpreter/contracts'; import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec'; import { ICodeExecutionService } from '../../terminals/types'; - +import * as vscode from 'vscode'; @injectable() export class TerminalCodeExecutionProvider implements ICodeExecutionService { private hasRanOutsideCurrentDrive = false; @@ -47,13 +47,17 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { await this.initializeRepl(resource); if (code == 'deprecated') { // If user is trying to smart send deprecated code show warning - await showWarningMessage( + const selection = await showWarningMessage( l10n.t( `You are attempting to run Smart Send on Python file with deprecated Python code, please turn off Smart Send if you wish to always run line by line or explicitly select code to force run. [logs](command:${Commands.ViewOutput}) for more details.`, ), + 'Change Settings', ); + if (selection === 'Change Settings') { + vscode.commands.executeCommand('workbench.action.openSettings', 'python.REPL.EnableREPLSmartSend'); + } } else { await this.getTerminalService(resource).sendText(code); } From e23c5043f2f7e889f35d4575fbe36c415d475e97 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 14 Nov 2023 15:00:51 -0800 Subject: [PATCH 14/31] Change message wording --- src/client/terminals/codeExecution/terminalCodeExecution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 5650c3682a71..686c3b507ef9 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -49,7 +49,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { // If user is trying to smart send deprecated code show warning const selection = await showWarningMessage( l10n.t( - `You are attempting to run Smart Send on Python file with deprecated Python code, please + `Python AST cannot parse invalid code provided in the current file, please turn off Smart Send if you wish to always run line by line or explicitly select code to force run. [logs](command:${Commands.ViewOutput}) for more details.`, ), From f6f8a4a1246a161d95c1a1360ed94a88e432887a Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 14 Nov 2023 15:23:58 -0800 Subject: [PATCH 15/31] Change wording --- src/client/terminals/codeExecution/terminalCodeExecution.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 686c3b507ef9..783308bb11af 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -49,13 +49,13 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { // If user is trying to smart send deprecated code show warning const selection = await showWarningMessage( l10n.t( - `Python AST cannot parse invalid code provided in the current file, please + `Python is unable to parse the code provided. Please turn off Smart Send if you wish to always run line by line or explicitly select code to force run. [logs](command:${Commands.ViewOutput}) for more details.`, ), - 'Change Settings', + 'Switch to line-by-line', ); - if (selection === 'Change Settings') { + if (selection === 'Switch to line-by-line') { vscode.commands.executeCommand('workbench.action.openSettings', 'python.REPL.EnableREPLSmartSend'); } } else { From 91ffe6449de94eb3ebf7e84c6c9cebd2675495b0 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 15 Nov 2023 10:45:45 -0800 Subject: [PATCH 16/31] use commandManager rather than calling vs code --- src/client/common/application/commands.ts | 1 + src/client/terminals/codeExecution/terminalCodeExecution.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/client/common/application/commands.ts b/src/client/common/application/commands.ts index ba29f0dcd956..51afbdc951b8 100644 --- a/src/client/common/application/commands.ts +++ b/src/client/common/application/commands.ts @@ -72,6 +72,7 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu ]; ['workbench.action.files.openFolder']: []; ['workbench.action.openWorkspace']: []; + ['workbench.action.openSettings']: [string]; ['setContext']: [string, boolean] | ['python.vscode.channel', Channel]; ['python.reloadVSCode']: [string]; ['revealLine']: [{ lineNumber: number; at: 'top' | 'center' | 'bottom' }]; diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 783308bb11af..416fa37e10b5 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -6,7 +6,7 @@ import { inject, injectable } from 'inversify'; import * as path from 'path'; import { Disposable, l10n, Uri } from 'vscode'; -import { IWorkspaceService } from '../../common/application/types'; +import { ICommandManager, IWorkspaceService } from '../../common/application/types'; import { Commands } from '../../common/constants'; import '../../common/extensions'; import { IPlatformService } from '../../common/platform/types'; @@ -16,7 +16,6 @@ import { showWarningMessage } from '../../common/vscodeApis/windowApis'; import { IInterpreterService } from '../../interpreter/contracts'; import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec'; import { ICodeExecutionService } from '../../terminals/types'; -import * as vscode from 'vscode'; @injectable() export class TerminalCodeExecutionProvider implements ICodeExecutionService { private hasRanOutsideCurrentDrive = false; @@ -29,6 +28,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { @inject(IDisposableRegistry) protected readonly disposables: Disposable[], @inject(IPlatformService) protected readonly platformService: IPlatformService, @inject(IInterpreterService) protected readonly interpreterService: IInterpreterService, + @inject(ICommandManager) protected readonly commandManager: ICommandManager, ) {} public async executeFile(file: Uri, options?: { newTerminalPerFile: boolean }) { @@ -56,7 +56,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { 'Switch to line-by-line', ); if (selection === 'Switch to line-by-line') { - vscode.commands.executeCommand('workbench.action.openSettings', 'python.REPL.EnableREPLSmartSend'); + this.commandManager.executeCommand('workbench.action.openSettings', 'python.REPL.EnableREPLSmartSend'); } } else { await this.getTerminalService(resource).sendText(code); From 93ab499bb6c7f7d5d6dc40ad2740c377a58e078a Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 15 Nov 2023 11:00:54 -0800 Subject: [PATCH 17/31] add commandManager --- .../terminals/codeExecution/djangoShellCodeExecution.ts | 1 + src/client/terminals/codeExecution/repl.ts | 4 +++- .../terminals/codeExecution/terminalCodeExec.unit.test.ts | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/client/terminals/codeExecution/djangoShellCodeExecution.ts b/src/client/terminals/codeExecution/djangoShellCodeExecution.ts index c70cd896b225..67b877429a2e 100644 --- a/src/client/terminals/codeExecution/djangoShellCodeExecution.ts +++ b/src/client/terminals/codeExecution/djangoShellCodeExecution.ts @@ -36,6 +36,7 @@ export class DjangoShellCodeExecutionProvider extends TerminalCodeExecutionProvi disposableRegistry, platformService, interpreterService, + commandManager, ); this.terminalTitle = 'Django Shell'; disposableRegistry.push(new DjangoContextInitializer(documentManager, workspace, fileSystem, commandManager)); diff --git a/src/client/terminals/codeExecution/repl.ts b/src/client/terminals/codeExecution/repl.ts index e3a4bc7582c2..45f19798c3d8 100644 --- a/src/client/terminals/codeExecution/repl.ts +++ b/src/client/terminals/codeExecution/repl.ts @@ -5,7 +5,7 @@ import { inject, injectable } from 'inversify'; import { Disposable } from 'vscode'; -import { IWorkspaceService } from '../../common/application/types'; +import { ICommandManager, IWorkspaceService } from '../../common/application/types'; import { IPlatformService } from '../../common/platform/types'; import { ITerminalServiceFactory } from '../../common/terminal/types'; import { IConfigurationService, IDisposableRegistry } from '../../common/types'; @@ -21,6 +21,7 @@ export class ReplProvider extends TerminalCodeExecutionProvider { @inject(IDisposableRegistry) disposableRegistry: Disposable[], @inject(IPlatformService) platformService: IPlatformService, @inject(IInterpreterService) interpreterService: IInterpreterService, + @inject(ICommandManager) commandManager: ICommandManager, ) { super( terminalServiceFactory, @@ -29,6 +30,7 @@ export class ReplProvider extends TerminalCodeExecutionProvider { disposableRegistry, platformService, interpreterService, + commandManager, ); this.terminalTitle = 'REPL'; } diff --git a/src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts b/src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts index 9523f35a1040..93845e6189eb 100644 --- a/src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts +++ b/src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts @@ -84,6 +84,7 @@ suite('Terminal - Code Execution', () => { disposables, platform.object, interpreterService.object, + commandManager.object, ); break; } @@ -95,6 +96,7 @@ suite('Terminal - Code Execution', () => { disposables, platform.object, interpreterService.object, + commandManager.object, ); expectedTerminalTitle = 'REPL'; break; From 972f144542779ac9dd12f2b4d0a062b3b9db9035 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 15 Nov 2023 11:14:06 -0800 Subject: [PATCH 18/31] remove systemVariable resolve --- src/client/common/configSettings.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/common/configSettings.ts b/src/client/common/configSettings.ts index dfb153fdb909..88a5007467bb 100644 --- a/src/client/common/configSettings.ts +++ b/src/client/common/configSettings.ts @@ -366,8 +366,8 @@ export class PythonSettings implements IPythonSettings { activateEnvInCurrentTerminal: false, }; - this.REPL = systemVariables.resolveAny(pythonSettings.get('REPL'))!; - const experiments = systemVariables.resolveAny(pythonSettings.get('experiments'))!; + this.REPL = pythonSettings.get('REPL')!; + const experiments = pythonSettings.get('experiments')!; if (this.experiments) { Object.assign(this.experiments, experiments); } else { From 05d4e7f27cfc6d33c9a7a0421bf59d6489a0d9e1 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 15 Nov 2023 15:47:01 -0800 Subject: [PATCH 19/31] add warning message test --- .../sample_invalid_smart_selection.py | 10 ++++ .../terminals/codeExecution/smartSend.test.ts | 57 ++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/test/pythonFiles/terminalExec/sample_invalid_smart_selection.py diff --git a/src/test/pythonFiles/terminalExec/sample_invalid_smart_selection.py b/src/test/pythonFiles/terminalExec/sample_invalid_smart_selection.py new file mode 100644 index 000000000000..73d9e0fba066 --- /dev/null +++ b/src/test/pythonFiles/terminalExec/sample_invalid_smart_selection.py @@ -0,0 +1,10 @@ +def beliebig(x, y, *mehr): + print "x=", x, ", x=", y + print "mehr: ", mehr + +list = [ +1, +2, +3, +] +print("Above is invalid");print("deprecated");print("show warning") diff --git a/src/test/terminals/codeExecution/smartSend.test.ts b/src/test/terminals/codeExecution/smartSend.test.ts index de594033cd6c..3eb79ac6b950 100644 --- a/src/test/terminals/codeExecution/smartSend.test.ts +++ b/src/test/terminals/codeExecution/smartSend.test.ts @@ -17,11 +17,12 @@ import { CodeExecutionHelper } from '../../../client/terminals/codeExecution/hel import { IServiceContainer } from '../../../client/ioc/types'; import { ICodeExecutionHelper } from '../../../client/terminals/types'; import { EnableREPLSmartSend } from '../../../client/common/experiments/groups'; -import { EXTENSION_ROOT_DIR } from '../../../client/common/constants'; +import { Commands, EXTENSION_ROOT_DIR } from '../../../client/common/constants'; import { EnvironmentType, PythonEnvironment } from '../../../client/pythonEnvironments/info'; import { PYTHON_PATH } from '../../common'; import { Architecture } from '../../../client/common/utils/platform'; import { ProcessService } from '../../../client/common/process/proc'; +import { l10n } from '../../mocks/vsc'; const TEST_FILES_PATH = path.join(EXTENSION_ROOT_DIR, 'src', 'test', 'pythonFiles', 'terminalExec'); @@ -254,4 +255,58 @@ suite('REPL - Smart Send', () => { const expectedNonSmartResult = 'my_dict = {\n\n'; // Standard for previous normalization logic expect(actualNonSmartResult).to.be.equal(expectedNonSmartResult); }); + + test('Smart Send should provide warning when code is not valid', async () => { + experimentService + .setup((exp) => exp.inExperimentSync(TypeMoq.It.isValue(EnableREPLSmartSend.experiment))) + .returns(() => true); + + configurationService + .setup((c) => c.getSettings(TypeMoq.It.isAny())) + .returns({ + REPL: { + EnableREPLSmartSend: true, + REPLSmartSend: true, + }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any); + + const activeEditor = TypeMoq.Mock.ofType(); + const firstIndexPosition = new Position(0, 0); + const selection = TypeMoq.Mock.ofType(); + const wholeFileContent = await fs.readFile( + path.join(TEST_FILES_PATH, `sample_invalid_smart_selection.py`), + 'utf8', + ); + + selection.setup((s) => s.anchor).returns(() => firstIndexPosition); + selection.setup((s) => s.active).returns(() => firstIndexPosition); + selection.setup((s) => s.isEmpty).returns(() => true); + activeEditor.setup((e) => e.selection).returns(() => selection.object); + + documentManager.setup((d) => d.activeTextEditor).returns(() => activeEditor.object); + document.setup((d) => d.getText(TypeMoq.It.isAny())).returns(() => wholeFileContent); + const actualProcessService = new ProcessService(); + + const { execObservable } = actualProcessService; + + processService + .setup((p) => p.execObservable(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())) + .returns((file, args, options) => execObservable.apply(actualProcessService, [file, args, options])); + + await codeExecutionHelper.normalizeLines('my_dict = {', wholeFileContent); + + applicationShell + .setup((a) => + a.showWarningMessage( + l10n.t( + `Python is unable to parse the code provided. Please + turn off Smart Send if you wish to always run line by line or explicitly select code + to force run. [logs](command:${Commands.ViewOutput}) for more details.`, + ), + 'Switch to line-by-line', + ), + ) + .verifiable(TypeMoq.Times.once()); + }); }); From 4ebc50230396068ea6dbfe2ffd418f95e9fbed5b Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 16 Nov 2023 10:34:32 -0800 Subject: [PATCH 20/31] fix typo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cc9cfa120fa7..92d7361fa866 100644 --- a/package.json +++ b/package.json @@ -699,7 +699,7 @@ "scope": "resource", "type": "array" }, - "python.REPL.EnableREPLSmartSend": { + "python.REPL.EnableREPL SmartSend": { "default": true, "description": "%python.EnableREPLSmartSend.description%", "scope": "resource", From 9283d808e141f302f17380abe62192148d1dddcc Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 16 Nov 2023 10:50:21 -0800 Subject: [PATCH 21/31] fix smoke test error --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 92d7361fa866..cc9cfa120fa7 100644 --- a/package.json +++ b/package.json @@ -699,7 +699,7 @@ "scope": "resource", "type": "array" }, - "python.REPL.EnableREPL SmartSend": { + "python.REPL.EnableREPLSmartSend": { "default": true, "description": "%python.EnableREPLSmartSend.description%", "scope": "resource", From 4682545edfd76cc2662d63970f6a6b1866fca072 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 16 Nov 2023 11:29:39 -0800 Subject: [PATCH 22/31] button will actually change setting --- src/client/terminals/codeExecution/terminalCodeExecution.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 416fa37e10b5..eb189c002b09 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -56,7 +56,8 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { 'Switch to line-by-line', ); if (selection === 'Switch to line-by-line') { - this.commandManager.executeCommand('workbench.action.openSettings', 'python.REPL.EnableREPLSmartSend'); + // this.commandManager.executeCommand('workbench.action.openSettings', 'python.REPL.EnableREPLSmartSend'); + this.configurationService.updateSetting('REPL.EnableREPLSmartSend', false, resource); } } else { await this.getTerminalService(resource).sendText(code); From d3efb7cd7755475a93f036ed4af2becee0c64137 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 16 Nov 2023 12:25:02 -0800 Subject: [PATCH 23/31] Update description according to suggestion --- package.nls.json | 2 +- src/client/terminals/codeExecution/terminalCodeExecution.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.nls.json b/package.nls.json index 9990f15ff84d..08ba732d8348 100644 --- a/package.nls.json +++ b/package.nls.json @@ -58,7 +58,7 @@ "python.missingPackage.severity.description": "Set severity of missing packages in requirements.txt or pyproject.toml", "python.pipenvPath.description": "Path to the pipenv executable to use for activation.", "python.poetryPath.description": "Path to the poetry executable.", - "python.EnableREPLSmartSend.description": "Toggle smart send for the Python REPL.", + "python.EnableREPLSmartSend.description": "Toggle Smart Send for the Python REPL. Smart Send enables sending the smallest runnable block of code to the REPL on Shift+Enter and moves the cursor accordingly.", "python.tensorBoard.logDirectory.description": "Set this setting to your preferred TensorBoard log directory to skip log directory prompt when starting TensorBoard.", "python.tensorBoard.logDirectory.markdownDeprecationMessage": "Tensorboard support has been moved to the extension [Tensorboard extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.tensorboard). Instead use the setting `tensorBoard.logDirectory`.", "python.tensorBoard.logDirectory.deprecationMessage": "Tensorboard support has been moved to the extension Tensorboard extension. Instead use the setting `tensorBoard.logDirectory`.", diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index eb189c002b09..0b66d080ac99 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -50,7 +50,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { const selection = await showWarningMessage( l10n.t( `Python is unable to parse the code provided. Please - turn off Smart Send if you wish to always run line by line or explicitly select code + turn off Smart Send if you wish to run code line by line or explicitly select code to force run. [logs](command:${Commands.ViewOutput}) for more details.`, ), 'Switch to line-by-line', From f4deb6203d1f8a1eb1bbf9f14e5a0692ce35fb2e Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 16 Nov 2023 12:41:34 -0800 Subject: [PATCH 24/31] add traceInfo message --- src/client/terminals/codeExecution/terminalCodeExecution.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 0b66d080ac99..4cdde04424f6 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -14,6 +14,7 @@ import { ITerminalService, ITerminalServiceFactory } from '../../common/terminal import { IConfigurationService, IDisposableRegistry, Resource } from '../../common/types'; import { showWarningMessage } from '../../common/vscodeApis/windowApis'; import { IInterpreterService } from '../../interpreter/contracts'; +import { traceInfo } from '../../logging'; import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec'; import { ICodeExecutionService } from '../../terminals/types'; @injectable() @@ -55,6 +56,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { ), 'Switch to line-by-line', ); + traceInfo(`Selected file contains invalid Python or Deprecated Python 2 code`); if (selection === 'Switch to line-by-line') { // this.commandManager.executeCommand('workbench.action.openSettings', 'python.REPL.EnableREPLSmartSend'); this.configurationService.updateSetting('REPL.EnableREPLSmartSend', false, resource); From 4ba135fd118837d510ed79ea8ac689a1a880aa80 Mon Sep 17 00:00:00 2001 From: Anthony Kim <62267334+anthonykim1@users.noreply.github.com> Date: Fri, 17 Nov 2023 12:50:53 -0800 Subject: [PATCH 25/31] Update src/client/terminals/codeExecution/terminalCodeExecution.ts Co-authored-by: Courtney Webster <60238438+cwebster-99@users.noreply.github.com> --- src/client/terminals/codeExecution/terminalCodeExecution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 4cdde04424f6..9175f6231fd3 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -54,7 +54,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { turn off Smart Send if you wish to run code line by line or explicitly select code to force run. [logs](command:${Commands.ViewOutput}) for more details.`, ), - 'Switch to line-by-line', + 'Disable Smart Send', ); traceInfo(`Selected file contains invalid Python or Deprecated Python 2 code`); if (selection === 'Switch to line-by-line') { From 1794700b6801f21f89b3d042d0d06791a7ff5894 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 17 Nov 2023 12:52:08 -0800 Subject: [PATCH 26/31] touch up on warning message --- src/client/terminals/codeExecution/terminalCodeExecution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 9175f6231fd3..9749661815a0 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -52,7 +52,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { l10n.t( `Python is unable to parse the code provided. Please turn off Smart Send if you wish to run code line by line or explicitly select code - to force run. [logs](command:${Commands.ViewOutput}) for more details.`, + to force run. [Logs](command:${Commands.ViewOutput}) for more details.`, ), 'Disable Smart Send', ); From 13eeb8091a0ef6cb54eaab9a0c704a92daad5581 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 17 Nov 2023 12:54:33 -0800 Subject: [PATCH 27/31] check condition on Disable button --- src/client/terminals/codeExecution/terminalCodeExecution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 9749661815a0..d5f9442911bd 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -57,7 +57,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { 'Disable Smart Send', ); traceInfo(`Selected file contains invalid Python or Deprecated Python 2 code`); - if (selection === 'Switch to line-by-line') { + if (selection === 'Disable Smart Send') { // this.commandManager.executeCommand('workbench.action.openSettings', 'python.REPL.EnableREPLSmartSend'); this.configurationService.updateSetting('REPL.EnableREPLSmartSend', false, resource); } From 4fc035752bec4076aca1b5c3d696a924caa53a32 Mon Sep 17 00:00:00 2001 From: Anthony Kim <62267334+anthonykim1@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:29:28 -0800 Subject: [PATCH 28/31] Update src/client/terminals/codeExecution/terminalCodeExecution.ts Co-authored-by: Kartik Raj --- src/client/terminals/codeExecution/terminalCodeExecution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index d5f9442911bd..083081c6e561 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -52,7 +52,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { l10n.t( `Python is unable to parse the code provided. Please turn off Smart Send if you wish to run code line by line or explicitly select code - to force run. [Logs](command:${Commands.ViewOutput}) for more details.`, + to force run. See [logs](command:${Commands.ViewOutput}) for more details.`, ), 'Disable Smart Send', ); From 956ee207f83110ea6af205e4b0b7e5c8745fccba Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 17 Nov 2023 14:12:19 -0800 Subject: [PATCH 29/31] put message and button in localize --- src/client/common/utils/localize.ts | 7 +++++++ .../codeExecution/terminalCodeExecution.ts | 16 ++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/client/common/utils/localize.ts b/src/client/common/utils/localize.ts index 95252b361c76..dc5e8cda3134 100644 --- a/src/client/common/utils/localize.ts +++ b/src/client/common/utils/localize.ts @@ -4,6 +4,7 @@ 'use strict'; import { l10n } from 'vscode'; +import { Commands } from '../constants'; /* eslint-disable @typescript-eslint/no-namespace, no-shadow */ @@ -42,6 +43,9 @@ export namespace Diagnostics { export const pylanceDefaultMessage = l10n.t( "The Python extension now includes Pylance to improve completions, code navigation, overall performance and much more! You can learn more about the update and learn how to change your language server [here](https://aka.ms/new-python-bundle).\n\nRead Pylance's license [here](https://marketplace.visualstudio.com/items/ms-python.vscode-pylance/license).", ); + export const invalidSmartSendMessage = l10n.t(`Python is unable to parse the code provided. Please + turn off Smart Send if you wish to always run line by line or explicitly select code + to force run. See [logs](command:${Commands.ViewOutput}) for more details`); } export namespace Common { @@ -92,6 +96,9 @@ export namespace AttachProcess { export const refreshList = l10n.t('Refresh process list'); } +export namespace Repl { + export const disableSmartSend = l10n.t('Disable Smart Send'); +} export namespace Pylance { export const remindMeLater = l10n.t('Remind me later'); diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 083081c6e561..6482c80060dc 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -5,13 +5,13 @@ import { inject, injectable } from 'inversify'; import * as path from 'path'; -import { Disposable, l10n, Uri } from 'vscode'; +import { Disposable, Uri } from 'vscode'; import { ICommandManager, IWorkspaceService } from '../../common/application/types'; -import { Commands } from '../../common/constants'; import '../../common/extensions'; import { IPlatformService } from '../../common/platform/types'; import { ITerminalService, ITerminalServiceFactory } from '../../common/terminal/types'; import { IConfigurationService, IDisposableRegistry, Resource } from '../../common/types'; +import { Diagnostics, Repl } from '../../common/utils/localize'; import { showWarningMessage } from '../../common/vscodeApis/windowApis'; import { IInterpreterService } from '../../interpreter/contracts'; import { traceInfo } from '../../logging'; @@ -48,17 +48,9 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { await this.initializeRepl(resource); if (code == 'deprecated') { // If user is trying to smart send deprecated code show warning - const selection = await showWarningMessage( - l10n.t( - `Python is unable to parse the code provided. Please - turn off Smart Send if you wish to run code line by line or explicitly select code - to force run. See [logs](command:${Commands.ViewOutput}) for more details.`, - ), - 'Disable Smart Send', - ); + const selection = await showWarningMessage(Diagnostics.invalidSmartSendMessage, Repl.disableSmartSend); traceInfo(`Selected file contains invalid Python or Deprecated Python 2 code`); - if (selection === 'Disable Smart Send') { - // this.commandManager.executeCommand('workbench.action.openSettings', 'python.REPL.EnableREPLSmartSend'); + if (selection === Repl.disableSmartSend) { this.configurationService.updateSetting('REPL.EnableREPLSmartSend', false, resource); } } else { From 16021ee13d77b1429dd9099aef7dfa54e45eccbe Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 17 Nov 2023 16:19:48 -0800 Subject: [PATCH 30/31] lowercase enable --- package.json | 2 +- src/client/common/types.ts | 2 +- src/client/terminals/codeExecution/helper.ts | 2 +- src/client/terminals/codeExecution/terminalCodeExecution.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index cc9cfa120fa7..fbd2b4438443 100644 --- a/package.json +++ b/package.json @@ -699,7 +699,7 @@ "scope": "resource", "type": "array" }, - "python.REPL.EnableREPLSmartSend": { + "python.REPL.enableREPLSmartSend": { "default": true, "description": "%python.EnableREPLSmartSend.description%", "scope": "resource", diff --git a/src/client/common/types.ts b/src/client/common/types.ts index fc156dd5a815..67fcf5c7b700 100644 --- a/src/client/common/types.ts +++ b/src/client/common/types.ts @@ -199,7 +199,7 @@ export interface ITerminalSettings { } export interface IREPLSettings { - readonly EnableREPLSmartSend: boolean; + readonly enableREPLSmartSend: boolean; } export interface IExperiments { diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index 43e3fbedd8d4..48a435c8710a 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -98,7 +98,7 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { const configuration = this.serviceContainer.get(IConfigurationService); if (configuration) { const pythonSettings = configuration.getSettings(this.activeResourceService.getActiveResource()); - smartSendSettingsEnabledVal = pythonSettings.REPL.EnableREPLSmartSend; + smartSendSettingsEnabledVal = pythonSettings.REPL.enableREPLSmartSend; } const input = JSON.stringify({ diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 6482c80060dc..a257fff20dbf 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -51,7 +51,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { const selection = await showWarningMessage(Diagnostics.invalidSmartSendMessage, Repl.disableSmartSend); traceInfo(`Selected file contains invalid Python or Deprecated Python 2 code`); if (selection === Repl.disableSmartSend) { - this.configurationService.updateSetting('REPL.EnableREPLSmartSend', false, resource); + this.configurationService.updateSetting('REPL.enableREPLSmartSend', false, resource); } } else { await this.getTerminalService(resource).sendText(code); From 7063648146c90f5da10d128fa263a8df5da9d3cd Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 17 Nov 2023 16:22:51 -0800 Subject: [PATCH 31/31] enable for test --- src/test/terminals/codeExecution/smartSend.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/terminals/codeExecution/smartSend.test.ts b/src/test/terminals/codeExecution/smartSend.test.ts index 3eb79ac6b950..01f490e2b252 100644 --- a/src/test/terminals/codeExecution/smartSend.test.ts +++ b/src/test/terminals/codeExecution/smartSend.test.ts @@ -108,7 +108,7 @@ suite('REPL - Smart Send', () => { .returns(() => activeResourceService.object); activeResourceService.setup((a) => a.getActiveResource()).returns(() => resource); - pythonSettings.setup((s) => s.REPL).returns(() => ({ EnableREPLSmartSend: true, REPLSmartSend: true })); + pythonSettings.setup((s) => s.REPL).returns(() => ({ enableREPLSmartSend: true, REPLSmartSend: true })); configurationService.setup((x) => x.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object);