Skip to content

fix(references): Find All References on a ?Name field equate - #862

Merged
msarson merged 1 commit into
msarson:version-1.0.11from
geircodes:fix/field-equate-references
Nov 17, 2026
Merged

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

Conversation

@geircodes

Copy link
Copy Markdown
Contributor

Find All References on a ?Name field equate

What happened

Hover and F12 resolve a ?Name field equate to its control (#614), but Find All References on the same token returned nothing — from the USE(?Name) declaration in the WINDOW and from any use in code:

Window WINDOW('Pick'),AT(,,100,50)
       BUTTON('OK'),AT(4,30),USE(?OkButton)      ! FAR here: nothing
     END
  CODE
  ...
  SELECT(?OkButton)                               ! FAR here: nothing

There was no quick way to get from a control in the window structure to the code that uses it.

Root cause

provideReferencesUnfiltered starts from TokenHelper.getWordRangeAtPosition, which treats ? as a non-word character:

const wordRange = TokenHelper.getWordRangeAtPosition(document, position);
if (!wordRange) return null;

With the cursor on the sigil the range is empty and the search stops. On the name it yields OkButton without the ?, and the symbol ladder then looks for a symbol called OkButton, which nothing declares.

The fix

A terminal route ahead of the word ladder, the same shape as F12's #614 route:

const feqToken = TokenHelper.getFieldEquateTokenAt(this.tokenCache.getTokens(document), position.line, position.character);
if (feqToken) {
    this.trace({ route: 'fieldEquate', word: feqToken.value });
    return this.provideFieldEquateReferences(document, feqToken, context.includeDeclaration);
}

provideFieldEquateReferences resolves the cursor's ?Name with resolveFieldEquate (the hover/F12 rule), then walks the file's FieldEquateLabel tokens with that name and keeps each one that resolves at its own line to the same control. That gives the compiler's scoping for free:

  • the same ?OkButton in another procedure's window is a different control and is left out;
  • a use inside a method of the procedure's local WindowManager class (the ABC shape) resolves through enclosingProcedures to the procedure that declares the window, so it is included;
  • a ?Name in a string or comment is never a FieldEquateLabel token.

The declaration is the ?Name inside the control's USE(); includeDeclaration: false drops it. Ranges cover the name without the ?, which is the word rename replaces, so rename on a field equate now rewrites USE(?OkButton) and its uses to USE(?SaveButton) etc., and leaves the other procedure's control alone.

A window's controls are only visible to the procedure that declares it, so the search stays in the current file.

Testing

New FieldEquateReferences.test.ts, 8 tests: from the declaration, from a body use (including ?Name{PROP:...}), from a use inside a local class method, with the cursor on the ?, the same name in another procedure, includeDeclaration: false, rename, and a colon-named equate (?LOC:Year:Prompt). All 8 fail without the fix (they return []).

Full suite: 4559 passing, 0 failing, 3 pending.

Live-tested in a real application: references from a BUTTON's USE(?Name) in the WINDOW list its OF ?Name handler in the ACCEPT loop, and back.

Scope

🤖 Generated with Claude Code

References on a ?Name control returned nothing. The word ladder dropped
the ?, bailed outright on the sigil, and searched for a bare name that
no symbol carries. A new terminal route resolves the field equate by the
rule hover and F12 already use (FieldEquateResolver) and lists every
?Name in the file that resolves to the same control, so a same-named
control in another procedure's window stays out and uses inside the
local WindowManager class methods count. Ranges exclude the ?, so
rename now rewrites USE(?Name) and its uses correctly.

FieldEquateReferences.test.ts: 8 tests, all 8 fail without the fix.
Full suite 4559 passing, 0 failing, 3 pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@msarson
msarson merged commit dba29db into msarson:version-1.0.11 Nov 17, 2026
1 check passed
msarson added a commit that referenced this pull request Nov 17, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@geircodes
geircodes deleted the fix/field-equate-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