| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -166,12 +166,12 @@ def __init__(self): | |||
| 166 | 166 | self.default_sys_path = sys.path | |
| 167 | 167 | self._input = io.open(sys.stdin.fileno(), encoding='utf-8') | |
| 168 | 168 | ||
| 169 | - def _rename(self, filePath, start, newName): | ||
| 169 | + def _rename(self, filePath, start, newName, indent_size): | ||
| 170 | 170 | """ | |
| 171 | 171 | Extracts a variale | |
| 172 | 172 | """ | |
| 173 | 173 | project = rope.base.project.Project( | |
| 174 | - WORKSPACE_ROOT, ropefolder=ROPE_PROJECT_FOLDER, save_history=False) | ||
| 174 | + WORKSPACE_ROOT, ropefolder=ROPE_PROJECT_FOLDER, save_history=False, indent_size=indent_size) | ||
| 175 | 175 | resourceToRefactor = libutils.path_to_resource(project, filePath) | |
| 176 | 176 | refactor = RenameRefactor( | |
| 177 | 177 | project, resourceToRefactor, startOffset=start, newName=newName) | |
@@ -183,12 +183,12 @@ def _rename(self, filePath, start, newName): | |||
| 183 | 183 | valueToReturn.append({'diff': change.diff}) | |
| 184 | 184 | return valueToReturn | |
| 185 | 185 | ||
| 186 | - def _extractVariable(self, filePath, start, end, newName): | ||
| 186 | + def _extractVariable(self, filePath, start, end, newName, indent_size): | ||
| 187 | 187 | """ | |
| 188 | 188 | Extracts a variale | |
| 189 | 189 | """ | |
| 190 | 190 | project = rope.base.project.Project( | |
| 191 | - WORKSPACE_ROOT, ropefolder=ROPE_PROJECT_FOLDER, save_history=False) | ||
| 191 | + WORKSPACE_ROOT, ropefolder=ROPE_PROJECT_FOLDER, save_history=False, indent_size=indent_size) | ||
| 192 | 192 | resourceToRefactor = libutils.path_to_resource(project, filePath) | |
| 193 | 193 | refactor = ExtractVariableRefactor( | |
| 194 | 194 | project, resourceToRefactor, startOffset=start, endOffset=end, newName=newName, similar=True) | |
@@ -200,12 +200,12 @@ def _extractVariable(self, filePath, start, end, newName): | |||
| 200 | 200 | valueToReturn.append({'diff': change.diff}) | |
| 201 | 201 | return valueToReturn | |
| 202 | 202 | ||
| 203 | - def _extractMethod(self, filePath, start, end, newName): | ||
| 203 | + def _extractMethod(self, filePath, start, end, newName, indent_size): | ||
| 204 | 204 | """ | |
| 205 | 205 | Extracts a method | |
| 206 | 206 | """ | |
| 207 | 207 | project = rope.base.project.Project( | |
| 208 | - WORKSPACE_ROOT, ropefolder=ROPE_PROJECT_FOLDER, save_history=False) | ||
| 208 | + WORKSPACE_ROOT, ropefolder=ROPE_PROJECT_FOLDER, save_history=False, indent_size=indent_size) | ||
| 209 | 209 | resourceToRefactor = libutils.path_to_resource(project, filePath) | |
| 210 | 210 | refactor = ExtractMethodRefactor( | |
| 211 | 211 | project, resourceToRefactor, startOffset=start, endOffset=end, newName=newName, similar=True) | |
@@ -244,15 +244,15 @@ def _process_request(self, request): | |||
| 244 | 244 | pass | |
| 245 | 245 | elif lookup == 'rename': | |
| 246 | 246 | changes = self._rename(request['file'], int( | |
| 247 | - request['start']), request['name']) | ||
| 247 | + request['start']), request['name'], int(request['indent_size'])) | ||
| 248 | 248 | return self._write_response(self._serialize(request['id'], changes)) | |
| 249 | 249 | elif lookup == 'extract_variable': | |
| 250 | 250 | changes = self._extractVariable(request['file'], int( | |
| 251 | - request['start']), int(request['end']), request['name']) | ||
| 251 | + request['start']), int(request['end']), request['name'], int(request['indent_size'])) | ||
| 252 | 252 | return self._write_response(self._serialize(request['id'], changes)) | |
| 253 | 253 | elif lookup == 'extract_method': | |
| 254 | 254 | changes = self._extractMethod(request['file'], int( | |
| 255 | - request['start']), int(request['end']), request['name']) | ||
| 255 | + request['start']), int(request['end']), request['name'], int(request['indent_size'])) | ||
| 256 | 256 | return self._write_response(self._serialize(request['id'], changes)) | |
| 257 | 257 | ||
| 258 | 258 | def _write_response(self, response): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,7 +35,7 @@ export function extractVariable(extensionDir: string, textEditor: vscode.TextEdi | |||
| 35 | 35 | return validateDocumentForRefactor(textEditor).then(() => { | |
| 36 | 36 | let newName = 'newvariable' + new Date().getMilliseconds().toString(); | |
| 37 | 37 | let proxy = new RefactorProxy(extensionDir, pythonSettings, workspaceRoot); | |
| 38 | - let rename = proxy.extractVariable<RenameResponse>(textEditor.document, newName, textEditor.document.uri.fsPath, range).then(response => { | ||
| 38 | + let rename = proxy.extractVariable<RenameResponse>(textEditor.document, newName, textEditor.document.uri.fsPath, range, textEditor.options).then(response => { | ||
| 39 | 39 | return response.results[0].diff; | |
| 40 | 40 | }); | |
| 41 | 41 | ||
@@ -51,7 +51,7 @@ export function extractMethod(extensionDir: string, textEditor: vscode.TextEdito | |||
| 51 | 51 | return validateDocumentForRefactor(textEditor).then(() => { | |
| 52 | 52 | let newName = 'newmethod' + new Date().getMilliseconds().toString(); | |
| 53 | 53 | let proxy = new RefactorProxy(extensionDir, pythonSettings, workspaceRoot); | |
| 54 | - let rename = proxy.extractMethod<RenameResponse>(textEditor.document, newName, textEditor.document.uri.fsPath, range).then(response => { | ||
| 54 | + let rename = proxy.extractMethod<RenameResponse>(textEditor.document, newName, textEditor.document.uri.fsPath, range, textEditor.options).then(response => { | ||
| 55 | 55 | return response.results[0].diff; | |
| 56 | 56 | }); | |
| 57 | 57 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ import * as child_process from 'child_process'; | |||
| 6 | 6 | import { IPythonSettings } from '../common/configSettings'; | |
| 7 | 7 | import { REFACTOR } from '../common/telemetryContracts'; | |
| 8 | 8 | import { sendTelemetryEvent, Delays } from '../common/telemetry'; | |
| 9 | - import {IS_WINDOWS} from '../common/utils'; | ||
| 9 | + import { IS_WINDOWS } from '../common/utils'; | ||
| 10 | 10 | ||
| 11 | 11 | export class RefactorProxy extends vscode.Disposable { | |
| 12 | 12 | private _process: child_process.ChildProcess; | |
@@ -30,8 +30,8 @@ export class RefactorProxy extends vscode.Disposable { | |||
| 30 | 30 | } | |
| 31 | 31 | this._process = null; | |
| 32 | 32 | } | |
| 33 | - private getOffsetAt(document: vscode.TextDocument, position:vscode.Position):number { | ||
| 34 | - if (!IS_WINDOWS){ | ||
| 33 | + private getOffsetAt(document: vscode.TextDocument, position: vscode.Position): number { | ||
| 34 | + if (!IS_WINDOWS) { | ||
| 35 | 35 | return document.offsetAt(position); | |
| 36 | 36 | } | |
| 37 | 37 | ||
@@ -41,21 +41,53 @@ export class RefactorProxy extends vscode.Disposable { | |||
| 41 | 41 | const offset = document.offsetAt(position); | |
| 42 | 42 | return offset - position.line; | |
| 43 | 43 | } | |
| 44 | - rename<T>(document: vscode.TextDocument, name: string, filePath: string, range: vscode.Range): Promise<T> { | ||
| 45 | - let command = { "lookup": "rename", "file": filePath, "start": this.getOffsetAt(document, range.start).toString(), "id": "1", "name": name }; | ||
| 46 | - | ||
| 44 | + rename<T>(document: vscode.TextDocument, name: string, filePath: string, range: vscode.Range, options?: vscode.TextEditorOptions): Promise<T> { | ||
| 45 | + if (!options) { | ||
| 46 | + options = vscode.window.activeTextEditor.options; | ||
| 47 | + } | ||
| 48 | + let command = { | ||
| 49 | + "lookup": "rename", | ||
| 50 | + "file": filePath, | ||
| 51 | + "start": this.getOffsetAt(document, range.start).toString(), | ||
| 52 | + "id": "1", | ||
| 53 | + "name": name, | ||
| 54 | + "indent_size": options.tabSize | ||
| 55 | + }; | ||
| 56 | + | ||
| 47 | 57 | return this.sendCommand<T>(JSON.stringify(command), REFACTOR.Rename); | |
| 48 | 58 | } | |
| 49 | - extractVariable<T>(document: vscode.TextDocument, name: string, filePath: string, range: vscode.Range): Promise<T> { | ||
| 50 | - let command = { "lookup": "extract_variable", "file": filePath, "start": this.getOffsetAt(document, range.start).toString(), "end": this.getOffsetAt(document, range.end).toString(), "id": "1", "name": name }; | ||
| 59 | + extractVariable<T>(document: vscode.TextDocument, name: string, filePath: string, range: vscode.Range, options?: vscode.TextEditorOptions): Promise<T> { | ||
| 60 | + if (!options) { | ||
| 61 | + options = vscode.window.activeTextEditor.options; | ||
| 62 | + } | ||
| 63 | + let command = { | ||
| 64 | + "lookup": "extract_variable", | ||
| 65 | + "file": filePath, | ||
| 66 | + "start": this.getOffsetAt(document, range.start).toString(), | ||
| 67 | + "end": this.getOffsetAt(document, range.end).toString(), | ||
| 68 | + "id": "1", | ||
| 69 | + "name": name, | ||
| 70 | + "indent_size": options.tabSize | ||
| 71 | + }; | ||
| 51 | 72 | return this.sendCommand<T>(JSON.stringify(command), REFACTOR.ExtractVariable); | |
| 52 | 73 | } | |
| 53 | - extractMethod<T>(document: vscode.TextDocument, name: string, filePath: string, range: vscode.Range): Promise<T> { | ||
| 74 | + extractMethod<T>(document: vscode.TextDocument, name: string, filePath: string, range: vscode.Range, options?: vscode.TextEditorOptions): Promise<T> { | ||
| 75 | + if (!options) { | ||
| 76 | + options = vscode.window.activeTextEditor.options; | ||
| 77 | + } | ||
| 54 | 78 | // Ensure last line is an empty line | |
| 55 | 79 | if (!document.lineAt(document.lineCount - 1).isEmptyOrWhitespace && range.start.line === document.lineCount - 1) { | |
| 56 | 80 | return Promise.reject<T>('Missing blank line at the end of document (PEP8).'); | |
| 57 | 81 | } | |
| 58 | - let command = { "lookup": "extract_method", "file": filePath, "start": this.getOffsetAt(document, range.start).toString(), "end": this.getOffsetAt(document, range.end).toString(), "id": "1", "name": name }; | ||
| 82 | + let command = { | ||
| 83 | + "lookup": "extract_method", | ||
| 84 | + "file": filePath, | ||
| 85 | + "start": this.getOffsetAt(document, range.start).toString(), | ||
| 86 | + "end": this.getOffsetAt(document, range.end).toString(), | ||
| 87 | + "id": "1", | ||
| 88 | + "name": name, | ||
| 89 | + "indent_size": options.tabSize | ||
| 90 | + }; | ||
| 59 | 91 | return this.sendCommand<T>(JSON.stringify(command), REFACTOR.ExtractMethod); | |
| 60 | 92 | } | |
| 61 | 93 | private sendCommand<T>(command: string, telemetryEvent: string): Promise<T> { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments