GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix for #244 · millin/pythonVSCode@c45bdd9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pythonFiles
    • refactor.py
  • src/client
    • providers
      • simpleRefactorProvider.ts
    • refactor
      • proxy.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pythonFiles/refactor.py‎

Copy file name to clipboardExpand all lines: pythonFiles/refactor.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,13 @@ def watch(self):
247247
message = ""
248248
try:
249249
message = ex.message
250-
except:
250+
except:
251251
pass
252-
252+
253253
message = message + ' \n' + traceback.format_exc()
254-
sys.stderr.write('$ERROR' + str(len(message)) + ':' + message)
254+
jsonMessage = {'error': True, 'message': message,
255+
'traceback': traceback.format_exc()}
256+
sys.stderr.write(json.dumps(jsonMessage))
255257
sys.stderr.flush()
256258

257259
if __name__ == '__main__':
Collapse file

‎src/client/providers/simpleRefactorProvider.ts‎

Copy file name to clipboardExpand all lines: src/client/providers/simpleRefactorProvider.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ function extractName(extensionDir: string, textEditor: vscode.TextEditor, range:
103103
errorMessage = error;
104104
}
105105
if (typeof error === 'object' && error.message) {
106-
errorMessage = `Refactor failed, ${error.message}`;
106+
errorMessage = error.message;
107107
}
108108
outputChannel.appendLine('#'.repeat(10) + 'Refactor Output' + '#'.repeat(10));
109109
outputChannel.appendLine('Error in refactoring:\n' + errorMessage);
110-
vscode.window.showErrorMessage('Cannot perform refactoring using selected element(s)');
110+
vscode.window.showErrorMessage(`Cannot perform refactoring using selected element(s). (${errorMessage})`);
111111
return Promise.reject(error);
112112
});
113113
}
Collapse file

‎src/client/refactor/proxy.ts‎

Copy file name to clipboardExpand all lines: src/client/refactor/proxy.ts
+21-29Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ export class RefactorProxy extends vscode.Disposable {
3636
this._process = null;
3737
}
3838
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 };
4040
return this.sendCommand<T>(JSON.stringify(command), REFACTOR.ExtractVariable);
4141
}
4242
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 };
4444
return this.sendCommand<T>(JSON.stringify(command), REFACTOR.ExtractVariable);
45-
}
45+
}
4646
private sendCommand<T>(command: string, telemetryEvent: string): Promise<T> {
4747
let timer = new Delays();
4848
return this.initialize(this.pythonSettings.pythonPath).then(() => {
@@ -83,37 +83,29 @@ export class RefactorProxy extends vscode.Disposable {
8383
});
8484
}
8585
private handleStdError(data: string) {
86+
// Possible there was an exception in parsing the data returned
87+
// So append the data then parse it
8688
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+
}
10598

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;
111103

112-
this._commandReject(`Refactor failed. ${errorMessage}`);
113-
}
104+
if (this._startedSuccessfully) {
105+
this._commandReject(`Refactor failed. ${errorMessage}`);
114106
}
115107
else {
116-
this._initializeReject(`Refactor failed. ${dataStr}`);
108+
this._initializeReject(`Refactor failed. ${errorMessage}`);
117109
}
118110
}
119111
private handleError(error: Error) {

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.