Skip to content

Commit

Permalink
Add context to "Overlapping ranges are not allowed!" error that will …
Browse files Browse the repository at this point in the history
…be included in issue description

I'm tired of getting so many duplicate issues without even knowing what's going on - this should help.
  • Loading branch information
J-Fields committed Jul 2, 2021
1 parent 7b3b17b commit cd9d1bf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/common/motion/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ export class Cursor {
}

public toString(): string {
return `[ ${this.start.toString()} | ${this.stop.toString()}]`;
return `[${this.start.toString()} | ${this.stop.toString()}]`;
}
}
14 changes: 14 additions & 0 deletions src/taskQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class TaskQueue {
if (err instanceof Error) {
const reportButton = 'Report bug';
const stack = err.stack;

// TODO: this is a bit janky - should probably create custom ContextualError class or find a library
// tslint:disable:no-string-literal
const context = err['context'];

vscode.window
.showErrorMessage(err.message, reportButton)
.then((picked: string | undefined) => {
Expand All @@ -20,6 +25,15 @@ class TaskQueue {
if (stack) {
body += `\n\n<details><summary>Stack trace</summary>\n\n\`\`\`\n${stack}\n\`\`\`\n\n</details>`;
}
if (context) {
body += `\n\n<details><summary>Additional context</summary>\n\n\`\`\``;
for (const prop in context) {
if (context.hasOwnProperty(prop)) {
body += `\n${prop}: ${JSON.stringify(context[prop], undefined, 2)}`;
}
}
body += `\n\`\`\`\n\n</details>`;
}
vscode.commands.executeCommand(
'vscode.open',
vscode.Uri.parse(
Expand Down
21 changes: 16 additions & 5 deletions src/transformations/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,22 @@ export async function executeTransformations(
* (this is primarily necessary for multi-cursor mode, since most
* actions will trigger at most one text operation).
*/
await vimState.editor.edit((edit) => {
for (const command of textTransformations) {
doTextEditorEdit(command, edit);
}
});
try {
await vimState.editor.edit((edit) => {
for (const command of textTransformations) {
doTextEditorEdit(command, edit);
}
});
} catch (e) {
e.context = {
currentMode: Mode[vimState.currentMode],
cursors: vimState.cursors.map((cursor) => cursor.toString()),
actionsRunPressedKeys: vimState.recordedState.actionsRunPressedKeys,
actionsRun: vimState.recordedState.actionsRun.map((action) => action.constructor.name),
textTransformations,
};
throw e;
}
}
}

Expand Down

0 comments on commit cd9d1bf

Please sign in to comment.