Skip to content

fix(hover): Comment lost first char - #387

Open
geircodes wants to merge 1 commit into
msarson:version-1.0.1from
geircodes:fix/doccomment-inline-fallback-dropped-char
Open

fix(hover): Comment lost first char#387
geircodes wants to merge 1 commit into
msarson:version-1.0.1from
geircodes:fix/doccomment-inline-fallback-dropped-char

Conversation

@geircodes

Copy link
Copy Markdown

fix(hover): DocCommentReader inline fallback dropped the comment's first character

What happened

Hovering a variable whose declaration has a trailing !comment with no space right after the !
rendered the comment text with its leading character missing. Example:

bulkfileName        STRING(256)   !Name of file to read from

Hover showed:

bulkfileName        STRING(256)   !Name of file to read from
ame of file to read from

(doc-comment appendix below the location link — missing the leading "N")

Root cause

DocCommentReader.read()'s inline-!-comment fallback used a consumed character class to assert
"this isn't a second !":

const inlineMatch = declLine.match(/![^!](.+)$/);

[^!] matches — and consumes — one character. When that character is the first real letter of the
comment (no space after !), it's excluded from the captured group and silently lost. The one existing
test for this path (! Does something useful) has a space in that position, so the dropped character
was invisible after .trim() — that's why this went unnoticed.

Fix

Replace the consumed character class with lookaround, so no comment text is ever consumed by the
disambiguation check:

const inlineMatch = declLine.match(/(?<!!)!{1,2}(?!!)(.+)$/);
  • (?<!!) — not immediately preceded by another ! (so we start at the true beginning of a bang-run)
  • !{1,2} — one or two ! (matches the documented intent: single ! or !!, not !!!/!!!!)
  • (?!!) — the bang-run doesn't continue into a third ! (that's the doc-block marker, already
    handled earlier in the function)
  • (.+)$ — captures everything after, untouched

Testing

Two regression tests added to DocCommentReader.test.ts:

  • The exact bulkfileName repro (no space after !) — asserts the full text survives.
  • A double-bang (!!) inline case — asserts the !!-vs-!!! boundary still holds.

npm run test:server: all passing, 0 failing (verified in an isolated worktree off
origin/version-1.0.1, no unrelated WIP mixed in).

Scope

Two files only: server/src/utils/DocCommentReader.ts, server/src/test/DocCommentReader.test.ts.
Unrelated to the in-flight hover-clickable-locations Issue (issue-hover-clickable-locations.md) —
found incidentally while live-testing that work, but this is a plain correctness bug fix, not a
look-and-feel change, so it goes out as its own PR rather than folded into that Issue+patch.

We should also think about if it is necessary to duplicate this information in the hover.

…rst character

The inline-! fallback regex used a consumed [^!] character class to assert
"not a second !", so that character was matched but excluded from the
captured group. For a comment with no space right after ! (e.g.
"!Name of file to read from"), the leading letter was silently lost.
Went unnoticed because the one existing test had a space in that position,
and a dropped space is invisible after trim().

Swap the consumed class for lookaround so no comment text is eaten.
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