-
Notifications
You must be signed in to change notification settings - Fork 734
Fix JSDoc inheritance for overridden methods and properties in hover #2036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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>
| } | ||
|
|
||
| // 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Overridden methods and properties in derived classes/interfaces were not showing JSDoc comments from their base declarations on hover.
Changes
internal/ls/hover.go: AddedgetJSDocFromBaseTypes()to recursively search base types for JSDoc when current declaration lacks documentation. ModifiedgetDocumentationFromDeclaration()to accept symbol parameter and invoke base type search.internal/checker/exports.go: ExportedGetBaseTypes()to enable base type traversal in language service.Tests: Added
hoverInheritedJSDoc_test.gocovering 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
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.