Skip to content

fix(hover): keep a declaration's trailing comment out of the method header - #868

Merged
msarson merged 1 commit into
msarson:version-1.0.11from
geircodes:fix/hover-header-return-type-comment
Nov 25, 2026
Merged

msarson merged 1 commit into
msarson:version-1.0.11from
geircodes:fix/hover-header-return-type-comment

Conversation

@geircodes

Copy link
Copy Markdown
Contributor

What happened

The hover card for a class method shows the wrong header line (the card's first line: name, kind, class and return type) when the method's declaration has a trailing ! comment. The comment leaks into that line. The declaration quoted below the header is fine.

Given this class:

SomeClass            CLASS,TYPE
Count                  PROCEDURE(LONG pId),LONG  !Rows found, or -1 when closed
Upper                  PROCEDURE(*STRING pText)  !Upper-cases pText (in place)
Reset                  PROCEDURE(),LONG,DERIVED  !Parent first, then Refresh
                     END

hovering Count (at its declaration, its implementation header SomeClass.Count PROCEDURE or a call obj.Count(1)) shows this card:

Count — Class Method · SomeClass  returns LONG  !Rows found

Count                  PROCEDURE(LONG pId),LONG  !Rows found, or -1 when closed
someclass.inc:2  Find References (Shift+F12)

The first line should end at returns LONG. The comment is cut at its first comma, because the header is built by splitting the declaration on commas.

The header line of each member's card:

Member Header before
Count **Count** — Class Method · SomeClass returns `` LONG !Rows found` ``
Upper **Upper** — Class Method · SomeClass returns `` !Upper-cases pText (in place)` ``
Reset **Reset** — Class Method · SomeClass returns `` LONG` `` (not "Derived")

The comment shows up as part of the return type, cut at its first comma; a method with no return type shows the comment as one; and an attribute right before the comment is lost.

Why

HoverFormatter.parseMethodModifiers takes everything after the parameter list, splits it on commas and treats the first token it does not know as the return type:

for (const part of afterParams.split(',').map(p => p.trim()).filter(p => p)) {
    const upper = part.toUpperCase();
    if (upper === 'PRIVATE' || upper === 'PROTECTED') {
        visibility = upper;
    } else if (upper === 'VIRTUAL' || upper === 'DERIVED' || upper === 'STATIC') {
        modifiers.push(upper);
    } else if (!KNOWN_NON_TYPES.has(upper) && !returnType) {
        returnType = part;
    }
}

With a comment on the line, ),LONG !Rows found, or -1 when closed splits into LONG !Rows found and or -1 when closed, and ,DERIVED !Parent first, then Refresh gives DERIVED !Parent first, which is not DERIVED.

The change

The comment is stripped before anything is read, with the existing DeclaredValueParser.stripTrailingComment (it skips a ! inside a string literal, so PROCEDURE(STRING pSep='!') keeps its parameter list):

private parseMethodModifiers(typeStr: string): { visibility: string; modifiers: string[]; returnType: string | null } {
    const KNOWN_NON_TYPES = new Set(['PRIVATE', 'PROTECTED', 'VIRTUAL', 'DERIVED', 'STATIC', 'PROC', 'PROCEDURE', 'FUNCTION']);
    typeStr = DeclaredValueParser.stripTrailingComment(typeStr);
    let afterParams = typeStr;

It runs before the parameter-list scan, so a ( in a comment is never taken for the parameter list of a declaration that has none. All three callers of buildMethodHeader (formatClassMember, formatMethodCall and formatMethodImplementation) go through it.

Member Header after
Count **Count** — Class Method · SomeClass returns `` LONG` ``
Upper **Upper** — Class Method · SomeClass
Reset **Reset** — Derived Class Method · SomeClass returns `` LONG` ``

The declaration snippet under the header is unchanged: it quotes the line, comment and all, which is where the comment belongs. The Count card is now:

Count — Class Method · SomeClass  returns LONG

Count                  PROCEDURE(LONG pId),LONG  !Rows found, or -1 when closed
someclass.inc:2  Find References (Shift+F12)

Testing

  • New server/src/test/HoverFormatter.MethodHeaderComment.test.ts, 5 tests: a comment with a comma after the return type, a comment and no return type, DERIVED before a comment, a ! inside a string-literal default, and a declaration with no comment (the header must be unchanged).
  • Without the fix 4 of the 5 fail, each with the header above; the no-comment case passes either way.
  • Full server suite: 4624 passing, 3 pending.

🤖 Generated with Claude Code

…eader

The method hover header ("Class Method · Owner  returns `TYPE`") reads the
return type and attributes from the declaration as written, comment and
all. parseMethodModifiers split it on commas, so "),LONG  !a, b" showed
returns `LONG  !a`, a method with no return type showed its comment as
the return type, and ",DERIVED  !note" lost "Derived". The trailing
comment is now stripped first (DeclaredValueParser.stripTrailingComment,
which skips a ! inside a string literal). The snippet below the header
still quotes the full line.

HoverFormatter.MethodHeaderComment.test: 5 tests, 4 fail without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@msarson
msarson merged commit cb2242c into msarson:version-1.0.11 Nov 25, 2026
1 check passed
@geircodes
geircodes deleted the fix/hover-header-return-type-comment 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