Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey committed Jan 19, 2024
1 parent 56d612e commit 299b893
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 45 deletions.
27 changes: 0 additions & 27 deletions packages/cursorless-vscode/src/keyboard/grammar/UniqueWorkQueue.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ import {
NEXT,
getAcceptableTokenTypes,
} from "./getAcceptableTokenTypes";
import { forEach, isEqual } from "lodash";
import produce from "immer";
import { isEqual } from "lodash";
import { stringifyTokens } from "./stringifyTokens";

interface TestCase {
/**
* The tokens to feed to the parser before checking for acceptable token types
*/
tokens: KeyDescriptor[];

/**
* Expect these token types to be acceptable; note that this list doesn't need
* to include all acceptable token types, just the ones that we want to test
* for.
*/
expected: AcceptableTokenType[];
}

Expand Down Expand Up @@ -125,7 +133,7 @@ suite("keyboard.getAcceptableTokenTypes", () => {
});

testCases.forEach(({ tokens, expected }) => {
test(`should parse \`${stringifyTokens(tokens)}\``, () => {
test(`after \`${stringifyTokens(tokens)}\``, () => {
parser.feed(tokens);
for (const value of expected) {
const candidates = getAcceptableTokenTypes(parser).filter(
Expand All @@ -141,22 +149,10 @@ suite("keyboard.getAcceptableTokenTypes", () => {
};
assert(
candidates.some((result) => isEqual(result, fullValue)),
JSON.stringify(produce(candidates, replaceSymbols), null, 2),
"Relevant candidates (note that symbols will be missing):\n" +
JSON.stringify(candidates, null, 2),
);
}
});
});
});

/**
* Deep search and replaces the given property value "prevVal" with "newVal"
*/
function replaceSymbols(object: any) {
forEach(object, (val, key) => {
if (typeof val === "symbol") {
object[key] = val.toString();
} else if (typeof val === "object") {
replaceSymbols(val);
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@ import { isEqual, times } from "lodash";
import { CommandRulePostProcessor } from "./CommandRulePostProcessor";
import { DefaultMap, uniqWithHash } from "@cursorless/common";
import { KeyboardCommandHandler } from "../KeyboardCommandHandler";
import { TokenType } from "../TokenTypeHelpers";

export interface AcceptableTokenType {
type: any;
/**
* The token type, eg "color".
*/
type: TokenType;

/**
* The command that wants the token type
*/
command: keyof KeyboardCommandHandler;

/**
* A partial argument for the command that wants the token type, where
* {@link NEXT} indicates where the next token would go and {@link MISSING}
* indicates arguments that haven't been typed yet.
*/
partialArg: any;
}

Expand Down

0 comments on commit 299b893

Please sign in to comment.