Skip to content

Commit a91a8fc

Browse files
Improves map formatting (#514)
1 parent 4b0ee37 commit a91a8fc

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

packages/language-support/src/formatting/formatting.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ export class TreePrintVisitor extends CypherCmdParserVisitor<void> {
726726
this.breakLine();
727727
const optionsGrp = this.startGroup();
728728
this.visit(ctx.OPTIONS());
729+
this.setOneItemProperty();
729730
const optionIndent = this.addIndentation();
730731
this.visit(ctx.mapOrParameter());
731732
this.removeIndentation(optionIndent);
@@ -2111,6 +2112,7 @@ export class TreePrintVisitor extends CypherCmdParserVisitor<void> {
21112112
this._visit(ctx.propertyKeyName(i));
21122113
const mapValueIndent = this.addIndentation();
21132114
this._visitTerminalRaw(ctx.COLON(i));
2115+
this.setOneItemProperty();
21142116
this._visit(ctx.expression(i));
21152117
if (i < n - 1) {
21162118
this._visit(ctx.COMMA(i));

packages/language-support/src/tests/formatting/commands.test.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,19 @@ ON EACH [a.name]`.trimStart();
110110
const expected = `CREATE CONSTRAINT aaaaaa
111111
FOR (aaaaaa:aaaaaa)
112112
REQUIRE (aaaaaa.aaaaaa) IS UNIQUE
113-
OPTIONS
114-
{
115-
aaaaaa: "20z9vakp",
116-
aaaaaa:
117-
{
118-
aaaaaa: ["aotV0uiw", "SCxu0Vyn", "ekTx6ngu"],
119-
aaaaaa: ["WqAr9IvS", "j5fYJwuN"],
120-
aaaaaa: ["HUDXLCRN", "LUfKWGc7"],
121-
aaaaaa: ["qbk3JzMe", "Ca4n1Ea9", "I96Uwq16"],
122-
aaaaaa: ["zcBcWjoJ", "dz78begI"],
123-
aaaaaa: ["MIADLwls", "qkacQgzY", "wYYAgiGo"],
124-
aaaaaa: ["Jmw0tXjZ", "ALiXrHno", "QRYTGYFd"],
125-
aaaaaa: ["EEJJKZGC", "GGDt2msc"]
126-
}
127-
}`;
113+
OPTIONS {
114+
aaaaaa: "20z9vakp",
115+
aaaaaa: {
116+
aaaaaa: ["aotV0uiw", "SCxu0Vyn", "ekTx6ngu"],
117+
aaaaaa: ["WqAr9IvS", "j5fYJwuN"],
118+
aaaaaa: ["HUDXLCRN", "LUfKWGc7"],
119+
aaaaaa: ["qbk3JzMe", "Ca4n1Ea9", "I96Uwq16"],
120+
aaaaaa: ["zcBcWjoJ", "dz78begI"],
121+
aaaaaa: ["MIADLwls", "qkacQgzY", "wYYAgiGo"],
122+
aaaaaa: ["Jmw0tXjZ", "ALiXrHno", "QRYTGYFd"],
123+
aaaaaa: ["EEJJKZGC", "GGDt2msc"]
124+
}
125+
}`;
128126
verifyFormatting(query, expected);
129127
});
130128

@@ -176,4 +174,16 @@ REQUIRE a.id IS UNIQUE
176174
OPTIONS {constraintName: 'Athlete_Id_Unique'}`;
177175
verifyFormatting(query, expected);
178176
});
177+
test('OPTION should be able to have nice map print', () => {
178+
const query =
179+
"CREATE DATABASE testdb OPTIONS {existingData: 'use', seedURI:'s3://bucketpath', seedConfig: 'region=eu-west-1', seedCredentials: 'foo;bar'};";
180+
const expected = `CREATE DATABASE testdb
181+
OPTIONS {
182+
existingData: 'use',
183+
seedURI: 's3://bucketpath',
184+
seedConfig: 'region=eu-west-1',
185+
seedCredentials: 'foo;bar'
186+
};`;
187+
verifyFormatting(query, expected);
188+
});
179189
});

packages/language-support/src/tests/formatting/edgecases.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,10 @@ RETURN graphName, nodeCount, relationshipCount, createMillis;`;
540540
"qk5jpmGl", // Name of the projected graph
541541
["TB4Tvv6q", "2iCI1Rll", "kaLEqBxX"], // Node labels to include
542542
{
543-
connection:
544-
{
545-
type: "R3e8WLkh", // Include all relationships
546-
orientation: "weFW44Gy" // Treat relationships as undirected
547-
}
543+
connection: {
544+
type: "R3e8WLkh", // Include all relationships
545+
orientation: "weFW44Gy" // Treat relationships as undirected
546+
}
548547
}
549548
)
550549
YIELD graphName, nodeCount, relationshipCount, createMillis

0 commit comments

Comments
 (0)