Skip to content

Commit 1ca0217

Browse files
committed
Accept 'for' keyword in surface bindings; recognise enum unions; bump to 0.1.6
1 parent 324fdcb commit 1ca0217

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

extensions/allium/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "allium-vscode",
33
"displayName": "Allium Tools for VS Code",
44
"description": "Allium language support for VS Code: diagnostics, refactors, hover, definitions, formatting, and more.",
5-
"version": "0.1.5",
5+
"version": "0.1.6",
66
"license": "MIT",
77
"publisher": "juxt",
88
"repository": {

extensions/allium/src/language-tools/analyzer.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ function findSurfaceActorLinkIssues(
15581558
const surfaceBlocks = blocks.filter((block) => block.kind === "surface");
15591559
const referencedActors = new Set<string>();
15601560
const forPattern =
1561-
/^\s*facing\s+[A-Za-z_][A-Za-z0-9_]*\s*:\s*([A-Za-z_][A-Za-z0-9_]*)\s*$/m;
1561+
/^\s*(?:facing|for)\s+[A-Za-z_][A-Za-z0-9_]*\s*:\s*([A-Za-z_][A-Za-z0-9_]*)\s*$/m;
15621562

15631563
for (const surface of surfaceBlocks) {
15641564
const match = surface.body.match(forPattern);
@@ -1645,17 +1645,17 @@ function findSurfaceBindingUsageIssues(
16451645
for (const surface of surfaceBlocks) {
16461646
const body = surface.body;
16471647
const forMatch = body.match(
1648-
/^\s*facing\s+([A-Za-z_][A-Za-z0-9_]*)\s*:\s*[A-Za-z_][A-Za-z0-9_]*(?:\s+with\s+.+)?\s*$/m,
1648+
/^\s*(?:facing|for)\s+([A-Za-z_][A-Za-z0-9_]*)\s*:\s*[A-Za-z_][A-Za-z0-9_]*(?:\s+with\s+.+)?\s*$/m,
16491649
);
16501650
const contextMatch = body.match(
16511651
/^\s*context\s+([A-Za-z_][A-Za-z0-9_]*)\s*:\s*[A-Za-z_][A-Za-z0-9_]*(?:\s+with\s+.+)?\s*$/m,
16521652
);
16531653
const bindings = [
16541654
...(forMatch
1655-
? [{ name: forMatch[1], source: "facing", line: forMatch[0] }]
1655+
? [{ name: forMatch[1], sourcePattern: "(?:facing|for)", sourceLabel: "for", line: forMatch[0] }]
16561656
: []),
16571657
...(contextMatch
1658-
? [{ name: contextMatch[1], source: "context", line: contextMatch[0] }]
1658+
? [{ name: contextMatch[1], sourcePattern: "context", sourceLabel: "context", line: contextMatch[0] }]
16591659
: []),
16601660
];
16611661

@@ -1670,7 +1670,7 @@ function findSurfaceBindingUsageIssues(
16701670
}
16711671

16721672
const linePattern = new RegExp(
1673-
`^\\s*${binding.source}\\s+${escapeRegex(binding.name)}\\s*:`,
1673+
`^\\s*${binding.sourcePattern}\\s+${escapeRegex(binding.name)}\\s*:`,
16741674
"m",
16751675
);
16761676
const lineMatch = body.match(linePattern);
@@ -1688,7 +1688,7 @@ function findSurfaceBindingUsageIssues(
16881688
absoluteOffset,
16891689
absoluteOffset + binding.name.length,
16901690
"allium.surface.unusedBinding",
1691-
`Surface '${surface.name}' binding '${binding.name}' from '${binding.source}' is not used in the surface body.`,
1691+
`Surface '${surface.name}' binding '${binding.name}' from '${binding.sourceLabel}' is not used in the surface body.`,
16921692
"warning",
16931693
),
16941694
);
@@ -2972,7 +2972,7 @@ function collectTypeSchemas(
29722972
field = fieldPattern.exec(body)
29732973
) {
29742974
const name = field[1];
2975-
const rhs = field[2].trim();
2975+
const rhs = field[2].replace(/\s*--.*$/, "").trim();
29762976
if (
29772977
/^[A-Za-z_][A-Za-z0-9_]*\s+for\s+this\s+[A-Za-z_][A-Za-z0-9_]*$/.test(
29782978
rhs,
@@ -2994,6 +2994,10 @@ function collectTypeSchemas(
29942994
fields.set(name, { typeName: genericMatch[2], isCollection: true });
29952995
continue;
29962996
}
2997+
if (/^[a-z_][a-z0-9_]*(?:\s*\|\s*[a-z_][a-z0-9_]*)+$/.test(cleaned)) {
2998+
fields.set(name, { typeName: "__enum", isCollection: false });
2999+
continue;
3000+
}
29973001
const direct = cleaned.match(/^([A-Za-z_][A-Za-z0-9_]*)$/);
29983002
if (direct) {
29993003
fields.set(name, { typeName: direct[1], isCollection: false });
@@ -3032,7 +3036,7 @@ function collectRulePathSuffixes(
30323036
function collectSurfaceBindingTypes(body: string): Map<string, string> {
30333037
const bindings = new Map<string, string>();
30343038
const patterns = [
3035-
/^\s*facing\s+([A-Za-z_][A-Za-z0-9_]*)\s*:\s*([A-Za-z_][A-Za-z0-9_]*)/m,
3039+
/^\s*(?:facing|for)\s+([A-Za-z_][A-Za-z0-9_]*)\s*:\s*([A-Za-z_][A-Za-z0-9_]*)/m,
30363040
/^\s*context\s+([A-Za-z_][A-Za-z0-9_]*)\s*:\s*([A-Za-z_][A-Za-z0-9_]*)/m,
30373041
];
30383042
for (const pattern of patterns) {

0 commit comments

Comments
 (0)