mirror of
https://github.com/Silverquark/dance.git
synced 2024-10-26 20:08:51 +03:00
Fix count issue; make test debugging slightly easier for error cases.
This commit is contained in:
parent
b4f98a4167
commit
c6ea85dbfc
@ -134,6 +134,11 @@ export interface InputDescrMap {
|
|||||||
* Defines a command's behavior, as well as its inputs.
|
* Defines a command's behavior, as well as its inputs.
|
||||||
*/
|
*/
|
||||||
export class CommandDescriptor<Input extends InputKind = InputKind> {
|
export class CommandDescriptor<Input extends InputKind = InputKind> {
|
||||||
|
/**
|
||||||
|
* Whether errors in command executions should lead to hard exceptions.
|
||||||
|
*/
|
||||||
|
public static throwOnError = false;
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
public readonly command: Command,
|
public readonly command: Command,
|
||||||
public readonly flags: CommandFlags,
|
public readonly flags: CommandFlags,
|
||||||
@ -269,6 +274,10 @@ export class CommandDescriptor<Input extends InputKind = InputKind> {
|
|||||||
argument,
|
argument,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!this.command.startsWith("dance.count.")) {
|
||||||
|
extension.currentCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
editorState.ignoreSelectionChanges = true;
|
editorState.ignoreSelectionChanges = true;
|
||||||
|
|
||||||
let result;
|
let result;
|
||||||
@ -283,6 +292,11 @@ export class CommandDescriptor<Input extends InputKind = InputKind> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (CommandDescriptor.throwOnError) {
|
||||||
|
console.error(e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
let message = e;
|
let message = e;
|
||||||
|
|
||||||
if (typeof e === "object" && e !== null && e.constructor === Error) {
|
if (typeof e === "object" && e !== null && e.constructor === Error) {
|
||||||
@ -336,10 +350,6 @@ export class CommandDescriptor<Input extends InputKind = InputKind> {
|
|||||||
editor.revealRange(new vscode.Range(position, position));
|
editor.revealRange(new vscode.Range(position, position));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.command.startsWith("dance.count.")) {
|
|
||||||
extension.currentCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remainingNormalCommands === 1) {
|
if (remainingNormalCommands === 1) {
|
||||||
remainingNormalCommands = 0;
|
remainingNormalCommands = 0;
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import * as path from "path";
|
|||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
|
|
||||||
import { Command } from "../../commands";
|
import { Command } from "../../commands";
|
||||||
|
import { CommandDescriptor } from "../../src/commands";
|
||||||
import { extensionState } from "../../src/extension";
|
import { extensionState } from "../../src/extension";
|
||||||
import { SelectionBehavior } from "../../src/state/extension";
|
import { SelectionBehavior } from "../../src/state/extension";
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ export namespace testCommands {
|
|||||||
readonly initialContent: string;
|
readonly initialContent: string;
|
||||||
readonly mutations: readonly Mutation[];
|
readonly mutations: readonly Mutation[];
|
||||||
readonly selectionBehavior: SelectionBehavior;
|
readonly selectionBehavior: SelectionBehavior;
|
||||||
|
readonly allowErrors: boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,10 +99,11 @@ function stringifySelection(document: vscode.TextDocument, selection: vscode.Sel
|
|||||||
|
|
||||||
async function testCommands(
|
async function testCommands(
|
||||||
editor: vscode.TextEditor,
|
editor: vscode.TextEditor,
|
||||||
{ initialContent, mutations, selectionBehavior }: testCommands.Options,
|
{ initialContent, mutations, selectionBehavior, allowErrors }: testCommands.Options,
|
||||||
) {
|
) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
extensionState._selectionBehavior = selectionBehavior;
|
extensionState._selectionBehavior = selectionBehavior;
|
||||||
|
CommandDescriptor.throwOnError = !allowErrors;
|
||||||
|
|
||||||
const content = getPlainContent(initialContent);
|
const content = getPlainContent(initialContent);
|
||||||
const document = editor.document;
|
const document = editor.document;
|
||||||
@ -214,6 +217,7 @@ suite("Running commands", function () {
|
|||||||
initialContent: `{0}f|{0}oo`,
|
initialContent: `{0}f|{0}oo`,
|
||||||
mutations: [{ contentAfterMutation: `{0}fo|{0}o`, commands: [Command.rightExtend] }],
|
mutations: [{ contentAfterMutation: `{0}fo|{0}o`, commands: [Command.rightExtend] }],
|
||||||
selectionBehavior: SelectionBehavior.Character,
|
selectionBehavior: SelectionBehavior.Character,
|
||||||
|
allowErrors: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -223,6 +227,7 @@ suite("Running commands", function () {
|
|||||||
initialContent: `|{0}foo`,
|
initialContent: `|{0}foo`,
|
||||||
mutations: [{ contentAfterMutation: `|{0}foo`, commands: [Command.rightExtend] }],
|
mutations: [{ contentAfterMutation: `|{0}foo`, commands: [Command.rightExtend] }],
|
||||||
selectionBehavior: SelectionBehavior.Character,
|
selectionBehavior: SelectionBehavior.Character,
|
||||||
|
allowErrors: false,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (
|
if (
|
||||||
@ -325,6 +330,7 @@ suite("Running commands", function () {
|
|||||||
initialContent,
|
initialContent,
|
||||||
mutations: [{ contentAfterMutation, commands }],
|
mutations: [{ contentAfterMutation, commands }],
|
||||||
selectionBehavior,
|
selectionBehavior,
|
||||||
|
allowErrors: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
|
9
test/suite/commands/objects.word.caret
Normal file
9
test/suite/commands/objects.word.caret
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
he|{0}l{0}lo world
|
||||||
|
|
||||||
|
//== 0 > 1
|
||||||
|
//= {"command": "dance.objects.performSelection", "args": [{"object": "word", "action": "select", "inner": true}]}
|
||||||
|
{0}hello|{0} world
|
||||||
|
|
||||||
|
//== 1 > 2
|
||||||
|
//= {"command": "dance.objects.performSelection", "args": [{"object": "word", "action": "select", "inner": true}]}
|
||||||
|
{0}hello|{0} world
|
Loading…
Reference in New Issue
Block a user