Skip to content

fix(member): one shim-aware MEMBER lookup for every feature - #867

Merged
msarson merged 1 commit into
msarson:version-1.0.11from
geircodes:fix/member-shim-shared-lookup
Nov 25, 2026
Merged

msarson merged 1 commit into
msarson:version-1.0.11from
geircodes:fix/member-shim-shared-lookup

Conversation

@geircodes

Copy link
Copy Markdown
Contributor

One shim-aware MEMBER lookup for every feature

What happens

A common project layout keeps a module's MEMBER('program') statement in a small shim file that every module includes as its first statement:

! member.clw
 MEMBER('mainprog')
! usage.clw
 INCLUDE('member.clw'),ONCE

Caller PROCEDURE()
  CODE
  Thr = START( Worker )
  Worker()
  OtherProc()

With Worker declared in the PROGRAM's MAP and implemented in mainprog.clw:

  • Ctrl+F12 on Worker (in START( Worker ) or Worker()), or on OtherProc(), does nothing.
  • Hover on Worker shows the MAP declaration link, but not the implementation link.
  • Missing MAP declaration (Diagnostic: warn when procedure has no MAP declaration #89): an implementation in usage.clw with no MAP entry in the PROGRAM is not reported.
  • PRIVATE procedure call: a call to a PRIVATE procedure of the PROGRAM's MAP is not reported.
  • Unresolved procedure call: the check cannot see the PROGRAM's MAP from this module, so it does not resolve calls through the parent.
  • Re-validation: editing the PROGRAM does not re-validate an open module that is a member through a shim, and vice versa.

The same module with MEMBER('mainprog') written in it works for all of these.

Root cause

Each of these paths reads the MEMBER statement with TokenHelper.findMemberHeaderToken(tokens), which only sees the tokens it is given: the module's own. For a module headed by a shim it finds nothing, so the feature concludes the module has no parent:

// ImplementationProvider.resolveProcedureReferenceImplementation
const memberToken = TokenHelper.findMemberHeaderToken(tokens);
if (memberToken?.referencedFile) {
    // ... search the parent's MAP: never reached for a shim-headed module

The shim has been handled before, one feature at a time: #388 (hover and F12), #395 (missing-include check), the PROGRAM-globals completion fix, and the MAP-include walk in MapProcedureResolver. Each added its own copy of the first-statement walk, so there were five copies, and eleven call sites still used the direct lookup:

File What it lost
ImplementationProvider Ctrl+F12 from a call site
ProcedureHoverResolver the implementation link on a procedure hover
HoverProvider the MEMBER-parent tier for procedures and variables
DefinitionProvider (3) implementation → MAP declaration; call → parent MAP; types included only by the PROGRAM
ReferencesProvider FAR from an implementation label → its MAP declaration
MapDeclarationDiagnostics missing MAP declaration (#89)
PrivateProcedureDiagnostics PRIVATE calls into the PROGRAM's MAP
UnresolvedProcedureCallDiagnostics parent-MAP resolution
server.ts (2) PROGRAM ↔ member re-validation

The fix

utils/MemberHeaderResolver.ts holds the walk once:

export function resolveMemberHeader(tokens: Token[], fromFile: string, options: MemberHeaderOptions = {}): MemberHeader | undefined {
    const resolveInclude = options.resolveInclude ?? defaultResolveShimInclude;
    const loadTokens = options.loadTokens ?? defaultLoadTokens;
    const visited = new Set<string>();

    for (let hop = 0; hop <= MAX_SHIM_HOPS; hop++) {
        const direct = TokenHelper.findMemberHeaderToken(tokens);
        if (direct?.referencedFile) return { token: direct, hostFile: fromFile };

        const shim = TokenHelper.findShimIncludeToken(tokens);
        if (!shim?.referencedFile) return undefined;
        ...

It keeps the existing rules: only the first statement can be a shim, the owner project's redirection comes first (#328) and then the module's folder, at most three hops, and a visited set stops cycles. It is synchronous: it loads a shim with TokenCache.getTokensForClosedFile (open buffer first, mtime-cached), so the synchronous callers (server.ts, the diagnostics) can use it too. It returns the file the MEMBER line is written in (hostFile), for callers that resolve the parent from there (MapProcedureResolver, WordCompletionProvider).

  • The eleven direct call sites call resolveMemberHeaderTokenForUri(tokens, document.uri).
  • MemberLocatorService, SymbolFinderService and IncludeVerifier keep their private method as a one-line wrapper, so their call sites are unchanged. MemberLocatorService passes its own resolveFilePath, which keeps its no-solution search; MapProcedureResolver passes its cached resolveIncludeTarget.
  • DefinitionProvider.findTypeInIncludes now adds the implied .clw to the MEMBER target before resolving it. Without it, MEMBER('mainprog') found through a shim still missed the parent.

Testing

server/src/test/MemberHeaderShimAllFeatures.test.ts, 22 tests:

  • The walk itself (6): MEMBER written in the module, a shim (with hostFile naming the shim), a chained shim, an include cycle, a later INCLUDE not followed, a shim that cannot be found.
  • The same fixture through every feature (8), run twice: with the shim, and with MEMBER written in the module as the control. The features covered are Ctrl+F12 on a START() argument and on a call into another member module, the hover's declaration and implementation links, F12, FAR from an implementation label, the missing-MAP-declaration warning, the unresolved-call resolver, and the PRIVATE-call warning.

Proven real: with the caller changes stashed (the new helper kept, since the walk tests import it), 6 of the 8 shim tests fail and all 8 control tests pass. F12 and FAR already pass without the fix (#388, #854); they stay as regression guards so a later change to those paths cannot drop the shim again.

Full server suite: 4641 passing, 3 pending, 0 failing. One run hit a 30 s timeout in StructureDeclarationIndexer.DiskCache.test ("a corrupt disk cache degrades to a full scan"); it passes on its own with and without this change (about 15 s) and passed on the next full run.

Scope

Left out on purpose:

  • HoverProvider's MEMBER-parent tier still resolves the parent only in the module's own folder (path.resolve(currentFileDir, ...)), not through redirection. That is unchanged by this PR and is a separate question from finding the MEMBER statement.
  • TokenHelper.findMemberHeaderToken itself is unchanged: it answers "is a MEMBER written in these tokens", which the walk is built on, and TokenHelper cannot load files without an import cycle.
  • server.ts re-validation now walks the shim of each open module when the PROGRAM changes. The walk costs nothing for a module whose first statement is not an INCLUDE; for a shim-headed one it is a stat of a small, cached file.

A module whose MEMBER sits in an INCLUDE'd shim had no parent for
Go to Implementation, the hover card's implementation link, FAR's
MAP-declaration step and three parent-MAP diagnostics: each read MEMBER
with findMemberHeaderToken, which sees only the module's own tokens.
Hover, F12, completion, the include check and the MAP-include walk each
had a private copy of the shim walk; those five copies are now one,
MemberHeaderResolver, and all eleven direct callers use it.

MemberHeaderShimAllFeatures.test.ts: 22 tests, 6 of them fail without
the fix. Full server suite: 4641 passing, 3 pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@msarson
msarson merged commit a3df318 into msarson:version-1.0.11 Nov 25, 2026
1 check passed
@geircodes
geircodes deleted the fix/member-shim-shared-lookup 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