Skip to content

Commit

Permalink
delete stale experiment, properly get setting
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed May 23, 2024
1 parent 0cffa5a commit a6036cd
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 62 deletions.
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,7 @@
"pythonDiscoveryUsingWorkers",
"pythonTestAdapter",
"pythonREPLSmartSend",
"pythonRecommendTensorboardExt",
"pythonRunREPL"
"pythonRecommendTensorboardExt"
],
"enumDescriptions": [
"%python.experiments.All.description%",
Expand All @@ -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",
Expand All @@ -472,8 +470,7 @@
"pythonTerminalEnvVarActivation",
"pythonDiscoveryUsingWorkers",
"pythonTestAdapter",
"pythonREPLSmartSend",
"pythonRunREPL"
"pythonREPLSmartSend"
],
"enumDescriptions": [
"%python.experiments.All.description%",
Expand All @@ -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",
Expand Down Expand Up @@ -632,7 +628,10 @@
"default": false,
"description": "%python.REPL.sendToNativeREPL.description%",
"scope": "resource",
"type": "boolean"
"type": "boolean",
"tags": [
"experimental"
]
},
"python.testing.autoTestDiscoverOnSaveEnabled": {
"default": true,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
Expand Down
1 change: 0 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
5 changes: 0 additions & 5 deletions src/client/common/experiments/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
11 changes: 11 additions & 0 deletions src/client/common/vscodeApis/windowApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextEditor> {
return window.showTextDocument(uri);
Expand Down Expand Up @@ -238,3 +240,12 @@ export function createStepForwardEndNode<T>(deferred?: Deferred<T>, 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;
}
32 changes: 4 additions & 28 deletions src/client/extensionActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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>(IExperimentService);
const configurationService = ext.legacyIOC.serviceContainer.get<IConfigurationService>(IConfigurationService);
const activeResourceService = ext.legacyIOC.serviceContainer.get<IActiveResourceService>(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);
}

/// //////////////////////////
Expand Down
29 changes: 13 additions & 16 deletions src/client/repl/replCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,27 +48,24 @@ async function getSelectedTextToExecute(textEditor: TextEditor): Promise<string

return code;
}

function getSendToNativeREPLSetting(): boolean {
const uri = getActiveResource();
const configuration = getConfiguration('python', uri);
return configuration.get<boolean>('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<void> {
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);
Expand Down

0 comments on commit a6036cd

Please sign in to comment.