Skip to content

fix(references): a local GROUP's field reached as Group.Field - #869

Merged
msarson merged 1 commit into
msarson:version-1.0.11from
geircodes:fix/group-field-dot-references
Nov 25, 2026
Merged

msarson merged 1 commit into
msarson:version-1.0.11from
geircodes:fix/group-field-dot-references

Conversation

@geircodes

Copy link
Copy Markdown
Contributor

Find All References on a field of a local GROUP reached as Group.Field

What happened

A procedure declares a GROUP without PRE() and uses its fields through the group label:

LoadIt     PROCEDURE()
Tally    GROUP
Rows        LONG(0)
Active       LONG(0)
           END
  CODE
  Tally.Rows += 1
  IF Tally.Rows > 10
    MESSAGE(Tally.Rows)
  END
  • From the declaration of Rows: only the declaration came back. None of the Tally.Rows uses were listed.
  • From Rows in Tally.Rows: Go to Definition lands on the right line, but References missed the procedure's own uses and listed every other X.Rows in the searched files instead (OrderLines.Rows, Summary.Rows, ... in unrelated procedures and modules).

Root cause

Two routes, each wrong in its own way.

  1. Plain-symbol route (cursor on the declaration). A field of a procedure-local GROUP resolves with scope local, not field. findReferencesInFile only matches the dotted StructureField form for field scope:

    } else if (scopeType === 'field' && (token.type === TokenType.StructureField || token.type === TokenType.Class)) {
        // Field reference via dot-notation: "QZipF.version" when searching for "version"

    With scope local the Tally.Rows token fell through to the object-prefix branch, which compares the first segment (tally) with the search word (rows) and drops it.

  2. Member route (cursor on Rows after the dot). provideMemberReferences resolves Tally.Rows to the right declaration through DottedAccessResolver, then treats Tally as a class: it builds a class family and scans for .Rows behind any receiver, so it lists unrelated groups and queues and misses Tally.Rows itself.

The fix

  • findReferencesInFile: when the symbol is a field of a GROUP, QUEUE, FILE or RECORD and is not field-scoped, a StructureField token matches when its last segment is the field and the segment before it is that structure's label (Tally.Rows, Outer.Tally.Rows):

    } else if (dotQualifier && token.type === TokenType.StructureField &&
               this.isQualifiedFieldAccess(token.value, dotQualifier, searchWordLower)) {
        // `Tally.Rows` when searching for the field Rows of `Tally GROUP`
        matchStart = token.start + token.value.length - searchWord.length;
        matchLength = searchWord.length;

    The existing line-range restriction for local scope still applies, so a same-named field of another procedure's group is not listed.

  • provideMemberReferences: when the resolved member is a field of such a structure declared in the current document, answer from the field's declaration through the plain route, so a use site lists exactly what the declaration lists.

  • A structure with the TYPE attribute is excluded (structureFieldQualifier): its fields are reached through the variables declared with it (MyQ.Name for MyQ QUEUE(BaseQ)), never through its own label, so narrowing to the label would lose them.

Testing

  • New server/src/test/ReferencesPrelessGroupField.test.ts, 6 tests: from the field declaration, from Rows in a use site, from Tally in a use site, from the group label, from another procedure's same-named field, and a QUEUE,TYPE field reached through an instance.
  • Without the fix 3 of them fail (declaration, use site, other group's field), with the symptoms above. The QUEUE,TYPE test guards against over-narrowing: an earlier draft without the TYPE check failed it.
  • ReferencesProvider.Perf309.test.ts caught an extra token fetch per scanned file in an earlier draft; the declaration-file lookup is now lazy and only runs for a field of a GROUP/QUEUE/FILE/RECORD.
  • Server suite: 4625 passing, 3 pending, 0 failing.

Scope: deliberately left out

  • 'text' & Group.Field is split by the tokenizer. The ReferenceVariable pattern /&\s*[A-Za-z_][A-Za-z0-9_]*/ takes the concatenation operator, the space and the next name as one token (& Tally), so the .Field that follows becomes a bare Field token. In this PR those uses are still found from the field, by name, but the group label's References miss them. The same pattern makes References miss a plain variable after & (with a space) anywhere: MESSAGE('Rows: ' & Num) is not listed, MESSAGE('Rows: ' &Num) is. This is a tokenizer change with a much wider reach, so it is a separate issue.
  • Global and module-level groups declared in another file, and field-scoped symbols, keep their existing behaviour: the member-route redirect only applies when the field is declared in the current document, and the existing scopeType === 'field' branch is unchanged.
  • A field of a QUEUE,TYPE from its own declaration returns nothing, before and after this change. Not touched here.

🤖 Generated with Claude Code

Find All References on a field of a procedure-local GROUP without PRE()
listed only the declaration from the declaration, and from a use site
(Tally.Rows) every other X.Rows in the searched files instead of the
group's own uses. The plain route matched dotted StructureField tokens
only for field scope, and the member route treated the group as a class.
A field of a GROUP, QUEUE, FILE or RECORD now matches Group.Field by the
structure's label, and a use site answers from the field's declaration.
A TYPE structure is left out: its fields are reached through instances.

Tests: 6 new in ReferencesPrelessGroupField.test.ts, 3 fail without the
fix. Server suite: 4625 passing, 3 pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@msarson
msarson merged commit 439107d into msarson:version-1.0.11 Nov 25, 2026
1 check passed
@geircodes
geircodes deleted the fix/group-field-dot-references branch November 25, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants