Fix missing JSDoc comments on destructured interface properties
Fixed the issue where destructured interface members were not showing inherited JSDoc comments when hovering.
Summary
When hovering over destructured variables from interfaces (e.g., const {foo} = fubar where fubar has an interface type), the hover information was showing type information but omitting JSDoc comments from the source interface properties.
Changes Made
- Modified
getDocumentationFromDeclarationininternal/ls/hover.goto detect binding elements and retrieve documentation from the corresponding property in the source type - Implemented proper fallback logic: First tries to get JSDoc from the binding element itself, only falls back to the property's JSDoc if none is found (matching TypeScript's behavior)
- Added
findPropertyInTypehelper function to handle union types properly (simplified usingIsUnion()andTypes()methods) - Updated function signature to pass symbol and location for proper context
- Updated signature help call site in
internal/ls/signaturehelp.gowith new signature
Testing
- Added comprehensive tests for both basic and renamed destructuring patterns:
TestDestructuredInterfaceJSDoc: Tests basic destructuring ({foo, bar}) and renamed destructuring ({baz: biz})TestDestructuredInterfaceJSDocWithRename: Tests renamed destructuring with JSDoc inheritanceTestDestructuredWithOwnJSDoc: Verifies behavior when binding elements have their own JSDoc (demonstrates current TypeScript behavior where binding element JSDoc is not attached)
- Updated 4 baseline tests that now correctly show JSDoc comments for destructured properties
- All existing tests pass
- No security vulnerabilities detected by CodeQL
Implementation Details
The fix matches TypeScript's reference implementation in symbolDisplay.ts (lines 787-799). The implementation:
- Checks if documentation was found for the binding element declaration
- Only if no documentation exists, looks up the property from the interface type
- For union types, searches through constituent types to find the property
- Uses
ValueDeclarationfor binding element detection (per code review feedback)
Original prompt
This section details on the original issue you should resolve
<issue_title>Destructured interface members lack inherited JSDoc comments</issue_title> <issue_description>### Extension Version
0.20251203.1
VS Code Version
1.106.3
Operating system Version
Ubuntu x86-64, running via Windows 11 inside WSL
Steps to reproduce
- Copy this MRE:
interface FooBar { /** foo comment */ foo: number; /** bar comment */ bar: string; /** baz comment */ baz: string; } declare const fubar: FooBar; const {foo, bar, baz} = fubar;- hover over properties
- no comments
![]()
Issue
Should have hovers, as is present in normal typescript</issue_description>
<agent_instructions>Make a fourslash test in ./internal/fourslash/tests first; see internal/fourslash/tests/hoverAliasInImportedFile_test.go for an example.
Remember that you have a reference hover implementation in the submodule to cross compare.
You can use print debugging with
go test -vas well.</agent_instructions>Comments on the Issue (you are @copilot in this section)
- Fixes microsoft/typescript-go#2194
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.