Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporated the extract method command #18518 #18514

Closed
wants to merge 122 commits into from

Conversation

Harry-Hopkinson
Copy link

@Harry-Hopkinson Harry-Hopkinson commented Feb 13, 2022

Supported the extract method command. #18518

@Harry-Hopkinson
Copy link
Author

Using --no-capture-output for a temporary alias.

@Harry-Hopkinson
Copy link
Author

As stated in conda/conda#11209

@@ -161,7 +161,6 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
'-n',
interpreter.envName,
'--no-capture-output',
'--live-stream',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed --live-stream where applicable if --no-capture-ouput was the former between the two.

@@ -171,7 +170,6 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
'-p',
interpreter.envPath,
'--no-capture-output',
'--live-stream',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed --live-stream where applicable if --no-capture-ouput was the former between the two.

@@ -416,7 +416,7 @@ export class Conda {
} else {
args.push('-p', env.prefix);
}
return [this.command, 'run', ...args, '--no-capture-output', '--live-stream', 'python', OUTPUT_MARKER_SCRIPT];
return [this.command, 'run', ...args, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed --live-stream where applicable if --no-capture-ouput was the former between the two.

@@ -481,14 +481,14 @@ suite('Conda and its environments are located correctly', () => {
expect(args).to.not.equal(undefined);
assert.deepStrictEqual(
args,
['conda', 'run', '-n', 'envName', '--no-capture-output', '--live-stream', 'python', OUTPUT_MARKER_SCRIPT],
['conda', 'run', '-n', 'envName', '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed --live-stream where applicable if --no-capture-ouput was the former between the two.

'Incorrect args for case 1',
);

args = await conda?.getRunPythonArgs({ name: '', prefix: 'envPrefix' });
assert.deepStrictEqual(
args,
['conda', 'run', '-p', 'envPrefix', '--no-capture-output', '--live-stream', 'python', OUTPUT_MARKER_SCRIPT],
['conda', 'run', '-p', 'envPrefix', '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed --live-stream where applicable if --no-capture-ouput was the former between the two.

@Harry-Hopkinson
Copy link
Author

Can I have the skip package*.json for this PR?

@Harry-Hopkinson Harry-Hopkinson changed the title Not use --live-stream with conda run #18511 Not use --live-stream with conda run #18511 and supported the extract method command #18518 Feb 14, 2022
Copy link

@karrtikr karrtikr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove extract method changes from this PR. We currently haven't made a decision on whether we want #18511 (it lacks a needs PR label), so we cannot accept this PR at the moment. Blocked on #18511 (comment).

@@ -0,0 +1 @@
Not use --live-stream with conda run and supported the extract method command. (Thanks [Harry-Hopkinson](https://github.com/Harry-Hopkinson))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please only solve one issue per PR, create a separate issue for the "Extra method" command.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was created by jdavchev in #18518

Comment on lines 99 to 116
// function UriToFileChanges(uri: any): vscode.TextEdit[] {
// const result: vscode.TextEdit[] = [];
// for (const edit of uri) {
// result.push(new vscode.TextEdit(new vscode.Range(edit.range.start, edit.range.end), edit.newText));
// }
// return result;
// }

// function WorkspaceEditToVSCodeEdit(workspaceEdit: any): vscode.WorkspaceEdit {
// const result: any = {
// changes: {},
// };
// for (const key of Object.keys(workspaceEdit)) {
// result.changes[key] = UriToFileChanges(workspaceEdit.changes[key]);
// }
// return result;
// }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should remove this.

Comment on lines 185 to 212
disposables.push(
cmdManager.registerCommand(Commands.ExtractMethod, async () => {
const editor = window.activeTextEditor;
const shell: IApplicationShell = serviceManager.get<IApplicationShell>(IApplicationShell);
if (editor) {
if (editor.selection.isEmpty) {
return shell.showErrorMessage('Please Select Text before Extracting a Method');
}
const { selection } = editor;
const { document } = editor;
const text = document.getText(selection);
const position = selection.start;
const edit = new WorkspaceEdit();
const methodName = await window.showInputBox({ prompt: 'Enter Method Name' });
if (methodName) {
const newText = `def ${methodName}():\n\t${text}`;
edit.delete(document.uri, selection);
edit.insert(document.uri, position, newText);
await workspace.applyEdit(edit);
} else {
return shell.showErrorMessage('Method Name is Required');
}
} else {
return shell.showErrorMessage('Open an Active Editor before Extracting a Method');
}
return undefined;
}),
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to conda run, should be undone.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the PR to only add support for the Extract Method command as requested in #18518

@Harry-Hopkinson Harry-Hopkinson changed the title Not use --live-stream with conda run #18511 and supported the extract method command #18518 Incorporated the extract method command #18518 Feb 14, 2022
@@ -150,6 +164,67 @@ async function activateLegacy(ext: ExtensionState): Promise<ActivationResult> {
disposables.push(cmdManager.registerCommand(Commands.ViewOutput, () => outputChannel.show()));
cmdManager.executeCommand('setContext', 'python.vscode.channel', applicationEnv.channel).then(noop, noop);

disposables.push(
cmdManager.registerCommand(Commands.ExtractMethod, async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract method and extract variable are supported via the LSP. This way of doing it might not work well since it doesn't correct the indentation on extract. Language servers are in better position of doing this right.

@karthiknadig
Copy link
Member

@Harry-Hopkinson Code extraction to method, and variable extraction are done via language server protocol (LSP). The code to extract that is written in TS in the PR does not verify that the code after extraction is still valid python code. Such things can be done in the Language Server.

Thanks for working on the PR. But we had decided to remove this command in favor of the LSP implementation of extract method, and extract variable a while ago. So, we don't plan on re-introducing it at this point.

I recommend looking at issues marked "needs PR". There is a greater possibility that we would accept PR on those. See here https://github.com/microsoft/vscode-python/wiki/Submitting-a-pull-request#creating-a-pull-request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants