Skip to content

feat(hover): CASE, OF and END cards list the CASE's branches - #857

Merged
msarson merged 2 commits into
msarson:version-1.0.11from
geircodes:feat/hover-case-branch-navigator
Nov 17, 2026
Merged

msarson merged 2 commits into
msarson:version-1.0.11from
geircodes:feat/hover-case-branch-navigator

Conversation

@geircodes

Copy link
Copy Markdown
Contributor

What this changes

The hover cards of a CASE, its OF / OROF / ELSE and its END list the CASE's branches: one row per branch, the line number as a link to it, then the branch's own source line, comment included. In a long CASE EVENT() or CASE FIELD() the card becomes a quick way to see the branches and jump to one, without scrolling through the block.

Hovering CASE:

image

Hovering OF

image
  • CASE card: a one-line header (the branch count and a link to the END), then the list. It replaces the "closed by END on line N" card, and the generic CASE keyword description is left out: the card is for navigating, and the description would push the list down.
  • OF / OROF / ELSE card of a CASE: the existing card (branch n of m, the value it matches), then the list with the hovered branch marked ▸. The CASE line is the list's first row, in place of the separate code block and link to it, which keeps the card short.
  • END card of a CASE: "closes CASE", then the list, the CASE line first.
  • A nested CASE lists only its own branches. IF / ELSIF / ELSE cards, and a CASE without branches, are unchanged.

The line links are links to the same document, labelled with the line number only (no file name), each with a link title: Go to branch, Go to CASE, Go to END. A client that wants to style the list can key on the title. VS Code shows the whole table in its hover, which scrolls as usual.

How it works

