Skip to content

Commit efb8ed3

Browse files
committed
test(fsharp): expect Foo.add qualified name after npm grammar bump (#1162)
The WASM tree-sitter-fsharp signature grammar was upgraded from v0.1.0 to v0.3.0 in adcaf40. v0.3.0 emits `module_defn` for nested `module Foo = ...` blocks (v0.1.0 emitted ERROR nodes), so the existing qualification logic now fires for the WASM engine too — `val` symbols get the parent module prefix in both engines. The signature test still expected the pre-bump behaviour (bare `add`), which made it fail in CI where the grammar bump landed. Update the assertion to lock in engine parity: - assert the qualified `Foo.add` function and the outer `Foo` module - assert the unqualified `add` is NOT emitted, so any future regression where the walker drops the enclosing module is caught Also refresh the `module_defn` comment in src/extractors/fsharp.ts — it still claimed the WASM grammar emitted ERROR nodes for this construct, which became stale after the v0.3.0 bump.
1 parent 576eab7 commit efb8ed3

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/extractors/fsharp.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ function walkFSharpNode(
5151
break;
5252
case 'module_defn':
5353
// Nested signature module (`module Foo = ...`) in `.fsi` files,
54-
// produced by the cargo 0.3.0 grammar. The WASM 0.1.0 signature
55-
// grammar currently emits ERROR nodes for this construct, so it
56-
// never reaches this branch there (tracked in #1161). When it
57-
// does fire, accumulate the dotted module path so nested `val`
58-
// declarations are qualified as `Outer.Inner.foo`.
54+
// emitted by both the WASM (npm ionide tarball v0.3.0) and cargo
55+
// v0.3.0 tree-sitter-fsharp signature grammars. Accumulate the
56+
// dotted module path so nested `val` declarations are qualified
57+
// as `Outer.Inner.foo` in parity with the native engine.
5958
nextModule = handleModuleDefn(node, ctx, currentModule);
6059
break;
6160
case 'function_declaration_left':

tests/parsers/fsharp-signature.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,21 @@ describe('F# signature (.fsi) parser', () => {
4242
});
4343

4444
it('extracts val declarations nested inside a module signature', () => {
45-
// The WASM tree-sitter-fsharp signature grammar (currently v0.3.0) does
46-
// NOT yet produce a `module_defn` for `module Foo = ...` — it emits
47-
// ERROR nodes and the `val` declarations float to the top level (so
48-
// they're indexed as `add`, not `Foo.add`). The cargo 0.3.0 grammar
49-
// parses it correctly and the Rust extractor qualifies as `Foo.add`.
50-
// The WASM grammar fix is tracked under #1161; once the signature
51-
// grammar emits `module_defn` for nested modules, this assertion
52-
// should be updated to expect `Foo.add` to match the native engine.
45+
// Both the WASM (npm ionide tarball v0.3.0) and the cargo v0.3.0
46+
// tree-sitter-fsharp signature grammars emit `module_defn` for
47+
// `module Foo = ...`, so `val` declarations nested inside are
48+
// qualified with the module path (`Foo.add`) in both engines. The
49+
// outer `module Foo` is also indexed as a `module` definition.
5350
const { symbols } = parseFSi(`module Foo =\n val add : int -> int\n`);
5451
expect(symbols.definitions).toContainEqual(
52+
expect.objectContaining({ name: 'Foo', kind: 'module' }),
53+
);
54+
expect(symbols.definitions).toContainEqual(
55+
expect.objectContaining({ name: 'Foo.add', kind: 'function' }),
56+
);
57+
// The unqualified name must NOT appear — that would mean the walker
58+
// failed to thread the enclosing module through to `handleValueDefinition`.
59+
expect(symbols.definitions).not.toContainEqual(
5560
expect.objectContaining({ name: 'add', kind: 'function' }),
5661
);
5762
});

0 commit comments

Comments
 (0)