Skip to content

feat(hover): a CASE branch list on a hover card scrolls, wheel included - #298

Open
geircodes wants to merge 2 commits into
ClarionLive:masterfrom
geircodes:feat/hover-case-branch-list
Open

geircodes wants to merge 2 commits into
ClarionLive:masterfrom
geircodes:feat/hover-case-branch-list

Conversation

@geircodes

Copy link
Copy Markdown
Contributor

What this changes

The language server's hover cards for a CASE, its OF / OROF / ELSE and its END now list the CASE's branches: a table with one row per branch, the line number as a link, then the branch's source line (msarson/Clarion-Extension#857). In a long CASE EVENT() that table is taller than a hover card should be, and Monaco's hover handling gets in the way of scrolling it. This makes the list work well in the CA Editor and the CA Embeditor. Without the server change nothing here applies: every rule and the wheel handler key on the server's link title.

image
  • 7 rows, the rest scrolls, the header row pinned. A list of 7 or fewer branches shows just its rows, with no blank space or scrollbar. The count is one CSS variable, --ca-branch-rows.
  • The mouse wheel scrolls the list and keeps the card open. Monaco reads a wheel over a hover card that cannot scroll as an editor scroll and closes the card, so the list could only be scrolled by dragging its scrollbar. A wheel over a list with more rows than it shows now scrolls the list and goes no further, even at either end. A mouse-wheel notch moves 3 rows; the distance is proportional (100px = 3 rows), so a touchpad glides and a notch under Windows display scaling moves a little more instead of a whole extra step. Ctrl+wheel (editor zoom), a list that shows all its rows, and the rest of the card behave as before.
  • No horizontal scrollbar. A branch line wider than 72 characters, or than the card can be (Monaco's --vscode-hover-maxWidth, so in a narrow editor too), ends in …. The event or control name, and the start of a comment, are what identify a branch.
  • The list's scrollbar is kept clear of the card's resize edge (Monaco's sash on the right border), which otherwise took the mouse first, and takes the theme's scrollbar colours, so a dark card does not get a light one.
  • CA Embeditor line numbers. The server's own-document links are relabelled "line N", with N the embeditor line (the host shifts the #L target past the MEMBER header). A link whose label is a bare number, as in this list, keeps a bare number, but the shifted one, so the numbers match the embeditor's gutter.

How it works

All in monaco-embeditor.html:

  • CSS keyed on .monaco-hover table:has(a[title="Go to branch"]): display: block with a max height of (rows + header) × row height, overflow-x: hidden, scrollbar-color from the theme, a sticky thead, fixed-height nowrap rows, and an inline-block code cell with max-width: min(72ch, hover max width − the number column) and text-overflow: ellipsis.
  • branchListWheel, a wheel listener on document in the capture phase (passive: false), so it runs before Monaco's own capture-phase listener on the editor. Over a branch list with hidden rows it calls preventDefault + stopPropagation and scrolls the list itself: pixels in proportion (100px = 3 rows), a line as a row, a page as the rows on show (the list less its pinned header), with the row height measured unrounded so steps stay on row boundaries.
  • prepareSelfLinks: a bare-number label stays a number (the shifted line) instead of becoming "line N".

Tests

  • hover-branch-list-wheel.test.js (new, 18 checks, added to npm test) runs the real branchListWheel: a notch scrolls 3 rows, a display-scaled notch 4.5 rather than 6, touchpad, line and page deltas, the event stopped at either end, and left alone for a list that fits, a table that is not a branch list, Ctrl+wheel and a target outside a hover table; the CSS rule (row cap, vertical-only scrolling, pinned header, ellipsis); and the capture-phase, non-passive registration.
  • hover-self-links.test.js: a new section for the bare-number label (the shifted number with the title kept; a bare number to another file left alone).

Without the page change the wheel suite fails and the new self-links check fails ("line 213"). With it, hover-branch-list-wheel 18/18 and hover-self-links 44/44, and monaco-page-integrity, hover-footer-row, hover-attribute-chips, local-first-hover, local-first-completion and buffer-sync all pass.

@clarionlive-agent clarionlive-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, and for the thorough description. It works well: we're holding the merge until msarson/Clarion-Extension#857 lands.

Tests

  • All 36 node test suites pass on this branch, including hover-branch-list-wheel (18/18) and hover-self-links (44/44).
  • Run against master's page, both new tests fail, as you said.
  • We also broke three things on purpose: Ctrl+wheel excluded, stopPropagation removed, and the label always "line N". The matching test failed each time.
  • The branch merges cleanly onto current master.

Fit with #857

  • The server's links carry exactly the "Go to branch" title and | Line | Branch | table that the CSS and branchListWheel key on.
  • #857 also makes the card's other line links bare numbers ("END on line [17]"). The prepareSelfLinks change is therefore needed: without it the CA Embeditor would show "on line line 17". With it, the card shows the embeditor's shifted number.
  • Everything is keyed to tables containing a "Go to branch" link. Until a server sends one, the page behaves as it does today.

Why we're holding it
CA currently ships LSP v1.0.9, and #857 is still open against version-1.0.11. If the title or table format changed during that review, this side would stop matching with no visible error. Once #857 is merged, we'll merge this together with the LSP update that brings it in.

Two small things we'll tidy when we merge (nothing needed from you):

  • the commit body still has the template's "Insert text here";
  • in Terminal/test/package.json, the missing space in &&node local-first-slices (copied from the existing line).

— Charlie

The language server's CASE / OF / END cards are getting a cap
(msarson/Clarion-Extension#857): at most 40 branches and a "...N more"
row, unless the client announces
capabilities.experimental.clarionCaseBranchListAll. This page limits
the list's height and scrolls it itself, so LspClient now announces the
flag next to clarionAttributeEditLinks and keeps getting the whole
list. A server without the cap ignores the flag.

Checked live against a 163-branch CASE: every branch is returned and
no "...N more" row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@geircodes

Copy link
Copy Markdown
Contributor Author

Added 6b51ae3: LspClient now also announces capabilities.experimental.clarionCaseBranchListAll.
The language server's CASE / OF / END cards are getting a cap in msarson/Clarion-Extension#857: at most 40 branches and a "…N more" row, unless the client announces this flag. This PR already limits the list's height and scrolls it, so CA asks for every branch and the scrolling list keeps working on large CASEs. Checked live on a 163-branch CASE: every branch is returned, no "…N more" row.
A server without the cap ignores the flag, as it does clarionAttributeEditLinks, so this can be merged before or after #857. The first commit is unchanged.

asantarelli pushed a commit to asantarelli/ClarionAssistant that referenced this pull request Nov 25, 2026
Reported by John: in the BrowseAuthors CA Embeditor, the global dbgCount carries a
red squiggle reading "'dbgCount' is not declared in this file." while HOVERING the
same word correctly reports it as a global variable.

Not our diagnostic. It comes from UndeclaredVariableDiagnostics in the Clarion
language server, and the split is a known upstream shape (Clarion-Extension ClarionLive#115,
whose audit ships in .lsp-build): the diagnostic and hover/F12 resolve globals
through two DIFFERENT paths. ClarionLive#115's fix chose a SymbolFinder fallback over reusing
hover's own loadGlobalScopeForCursor, so the two can still disagree -- same family
as the ClarionLive#298 / ClarionLive#300 follow-ups already fixed on top of it. Filed upstream; this is
the CA-side stopgap, and it leans on that diagnostic's own stated contract: "if ANY
of our own resolution paths knows the name, don't flag it."

Ruled OUT as the source of truth first: CodeGraph. ClarionParser emits
Type="variable" in exactly two places, both Scope="local" -- program- and
module-scope DATA is never indexed at all. Verified against two real .codegraph.db
files: type='variable' occurs ONLY with scope='local' (223 and 56 rows, zero
globals). A CodeGraph-only filter would have been inert for the reported bug. That
also independently confirms the diagnosis -- CodeGraph cannot have answered the
hover, so the server itself resolved it.

So the global check reads the source the app actually generates:
ResolveNamesFromProgramGlobals follows the module's own MEMBER('...') line to the
PROGRAM .clw and looks for a column-1 label in its declaration section (bounded by
ClarionParser.FindMainTailStart, so the global CODE and everything after it are
excluded). In embed mode EmbedLspContext already addresses the buffer to the real
generated module path, so the file whose MEMBER line we need is exactly the path
the diagnostics request carries. A file that IS the PROGRAM is handled directly.

CodeGraph is still consulted afterwards, for what it does know: global
CLASS/INTERFACE, module procedures, ABC library symbols. That path needed a new
primitive -- FindAllSymbolsByName -- because FindSymbolByName's unordered LIMIT 1
answers "is any declaration of this name non-local?" with an arbitrary row, so the
verdict would have depended on index order. Results are scope-ordered (global,
module, class, then local/parameter last) so a reachable declaration is seen first.

Kept deliberately narrow so real undeclared variables still surface:
  * only this exact message shape is considered; no DB or file is even opened
    otherwise, and every other diagnostic passes through untouched
  * 'local'/'parameter' matches clear NOTHING -- that is another procedure's
    private data, the case the server is right about (same reasoning as
    IsUnreachableLocalVariable, which guards the F12 fallback)
  * unknown to every path => keep the diagnostic; the server stays the default and
    is only overruled on positive evidence
  * a throw anywhere in the filter returns the diagnostics unchanged

Verified by driving the SHIPPED DLL through reflection against real generated
Clarion source (EmptyApp001.clw -> EmptyApp.clw): 18 assertions -- five genuine
globals of differing shapes cleared (BYTE(0), INIClass, LONG(0),THREAD, ErrorClass,
FuzzyClass), unknown names NOT cleared, case-insensitive both ways, PROGRAM-file
passed directly, null/empty/missing paths non-throwing, and end-to-end that
DropUndeclaredWeCanResolve drops only the resolvable entry while the genuinely
undeclared one and an unrelated diagnostic both survive with Pending preserved.

NOT yet verified live against BrowseAuthors -- Clarion is running, so no deploy.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant