From a6036cd5de7d77fc97907033d05557b38451f8bc Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 23 May 2024 11:11:06 -0700 Subject: [PATCH] delete stale experiment, properly get setting --- package.json | 23 ++++++++-------- package.nls.json | 1 - src/client/common/experiments/groups.ts | 5 ---- src/client/common/vscodeApis/windowApis.ts | 11 ++++++++ src/client/extensionActivation.ts | 32 +++------------------- src/client/repl/replCommands.ts | 29 +++++++++----------- 6 files changed, 39 insertions(+), 62 deletions(-) diff --git a/package.json b/package.json index b60a07994870..0c4cc49545bc 100644 --- a/package.json +++ b/package.json @@ -442,8 +442,7 @@ "pythonDiscoveryUsingWorkers", "pythonTestAdapter", "pythonREPLSmartSend", - "pythonRecommendTensorboardExt", - "pythonRunREPL" + "pythonRecommendTensorboardExt" ], "enumDescriptions": [ "%python.experiments.All.description%", @@ -453,8 +452,7 @@ "%python.experiments.pythonDiscoveryUsingWorkers.description%", "%python.experiments.pythonTestAdapter.description%", "%python.experiments.pythonREPLSmartSend.description%", - "%python.experiments.pythonRecommendTensorboardExt.description%", - "%python.experiments.pythonRunREPL.description%" + "%python.experiments.pythonRecommendTensorboardExt.description%" ] }, "scope": "window", @@ -472,8 +470,7 @@ "pythonTerminalEnvVarActivation", "pythonDiscoveryUsingWorkers", "pythonTestAdapter", - "pythonREPLSmartSend", - "pythonRunREPL" + "pythonREPLSmartSend" ], "enumDescriptions": [ "%python.experiments.All.description%", @@ -482,8 +479,7 @@ "%python.experiments.pythonTerminalEnvVarActivation.description%", "%python.experiments.pythonDiscoveryUsingWorkers.description%", "%python.experiments.pythonTestAdapter.description%", - "%python.experiments.pythonREPLSmartSend.description%", - "%python.experiments.pythonRunREPL.description%" + "%python.experiments.pythonREPLSmartSend.description%" ] }, "scope": "window", @@ -632,7 +628,10 @@ "default": false, "description": "%python.REPL.sendToNativeREPL.description%", "scope": "resource", - "type": "boolean" + "type": "boolean", + "tags": [ + "experimental" + ] }, "python.testing.autoTestDiscoverOnSaveEnabled": { "default": true, @@ -1114,12 +1113,12 @@ { "command": "python.execSelectionInTerminal", "key": "shift+enter", - "when": "!pythonRunREPL && editorTextFocus && editorLangId == python && !findInputFocussed && !replaceInputFocussed && !jupyter.ownsSelection && !notebookEditorFocused && activeEditor != 'workbench.editor.interactive'" + "when": "!config.python.REPL.sendToNativeREPL && editorTextFocus && editorLangId == python && !findInputFocussed && !replaceInputFocussed && !jupyter.ownsSelection && !notebookEditorFocused && activeEditor != 'workbench.editor.interactive'" }, { "command": "python.execInREPL", "key": "shift+enter", - "when": "pythonRunREPL" + "when": "config.python.REPL.sendToNativeREPL" }, { "command": "python.execInREPLEnter", @@ -1388,7 +1387,7 @@ { "command": "python.execInREPL", "group": "Python", - "when": "editorFocus && editorLangId == python && !virtualWorkspace && shellExecutionSupported && pythonRunREPL && config.python.REPL.sendToNativeREPL" + "when": "editorFocus && editorLangId == python && !virtualWorkspace && shellExecutionSupported && config.python.REPL.sendToNativeREPL" } ], "editor/title": [ diff --git a/package.nls.json b/package.nls.json index 6256da62697a..669a14bed528 100644 --- a/package.nls.json +++ b/package.nls.json @@ -45,7 +45,6 @@ "python.experiments.pythonTestAdapter.description": "Denotes the Python Test Adapter experiment.", "python.experiments.pythonREPLSmartSend.description": "Denotes the Python REPL Smart Send experiment.", "python.experiments.pythonRecommendTensorboardExt.description": "Denotes the Tensorboard Extension recommendation experiment.", - "python.experiments.pythonRunREPL.description": "Enables users to run code in interactive Python REPL.", "python.globalModuleInstallation.description": "Whether to install Python modules globally when not using an environment.", "python.languageServer.description": "Defines type of the language server.", "python.languageServer.defaultDescription": "Automatically select a language server: Pylance if installed and available, otherwise fallback to Jedi.", diff --git a/src/client/common/experiments/groups.ts b/src/client/common/experiments/groups.ts index 543b1e27516f..81f157751346 100644 --- a/src/client/common/experiments/groups.ts +++ b/src/client/common/experiments/groups.ts @@ -30,8 +30,3 @@ export enum RecommendTensobardExtension { export enum CreateEnvOnPipInstallTrigger { experiment = 'pythonCreateEnvOnPipInstall', } - -// Experiment to enable running Python REPL using IW. -export enum EnableRunREPL { - experiment = 'pythonRunREPL', -} diff --git a/src/client/common/vscodeApis/windowApis.ts b/src/client/common/vscodeApis/windowApis.ts index 6ef02df41d1e..37d302946614 100644 --- a/src/client/common/vscodeApis/windowApis.ts +++ b/src/client/common/vscodeApis/windowApis.ts @@ -21,6 +21,8 @@ import { TerminalShellExecutionStartEvent, } from 'vscode'; import { createDeferred, Deferred } from '../utils/async'; +import { Resource } from '../types'; +import { getWorkspaceFolders } from './workspaceApis'; export function showTextDocument(uri: Uri): Thenable { return window.showTextDocument(uri); @@ -238,3 +240,12 @@ export function createStepForwardEndNode(deferred?: Deferred, result?: T): undefined, ); } + +export function getActiveResource(): Resource { + const editor = window.activeTextEditor; + if (editor && !editor.document.isUntitled) { + return editor.document.uri; + } + const workspaces = getWorkspaceFolders(); + return Array.isArray(workspaces) && workspaces.length > 0 ? workspaces[0].uri : undefined; +} diff --git a/src/client/extensionActivation.ts b/src/client/extensionActivation.ts index f2fdeb0dd9b4..1c7e8f384ff1 100644 --- a/src/client/extensionActivation.ts +++ b/src/client/extensionActivation.ts @@ -3,25 +3,19 @@ 'use strict'; -import { DebugConfigurationProvider, debug, languages, window, commands } from 'vscode'; +import { DebugConfigurationProvider, debug, languages, window } from 'vscode'; import { registerTypes as activationRegisterTypes } from './activation/serviceRegistry'; import { IExtensionActivationManager } from './activation/types'; import { registerTypes as appRegisterTypes } from './application/serviceRegistry'; import { IApplicationDiagnostics } from './application/types'; -import { - IActiveResourceService, - IApplicationEnvironment, - ICommandManager, - IWorkspaceService, -} from './common/application/types'; +import { IApplicationEnvironment, ICommandManager, IWorkspaceService } from './common/application/types'; import { Commands, PYTHON_LANGUAGE, UseProposedApi } from './common/constants'; import { registerTypes as installerRegisterTypes } from './common/installer/serviceRegistry'; import { IFileSystem } from './common/platform/types'; import { IConfigurationService, IDisposableRegistry, - IExperimentService, IExtensions, IInterpreterPathService, ILogOutputChannel, @@ -59,7 +53,6 @@ import { logAndNotifyOnLegacySettings } from './logging/settingLogs'; import { DebuggerTypeName } from './debugger/constants'; import { StopWatch } from './common/utils/stopWatch'; import { registerReplCommands, registerReplExecuteOnEnter } from './repl/replCommands'; -import { EnableRunREPL } from './common/experiments/groups'; export async function activateComponents( // `ext` is passed to any extra activation funcs. @@ -114,25 +107,8 @@ export function activateFeatures(ext: ExtensionState, _components: Components): pathUtils, ); - // Register native REPL context menu when in experiment - const experimentService = ext.legacyIOC.serviceContainer.get(IExperimentService); - const configurationService = ext.legacyIOC.serviceContainer.get(IConfigurationService); - const activeResourceService = ext.legacyIOC.serviceContainer.get(IActiveResourceService); - // commands.executeCommand('setContext', 'pythonRunREPL', false); - if (experimentService) { - const replExperimentValue = experimentService.inExperimentSync(EnableRunREPL.experiment); - commands.executeCommand('setContext', 'pythonRunREPL', replExperimentValue); - // If user is in pythonRunREPL experiment, we enable the sendToNativeREPL setting to True by default. - if (replExperimentValue) { - configurationService.updateSetting( - 'REPL.sendToNativeREPL', - true, - activeResourceService.getActiveResource(), - ); - registerReplCommands(ext.disposables, interpreterService, configurationService, activeResourceService); - registerReplExecuteOnEnter(ext.disposables, interpreterService); - } - } + registerReplCommands(ext.disposables, interpreterService); + registerReplExecuteOnEnter(ext.disposables, interpreterService); } /// ////////////////////////// diff --git a/src/client/repl/replCommands.ts b/src/client/repl/replCommands.ts index 9232c2a45512..5b056ce2a9d7 100644 --- a/src/client/repl/replCommands.ts +++ b/src/client/repl/replCommands.ts @@ -16,14 +16,14 @@ import { NotebookDocument, } from 'vscode'; import { Disposable } from 'vscode-jsonrpc'; -import { IActiveResourceService } from '../common/application/types'; import { Commands, PVSC_EXTENSION_ID } from '../common/constants'; -import { IConfigurationService } from '../common/types'; import { noop } from '../common/utils/misc'; import { IInterpreterService } from '../interpreter/contracts'; import { getMultiLineSelectionText, getSingleLineSelectionText } from '../terminals/codeExecution/helper'; import { createPythonServer } from './pythonServer'; import { createReplController } from './replController'; +import { getActiveResource } from '../common/vscodeApis/windowApis'; +import { getConfiguration } from '../common/vscodeApis/workspaceApis'; let notebookController: NotebookController | undefined; let notebookEditor: NotebookEditor | undefined; @@ -48,27 +48,24 @@ async function getSelectedTextToExecute(textEditor: TextEditor): Promise('REPL.sendToNativeREPL', false); +} // Will only be called when user has experiment enabled. export async function registerReplCommands( disposables: Disposable[], interpreterService: IInterpreterService, - configurationService: IConfigurationService, - activeResourceService: IActiveResourceService, ): Promise { disposables.push( commands.registerCommand(Commands.Exec_In_REPL, async (uri: Uri) => { - let nativeREPLSetting = false; - - // Get REPL setting value from user settings - if (configurationService) { - const pythonSettings = configurationService.getSettings(activeResourceService.getActiveResource()); - nativeREPLSetting = pythonSettings.REPL.sendToNativeREPL; - // If nativeREPLSetting is false(Send to Terminal REPL), then fall back to running in Terminal REPL - if (!nativeREPLSetting) { - await commands.executeCommand(Commands.Exec_Selection_In_Terminal); - return; - } + const nativeREPLSetting = getSendToNativeREPLSetting(); + + // If nativeREPLSetting is false(Send to Terminal REPL), then fall back to running in Terminal REPL + if (!nativeREPLSetting) { + await commands.executeCommand(Commands.Exec_Selection_In_Terminal); + return; } const interpreter = await interpreterService.getActiveInterpreter(uri);