Skip to content

Commit e5fce66

Browse files
Transform implicit string literal insert into explicit insert actions when sibling statements are present
1 parent b3691a0 commit e5fce66

11 files changed

Lines changed: 83 additions & 34 deletions

out/lib.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/snippetFormatter.js

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/talonFormatter.js

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/treeSitterFormatter.js

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export interface Logger {
3434
log(message: string): void;
3535
warn(message: string): void;
3636
error(message: string): void;
37+
}
38+
export interface TestLogger extends Logger {
3739
getEntries(): readonly LoggerEntry[];
3840
}
3941
export interface DebugLogger {

out/util/FilePatternError.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export declare class FilePatternError extends Error {
2+
messages: string[];
3+
name: string;
4+
constructor(messages: string[]);
5+
}

out/util/createLogger.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import type { DebugLogger, Logger } from "../types.js";
1+
import type { DebugLogger, Logger, TestLogger } from "../types.js";
22
export declare function createLogger(quiet?: boolean): Logger;
3+
export declare function createTestLogger(): TestLogger;
34
export declare function createDebugLogger(debug: boolean): DebugLogger;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cursorless/talon-tools",
3-
"version": "0.4.1",
3+
"version": "0.5.0",
44
"description": "Linting and formatting tools for Talon and Cursorless",
55
"author": "Cursorless Dev",
66
"license": "MIT",

src/talon/talonFormatter.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ class TalonFormatter {
223223
case "choice":
224224
return node.children.map((n) => this.getNodeText(n)).join(" ");
225225

226+
case "string":
227+
return formatString(node);
228+
226229
case "tag_binding":
227230
case "settings_binding":
228231
case "capture":
@@ -237,7 +240,6 @@ class TalonFormatter {
237240
case "variable":
238241
case "word":
239242
case "binary_operator":
240-
case "string":
241243
case "integer":
242244
case "float":
243245
case "start_anchor":
@@ -278,3 +280,18 @@ function rangeEqual(a: SyntaxNode, b: SyntaxNode): boolean {
278280
function isFirstChild(node: SyntaxNode): boolean {
279281
return node.id === node.parent?.children?.[0]?.id;
280282
}
283+
284+
function formatString(node: SyntaxNode): string {
285+
// A single string literal is allowed as syntactic sugar for the insert
286+
// action, but not in combination with other sibling statements.
287+
if (
288+
node.parent?.type === "expression_statement" &&
289+
node.parent.parent?.type === "block" &&
290+
rangeEqual(node, node.parent) &&
291+
node.parent.parent.children.length > 1
292+
) {
293+
return `insert(${node.text})`;
294+
}
295+
296+
return node.text;
297+
}

0 commit comments

Comments
 (0)