Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

Overridden methods and properties in derived classes/interfaces were not showing JSDoc comments from their base declarations on hover.

interface Base {
  /** Documentation here */
  method(): void;
}

interface Derived extends Base {
  method(): void;  // Hover showed no docs
}

Changes

  • internal/ls/hover.go: Added getJSDocFromBaseTypes() to recursively search base types for JSDoc when current declaration lacks documentation. Modified getDocumentationFromDeclaration() to accept symbol parameter and invoke base type search.

  • internal/checker/exports.go: Exported GetBaseTypes() to enable base type traversal in language service.

  • Tests: Added hoverInheritedJSDoc_test.go covering interface extension and class inheritance scenarios. Updated baselines for existing JSDoc inheritance tests to reflect correct behavior.

The fix handles multiple inheritance levels and includes nil safety for non-class/interface types (enums, modules, etc.).

Original prompt

This section details on the original issue you should resolve

<issue_title>Classes and interfaces lose hover JSDoc comments from parent class/interface when re-declaring properties</issue_title>
<issue_description>### Extension Version

v0.20251107.1

VS Code Version

1.105.1

Operating system Version

Ubuntu x86-64 (WSL, though I highly doubt this matters)

Steps to reproduce

Copy the following MRE into a new .ts file in the editor.

interface foo {
  /** base jsdoc */
  bar(k: string): number;
  /** other jsdoc */
  other: 24;
}

interface bar extends foo {
  bar(k: string | symbol): number | 99;
}

declare class thing {
  /** doc comment */
  method(s: string): void;
}

declare class potato extends thing {
  method(s: "1234"): void;
}

declare const f: foo;
declare const b: bar;
declare const t: thing;
declare const p: potato;

// b and p lack comments on the properties they overrode (`bar` and `method` respectively)
f.bar;
f.other;
b.bar;
b.other;
t.method;
p.method;

Hover over the bottom 6 symbols and notice how b and p's overridden methods lack hover comments.

Issue

The interfaces and classes should inherit the parents' doc comments if they themself lack an accompanying JSDoc comment, as happens with normal tsc.

NB: This also occurs with classes implementing interfaces and interfaces extending classes.</issue_description>

<agent_instructions>Use fourslash tests for this, in ./internal/fourslash/tests; there are examples of hover there.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 7, 2025 23:53
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix loss of hover JSDoc comments in re-declared properties Fix JSDoc inheritance for overridden methods and properties in hover Nov 8, 2025
Copilot AI requested a review from jakebailey November 8, 2025 00:14
Copilot finished work on behalf of jakebailey November 8, 2025 00:14
}

// getJSDocFromBaseTypes searches for JSDoc comments in base types when the current symbol doesn't have one
func (l *LanguageService) getJSDocFromBaseTypes(c *checker.Checker, symbol *ast.Symbol) *ast.Node {
Copy link
Member

Choose a reason for hiding this comment

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

@copilot This function does not exist in the old codebase. What does this code correspond to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This corresponds to the findBaseOfDeclaration function in src/services/services.ts (lines ~3565-3575 in the TypeScript codebase).

The TypeScript implementation:

function findBaseOfDeclaration<T>(checker: TypeChecker, declaration: Declaration, cb: (symbol: Symbol) => T[] | undefined): T[] | undefined {
    const classOrInterfaceDeclaration = declaration.parent?.kind === SyntaxKind.Constructor ? declaration.parent.parent : declaration.parent;
    if (!classOrInterfaceDeclaration) return;

    const isStaticMember = hasStaticModifier(declaration);
    return firstDefined(getAllSuperTypeNodes(classOrInterfaceDeclaration), superTypeNode => {
        const baseType = checker.getTypeAtLocation(superTypeNode);
        const type = isStaticMember && baseType.symbol ? checker.getTypeOfSymbol(baseType.symbol) : baseType;
        const symbol = checker.getPropertyOfType(type, declaration.symbol.name);
        return symbol ? cb(symbol) : undefined;
    });
}

Our Go implementation achieves the same goal: traverse base types to find JSDoc from parent declarations when the current declaration lacks documentation.

Copilot AI requested a review from jakebailey November 8, 2025 00:32
Copilot finished work on behalf of jakebailey November 8, 2025 00:32
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.

Classes and interfaces lose hover JSDoc comments from parent class/interface when re-declaring properties

2 participants