interplane.Get Omega
Read in your language

vscode-omega

aien-dev/vscode-omega

Brought by drakestapleton

GitHub aien-dev/vscode-omega#1 (code only)

closed derived 1519f9d37c0aeb02 #1

Imported from GitHub aien-dev/vscode-omega#1 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 885db1b2f75c64b4c138bbf9cd4dbb91970340fc · Head 94dd1773cf871b704c2649070fed66ae8640511c

Apply it

git checkout -b patch-1519f9d37c0aeb02 885db1b2f75c64b4c138bbf9cd4dbb91970340fc
curl -fsSL https://interplane.io/drakestapleton/vscode-omega/patches/1519f9d37c0aeb02.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/vscode-omega
1
94dd1773cf871b704c2649070fed66ae8640511c
{"kind":"github-import","owner":"aien-dev","repo":"vscode-omega","number":1,"url":"https://github.com/aien-dev/vscode-omega/pull/1","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:41:02Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ddbfd1a..745fe42 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -69,11 +69,11 @@ jobs:
           npm ci --ignore-scripts
           (cd node_modules/tree-sitter-cli && node install.js)
           sha256sum -c tree-sitter-cli.sha256
-          sh scripts/coverage.sh "$RUNNER_TEMP/omega-mv" "$OMC" > "$RUNNER_TEMP/coverage.tsv"
+          sh scripts/coverage.sh --omc "$OMC" "$RUNNER_TEMP/omega-mv" > "$RUNNER_TEMP/coverage.tsv"
           grep '^COVERAGE' "$RUNNER_TEMP/coverage.tsv"
           awk -F'\t' '$2=="omc=accept"{print $1}' "$RUNNER_TEMP/coverage.tsv" > "$RUNNER_TEMP/accepted.txt"
           wc -l < "$RUNNER_TEMP/accepted.txt"
-      - name: TextMate vs tree-sitter agreement (omc-accepted files must agree 100%; all files reported)
+      - name: TextMate vs tree-sitter agreement (omc-accepted files and test/fixtures must agree 100%; all files reported)
         run: |
           set -eu
           node test/agree.js --ts "$RUNNER_TEMP/ts" --src "$RUNNER_TEMP/omega-mv" --min 0 > agree-all.txt
@@ -81,6 +81,11 @@ jobs:
           node test/agree.js --ts "$RUNNER_TEMP/ts" --src "$RUNNER_TEMP/omega-mv" --files "$RUNNER_TEMP/accepted.txt" --min 100 > agree-accepted.txt \
             || { cat agree-accepted.txt; exit 1; }
           tail -2 agree-accepted.txt
+          # test/fixtures: omc-accepted edge cases (names that start with note, note(...), note in text).
+          for f in test/fixtures/*.om; do "$OMC" < "$f" > /dev/null || { echo "omc refuses $f"; exit 1; }; done
+          node test/agree.js --ts "$RUNNER_TEMP/ts" --src test/fixtures --min 100 > agree-fixtures.txt \
+            || { cat agree-fixtures.txt; exit 1; }
+          tail -2 agree-fixtures.txt
           { echo '```'; echo "all files:"; tail -2 agree-all.txt; echo "omc-accepted files:"; tail -2 agree-accepted.txt; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
       - name: Negative control 3, a TextMate grammar without the type words must fail agreement
         run: |
diff --git a/README.md b/README.md
index d930d8c..8279dad 100644
--- a/README.md
+++ b/README.md
@@ -86,22 +86,36 @@ All of this runs in CI on GitHub's `ubuntu-24.04-arm` runner, with `omc` born fr
   `omc error 16` on line 3 and an accepted one gets none, and that Format Document returns `om2 fmt`'s text.
 - `test/agree.js`: the TextMate grammar against
   [tree-sitter-omega](https://github.com/aien-dev/tree-sitter-omega)'s highlight query, token by token,
-  over every `*.om` file in omega-mv. On the files `omc` accepts the two must agree on every token;
-  CI fails otherwise.
+  over every `*.om` file in omega-mv and over [`test/fixtures/`](test/fixtures) (edge cases `omc`
+  accepts: names that start with `note`, `note(...)`, `note` inside text, a function named `field`
+  next to a `layout`). On the files `omc` accepts the two must agree on every token; CI fails otherwise.
 - Negative controls that must fail: the unit tests with a fake `omc` that accepts everything, the
   VS Code test with that fake `omc`, the agreement check with the type words removed from the
   TextMate grammar, and a package built without `.vscodeignore`, which must fail `test/check-vsix.sh`.
 
-MEASURED at omega-mv `e5b32567` and tree-sitter-omega `9b63612` (local run on a DGX Spark, 2026-10-27, and the
-same numbers in CI [run 40432889449](https://github.com/aien-dev/vscode-omega/actions/runs/40432889449)):
+MEASURED at omega-mv `e5b32567` with the TextMate grammar of this commit and the tree-sitter-omega
+commit in `tree-sitter-omega.ref` (local run on a DGX Spark, 2026-10-28; CI has not run on these
+commits yet):
 
 | files | tokens compared | TextMate and tree-sitter agree |
 |---|---:|---:|
-| 393 files `omc` accepts | 118,468 | 118,468 (100%) |
-| all 811 `*.om` files | 211,399 | 211,358 (99.98%) |
-
-The 41 disagreements are all in files `omc` refuses: malformed hex numbers, which the two grammars split
-differently, and incomplete test fixtures.
+| 393 omega-mv files `omc` accepts | 118,468 | 118,468 (100%) |
+| all 811 omega-mv `*.om` files | 211,404 | 211,358 (99.978%) |
+| 3 files in `test/fixtures/` | 108 | 108 (100%) |
+
+The 46 disagreements are all in files `omc` refuses: malformed hex numbers, which the two grammars split
+differently, and deliberately malformed test fixtures.
+
+The same check over every public aien-dev repository with Omega in it (948 files `omc` accepts, in 17
+of the 26 repositories measured, omega-rosetta at its `corpus/200` commit `a5b7330a`; list and
+commits in tree-sitter-omega's README): 423,864 of 423,864 tokens agree. Over all 357 omega-rosetta
+files, exercise stubs and `test.om` files included, 100,651 of 100,651 agree. With the previous
+grammars (TextMate here at `885db1b`, tree-sitter-omega `9b63612`) it was 423,733 of 423,797 on the
+accepted files: a function named `field` outside a layout (aienos.com `om/hive-render/render.om`) and a
+`note` inside text (babel `build/babel.om`). With the previous grammars `test/fixtures/` agreed on 108
+of 117 tokens.
+`test/agree.js` now converts tree-sitter's byte columns to the editor's UTF-16 columns, so a line with
+a non-ASCII character no longer compares the wrong tokens.
 
 Not tested: the extension on Windows or macOS, the `qemu-aarch64` wrapper path, and VS Code versions
 other than 1.90.0.
diff --git a/syntaxes/omega.tmLanguage.json b/syntaxes/omega.tmLanguage.json
index 7fa9133..3dff947 100644
--- a/syntaxes/omega.tmLanguage.json
+++ b/syntaxes/omega.tmLanguage.json
@@ -16,6 +16,9 @@
     {
       "include": "#function-header"
     },
+    {
+      "include": "#layout"
+    },
     {
       "include": "#assignment-target"
     },
@@ -29,7 +32,7 @@
   "repository": {
     "comment": {
       "name": "comment.line.note.omega",
-      "match": "(?:^|(?<=[ \\t]))note(?:[ \\t].*)?$"
+      "match": "(?:^|(?<=[ \\t]))note(?:[ \\t\\r()].*)?$"
     },
     "profile": {
       "match": "^\\s*(om2|ir)(?![A-Za-z0-9_])((?:[ \\t]+[A-Za-z_][A-Za-z0-9_]*)*)[ \\t]*$",
@@ -104,7 +107,7 @@
           }
         },
         {
-          "match": "^\\s*(global|text|const|struct|layout|field|abstract|holds)[ \\t]+([A-Za-z_][A-Za-z0-9_]*)(?!\\s*=(?!=))",
+          "match": "^\\s*(global|text|const|struct|abstract|holds)[ \\t]+([A-Za-z_][A-Za-z0-9_]*)(?!\\s*=(?!=))",
           "captures": {
             "1": {
               "name": "keyword.other.omega"
@@ -116,6 +119,43 @@
         }
       ]
     },
+    "layout": {
+      "comment": "`layout NAME SIZE`, `field` lines, `end`. `field` is a keyword only here: elsewhere an OM-1 unit may call a function named field.",
+      "begin": "^\\s*(layout)[ \\t]+([A-Za-z_][A-Za-z0-9_]*)(?!\\s*=(?!=))",
+      "beginCaptures": {
+        "1": {
+          "name": "keyword.other.omega"
+        },
+        "2": {
+          "name": "entity.name.type.omega"
+        }
+      },
+      "end": "^\\s*(end)(?![A-Za-z0-9_])",
+      "endCaptures": {
+        "1": {
+          "name": "keyword.other.omega"
+        }
+      },
+      "patterns": [
+        {
+          "include": "#comment"
+        },
+        {
+          "match": "^\\s*(field)[ \\t]+([A-Za-z_][A-Za-z0-9_]*)",
+          "captures": {
+            "1": {
+              "name": "keyword.other.omega"
+            },
+            "2": {
+              "name": "variable.other.member.omega"
+            }
+          }
+        },
+        {
+          "include": "#words"
+        }
+      ]
+    },
     "words": {
       "patterns": [
         {
diff --git a/test/agree.js b/test/agree.js
index b29881f..08ca54c 100755
--- a/test/agree.js
+++ b/test/agree.js
@@ -159,14 +159,17 @@ async function main() {
     for (const c of (caps.get(f) || new Map()).values()) {
       const tsc = TS_CLASS[c.name];
       if (!tsc) continue;
+      // tree-sitter columns count UTF-8 bytes; TextMate token indices count UTF-16 code units.
+      const line = lines[c.row] || '';
+      const col = Buffer.from(line, 'utf8').subarray(0, c.col).toString('utf8').length;
       const toks = tm[c.row] || [];
-      const t = toks.find((k) => k.startIndex <= c.col && c.col < k.endIndex);
+      const t = toks.find((k) => k.startIndex <= col && col < k.endIndex);
       const tmc = t ? tmClass(t.scopes) : 'plain';
       compared++;
       if (tmc === tsc) agree++;
       else {
-        const text = (lines[c.row] || '').slice(c.col).split(/[ \t]/)[0].slice(0, 24);
-        process.stdout.write(`${path.relative(srcDir, f)}\t${c.row + 1}:${c.col + 1}\t${text}\tts=${tsc}\ttm=${tmc}\n`);
+        const text = line.slice(col).split(/[ \t]/)[0].slice(0, 24);
+        process.stdout.write(`${path.relative(srcDir, f)}\t${c.row + 1}:${col + 1}\t${text}\tts=${tsc}\ttm=${tmc}\n`);
       }
     }
   }
diff --git a/test/fixtures/field-call.om b/test/fixtures/field-call.om
new file mode 100644
index 0000000..97d1c18
--- /dev/null
+++ b/test/fixtures/field-call.om
@@ -0,0 +1,17 @@
+note An OM-1 unit may name a function field: only a layout makes field a keyword.
+global buf uchar 64
+fn field a ulong to void
+put buf a 7
+end
+fn main to int
+b = ulong 1
+field add b 2
+field 4
+if ne get buf 3 7
+ret 1
+end
+if ne get buf 4 7
+ret 2
+end
+ret 0
+end
diff --git a/test/fixtures/layout.om b/test/fixtures/layout.om
new file mode 100644
index 0000000..7b6baf2
--- /dev/null
+++ b/test/fixtures/layout.om
@@ -0,0 +1,9 @@
+om2
+note field is a keyword on the lines of a layout.
+layout blk 8
+field lo uint at 0 little
+field hi uint at 4 big
+end
+fn main to int
+ret 0
+end
diff --git a/test/fixtures/notes.om b/test/fixtures/notes.om
new file mode 100644
index 0000000..dc6dc00
--- /dev/null
+++ b/test/fixtures/notes.om
@@ -0,0 +1,11 @@
+note names that start with note, a note with a parenthesis, and note inside text
+text msg " note "
+text two "x\nnote add three\nfn"
+fn main to int
+  note
+note(x) y
+notes = int 2
+noted = add notes int 1
+ret sub noted int 3
+end
+note
diff --git a/tree-sitter-omega.ref b/tree-sitter-omega.ref
index b30d453..f4204df 100644
--- a/tree-sitter-omega.ref
+++ b/tree-sitter-omega.ref
@@ -1 +1 @@
-commit 9b63612aa91cf9309a8194ce4b3286493f250142
+commit f9d8fb2e7d476529cb4c24be575e424293979a1f