Skip to content

Commit

Permalink
start setting up experiment for smart send
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Aug 21, 2023
1 parent 3734312 commit 5d2e450
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,16 @@
"pythonSurveyNotification",
"pythonPromptNewToolsExt",
"pythonTerminalEnvVarActivation",
"pythonTestAdapter"
"pythonTestAdapter",
"pythonREPLSmartSend"
],
"enumDescriptions": [
"%python.experiments.All.description%",
"%python.experiments.pythonSurveyNotification.description%",
"%python.experiments.pythonPromptNewToolsExt.description%",
"%python.experiments.pythonTerminalEnvVarActivation.description%",
"%python.experiments.pythonTestAdapter.description%"
"%python.experiments.pythonTestAdapter.description%",
"%python.experiments.pythonREPLSmartSend.description%"
]
},
"scope": "machine",
Expand All @@ -572,14 +574,16 @@
"pythonSurveyNotification",
"pythonPromptNewToolsExt",
"pythonTerminalEnvVarActivation",
"pythonTestAdapter"
"pythonTestAdapter",
"pythonREPLSmartSend"
],
"enumDescriptions": [
"%python.experiments.All.description%",
"%python.experiments.pythonSurveyNotification.description%",
"%python.experiments.pythonPromptNewToolsExt.description%",
"%python.experiments.pythonTerminalEnvVarActivation.description%",
"%python.experiments.pythonTestAdapter.description%"
"%python.experiments.pythonTestAdapter.description%",
"%python.experiments.pythonREPLSmartSend.description%"
]
},
"scope": "machine",
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"python.experiments.pythonPromptNewToolsExt.description": "Denotes the Python Prompt New Tools Extension experiment.",
"python.experiments.pythonTerminalEnvVarActivation.description": "Enables use of environment variables to activate terminals instead of sending activation commands.",
"python.experiments.pythonTestAdapter.description": "Denotes the Python Test Adapter experiment.",
"python.experiments.pythonREPLSmartSend.description": "Denotes the Python REPL Smart Send experiment.",
"python.formatting.autopep8Args.description": "Arguments passed in. Each argument is a separate item in the array.",
"python.formatting.autopep8Args.markdownDeprecationMessage": "This setting will soon be deprecated. Please use the [Autopep8 extension](https://marketplace.visualstudio.com/items?itemName=ms-python.autopep8). <br>Learn more [here](https://aka.ms/AAlgvkb).",
"python.formatting.autopep8Args.deprecationMessage": "This setting will soon be deprecated. Please use the Autopep8 extension. Learn more here: https://aka.ms/AAlgvkb.",
Expand Down Expand Up @@ -265,4 +266,4 @@
"walkthrough.step.python.createNewNotebook.altText": "Creating a new Jupyter notebook",
"walkthrough.step.python.openInteractiveWindow.altText": "Opening Python interactive window",
"walkthrough.step.python.dataScienceLearnMore.altText": "Image representing our documentation page and mailing list resources."
}
}
4 changes: 4 additions & 0 deletions src/client/common/experiments/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ export enum ShowFormatterExtensionPrompt {
export enum EnableTestAdapterRewrite {
experiment = 'pythonTestAdapter',
}
// Experiment to enable smart shift+enter, advance cursor.
export enum EnableREPLSmartSend {
experiment = 'pythonREPLSmartSend',
}
23 changes: 17 additions & 6 deletions src/client/terminals/codeExecution/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { IInterpreterService } from '../../interpreter/contracts';
import { IServiceContainer } from '../../ioc/types';
import { ICodeExecutionHelper } from '../types';
import { traceError } from '../../logging';
import { Resource } from '../../common/types';
import { IExperimentService, Resource } from '../../common/types';
import { EnableREPLSmartSend } from '../../common/experiments/groups';

@injectable()
export class CodeExecutionHelper implements ICodeExecutionHelper {
Expand All @@ -26,11 +27,14 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {

private readonly interpreterService: IInterpreterService;

// private readonly configSettings: IConfigurationService;

constructor(@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer) {
this.documentManager = serviceContainer.get<IDocumentManager>(IDocumentManager);
this.applicationShell = serviceContainer.get<IApplicationShell>(IApplicationShell);
this.processServiceFactory = serviceContainer.get<IProcessServiceFactory>(IProcessServiceFactory);
this.interpreterService = serviceContainer.get<IInterpreterService>(IInterpreterService);
// this.configSettings = serviceContainer.get<IConfigurationService>(IConfigurationService);
}

public async normalizeLines(code: string, wholeFileContent: string, resource?: Uri): Promise<string> {
Expand Down Expand Up @@ -80,14 +84,16 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {
// We expect a serialized JSON object back, with the normalized code under the "normalized" key.
const result = await normalizeOutput.promise;
const object = JSON.parse(result);
// this.smartMoveCursor(object.nextBlockIndex);
// commands.executeCommand('cursorMove', { to: 'down'});
// calculate and return offset
// Smart cursor move only for smart shift+enter
if (activeEditor!.selection.isEmpty) {

// Let user experience smart shift+enter, advance cursor if in experiment
if (pythonSmartSendEnabled(this.serviceContainer)) {
// Advance cursor move only for smart shift+enter
if (activeEditor!.selection.isEmpty) {
const lineOffset = object.nextBlockLineno - activeEditor!.selection.start.line;
commands.executeCommand('cursorMove', { to: 'down', by: 'line', value: Number(lineOffset) });
}
}

return parse(object.normalized);
} catch (ex) {
traceError(ex, 'Python: Failed to normalize code for execution in terminal');
Expand Down Expand Up @@ -251,3 +257,8 @@ function getMultiLineSelectionText(textEditor: TextEditor): string {
// ↑<---------------- To here
return selectionText;
}

function pythonSmartSendEnabled(serviceContainer: IServiceContainer): boolean {
const experiment = serviceContainer.get<IExperimentService>(IExperimentService);
return experiment.inExperimentSync(EnableREPLSmartSend.experiment);
}

0 comments on commit 5d2e450

Please sign in to comment.