@@ -36,13 +36,13 @@ export class RefactorProxy extends vscode.Disposable { |
36 | 36 | this._process = null; |
37 | 37 | } |
38 | 38 | extractVariable<T>(document: vscode.TextDocument, name: string, filePath: string, range: vscode.Range): Promise<T> { |
39 | | - let command = {"lookup":"extract_variable", "file":filePath, "start":document.offsetAt(range.start).toString(), "end":document.offsetAt(range.end).toString(), "id":"1", "name":name}; |
| 39 | + let command = { "lookup": "extract_variable", "file": filePath, "start": document.offsetAt(range.start).toString(), "end": document.offsetAt(range.end).toString(), "id": "1", "name": name }; |
40 | 40 | return this.sendCommand<T>(JSON.stringify(command), REFACTOR.ExtractVariable); |
41 | 41 | } |
42 | 42 | extractMethod<T>(document: vscode.TextDocument, name: string, filePath: string, range: vscode.Range): Promise<T> { |
43 | | - let command = {"lookup":"extract_method", "file":filePath, "start":document.offsetAt(range.start).toString(), "end":document.offsetAt(range.end).toString(), "id":"1","name":name}; |
| 43 | + let command = { "lookup": "extract_method", "file": filePath, "start": document.offsetAt(range.start).toString(), "end": document.offsetAt(range.end).toString(), "id": "1", "name": name }; |
44 | 44 | return this.sendCommand<T>(JSON.stringify(command), REFACTOR.ExtractVariable); |
45 | | - } |
| 45 | + } |
46 | 46 | private sendCommand<T>(command: string, telemetryEvent: string): Promise<T> { |
47 | 47 | let timer = new Delays(); |
48 | 48 | return this.initialize(this.pythonSettings.pythonPath).then(() => { |
@@ -83,37 +83,29 @@ export class RefactorProxy extends vscode.Disposable { |
83 | 83 | }); |
84 | 84 | } |
85 | 85 | private handleStdError(data: string) { |
| 86 | + // Possible there was an exception in parsing the data returned |
| 87 | + // So append the data then parse it |
86 | 88 | let dataStr = this._previousStdErrData = this._previousStdErrData + data + ''; |
87 | | - if (this._startedSuccessfully) { |
88 | | - // The Rope library can send other (warning) messages in the stderr stream |
89 | | - // Hence look for the prefix, if we don't have the prefix ignore them |
90 | | - if (!dataStr.startsWith(ERROR_PREFIX)) { |
91 | | - this._previousStdErrData = ''; |
92 | | - return; |
93 | | - } |
94 | | - |
95 | | - let lengthOfHeader = dataStr.indexOf(':') + 1; |
96 | | - let lengthOfMessage = parseInt(dataStr.substring(ERROR_PREFIX.length, lengthOfHeader - 1)); |
97 | | - if (dataStr.length >= lengthOfMessage + lengthOfHeader) { |
98 | | - this._previousStdErrData = ''; |
99 | | - this.dispose(); |
100 | | - |
101 | | - let errorLines = dataStr.substring(lengthOfHeader).split(/\r?\n/g); |
102 | | - let hasErrorMessage = errorLines[0].trim().length > 0; |
103 | | - errorLines = errorLines.filter(line => line.length > 0); |
104 | | - let errorMessage = errorLines.join('\n'); |
| 89 | + let errorResponse: { message: string, traceback: string }[]; |
| 90 | + try { |
| 91 | + errorResponse = dataStr.split(/\r?\n/g).filter(line => line.length > 0).map(resp => JSON.parse(resp)); |
| 92 | + this._previousStdErrData = ''; |
| 93 | + } |
| 94 | + catch (ex) { |
| 95 | + // Possible we've only received part of the data, hence don't clear previousData |
| 96 | + return; |
| 97 | + } |
105 | 98 |
|
106 | | - // If there is no error message take the last line from the error (stack) |
107 | | - // As this generally contains the actual error |
108 | | - if (!hasErrorMessage) { |
109 | | - errorMessage = errorLines[errorLines.length - 1].trim() + '\n' + errorMessage; |
110 | | - } |
| 99 | + if (typeof errorResponse[0].message !== 'string' || errorResponse[0].message.length === 0) { |
| 100 | + errorResponse[0].message = errorResponse[0].traceback.split(/\r?\n/g).pop(); |
| 101 | + } |
| 102 | + let errorMessage = errorResponse[0].message + '\n' + errorResponse[0].traceback; |
111 | 103 |
|
112 | | - this._commandReject(`Refactor failed. ${errorMessage}`); |
113 | | - } |
| 104 | + if (this._startedSuccessfully) { |
| 105 | + this._commandReject(`Refactor failed. ${errorMessage}`); |
114 | 106 | } |
115 | 107 | else { |
116 | | - this._initializeReject(`Refactor failed. ${dataStr}`); |
| 108 | + this._initializeReject(`Refactor failed. ${errorMessage}`); |
117 | 109 | } |
118 | 110 | } |
119 | 111 | private handleError(error: Error) { |
|