-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
…nd fetches the path of the interpreter.
…ing Multiple Files
Using --no-capture-output for a temporary alias. |
As stated in conda/conda#11209 |
@@ -161,7 +161,6 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac | |||
'-n', | |||
interpreter.envName, | |||
'--no-capture-output', | |||
'--live-stream', |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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.
Can I have the |
There was a problem hiding this 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).
news/2 Fixes/18514.md
Outdated
@@ -0,0 +1 @@ | |||
Not use --live-stream with conda run and supported the extract method command. (Thanks [Harry-Hopkinson](https://github.com/Harry-Hopkinson)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
src/client/extensionActivation.ts
Outdated
// 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; | ||
// } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should remove this.
src/client/extensionActivation.ts
Outdated
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; | ||
}), | ||
); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
… default import``` error
@@ -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 () => { |
There was a problem hiding this comment.
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.
@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 |
Supported the extract method command. #18518