The branches are already recorded: DocumentStructure.populateBranches() puts every OF / OROF / ELSE of a CASE in Token.branches, with its line, and leaves out a nested CASE's own branches.

  • HoverRouter.handleBlockOpener: a CASE with recorded branches gets buildCaseBranchList (header + table) instead of the closed-by card.
  • HoverRouter.caseBranchTable(caseToken, document, current?, withOpener?): the table rows from caseToken.branches; current marks the hovered branch, withOpener puts the CASE line first. Used by the CASE card, handleBranchKeyword and buildTerminatorHover.
  • HoverRouter.tableCode: the source line as inline code in a table cell, | escaped and a longer backtick fence when the line holds a backtick.
  • HoverFormatter.lineLink(uri, line0, title?): a [n](file:///…#Ln "title") link with the bare line number as its label.

Open questions

  • IF / ELSIF chains could get the same list. Left out here: long ELSIF chains are rarer, and the IF card's preview of the condition is more useful there.
  • Whether the CASE card should keep the keyword description under the list.

Tests

HoverProvider.CaseBranchList.test.ts (new, 13 tests): the rows and their order, line-number links with titles and no file names, the hovered-branch marker on OF / OROF / ELSE, the CASE row on the branch and END cards, nested CASEs, | and backtick escaping, IF cards unchanged, a CASE without branches unchanged. With the source change removed, 11 of the 13 fail; the two that still pass are the unchanged-card guards. The full suite passes: 4557 passing, 3 pending.

In a long CASE EVENT() or CASE FIELD() there was no quick way to see the
branches or jump to one. The hover cards of a CASE, its OF / OROF / ELSE
and its END now list the CASE's branches: one row per branch, its line
number as a link, then the branch's source line with its comment. The OF
and END cards put the CASE line first and mark the hovered branch. A
nested CASE lists only its own branches; IF cards and a CASE without
branches are unchanged. Rows come from Token.branches, which
populateBranches() already fills, and each link has a title (Go to
branch / Go to CASE / Go to END) a client can key on.

Tests: new HoverProvider.CaseBranchList.test.ts, 13 tests, 11 of which
fail without the source change (the other two guard unchanged cards).
Server suite: 4557 passing, 3 pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@geircodes
geircodes force-pushed the feat/hover-case-branch-navigator branch from f500ef8 to 8379812 Compare November 6, 2026 07:24
@msarson

msarson commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks for this, it's a nice card. The review results:

  • the build is clean;
  • 11 of the 13 tests fail on the base;
  • the full suite passes;
  • it merges cleanly with the current version-1.0.11.

The markdown escaping, the links (1-based, through toFileUri) and the nesting are all right.

One thing to change before we merge: caseBranchTable has no limit. A generated window's CASE EVENT() or CASE ACCEPTED() can have hundreds of branches, and each row carries the whole source line, comment included. Nothing in this repo caps the card's height on the client side, so the hover becomes as tall and as wide as the CASE.

Could you make these changes?

  • Cap the table at about 40 rows, and always keep the CASE row and the hovered branch. End it with a …N more row, ideally linking to the first branch left out. The header already gives the full count. HoverRouter caps a VIEW's projected fields the same way.
  • Cut each row's text at about 100 characters with …, before tableCode, so the fence logic still sees the real text.
  • Add a test with about 60 branches.

A small optional one: tableCode turns a source \| into \\|, which can leave a stray backslash in the cell. It's cosmetic.

— Alice

…r all

Review follow-up. A generated CASE EVENT() can have hundreds of
branches, so the branch list is now capped at 40 rows. The hovered
branch is always kept, and a "...N more" row links to the first branch
left out. A client that limits the list's height itself can announce
capabilities.experimental.clarionCaseBranchListAll to get every branch.
Each row's text is cut at 100 characters before the markdown escaping.

The hovered row is now marked by branch index rather than line, so
"OF 1 OROF 2" on one line marks only the hovered keyword. A backslash
before a | in the source gets a zero-width space after it: marked
counts the backslashes before a pipe and otherwise ends the cell there.

Tests: 8 new in HoverProvider.CaseBranchList.test.ts (60-branch CASE,
OF past the cap, END card, list-all client, same-line OROF, \|, long
line); 7 fail without the change. Server suite: 4564 passing, 3
pending; one timing-sensitive SDI disk cache test timed out under full
load and passes on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
geircodes added a commit to geircodes/ClarionAssistant that referenced this pull request Nov 17, 2026
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

Thanks for the review. Pushed b524403 with the changes:

  • Cap. The branch list now shows at most 40 branches. The hovered branch is always kept (when it lies past the 40th it takes the 40th's place), and the list ends with a …N more row whose line number links to the first branch left out. On the CASE card the CASE line is the card's first line; the OF and END cards keep it as the table's first row, as before.
  • Row text is cut at 100 characters with … before tableCode, so the fence logic sees the cut text.
  • Tests. A 60-branch CASE: the CASE card, an OF past the cap, an OF within it, and the END card.

Two additions:

  • capabilities.experimental.clarionCaseBranchListAll, read in ClientFeatures next to clarionAttributeEditLinks. A client that announces it gets every branch. It is for a client that limits the list's height and scrolls it itself, as ClarionAssistant's Monaco editor does (feat(hover): a CASE branch list on a hover card scrolls, wheel included ClarionLive/ClarionAssistant#298, which also announces the flag); without the flag the cap applies, so VS Code gets 40.
  • The hovered row is marked by branch index, not line. With OF 1 OROF 2 on one line, both rows were marked before. New test.

On the \| point: it is more than a stray backslash in the renderer VS Code and Monaco use. marked counts the backslashes in front of a pipe, so the \\| that tableCode wrote for a source \| reads as an escaped backslash followed by a real pipe, and the cell ends there; the rest of the line is lost. markdown-it shows it correctly. tableCode now puts a zero-width space between a backslash in the source and the escaping backslash, which renders as \| in both (checked with marked 14 and markdown-it 14). New test.

Server suite: 4564 passing, 3 pending. One SDI disk cache test (a corrupt disk cache degrades to a full scan) timed out under the full run and passes on its own; it does not touch the hover code. 7 of the 8 new tests fail without the change; the list-all test passes on the base too, since the base lists every branch.

@msarson
msarson merged commit efbe313 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 feat/hover-case-branch-navigator 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