typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Fix missing JSDoc comments on destructured interface properties

Open Copilot opened this issue 3 weeks ago • 0 comments

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

  1. Modified getDocumentationFromDeclaration in internal/ls/hover.go to detect binding elements and retrieve documentation from the corresponding property in the source type
  2. 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)
  3. Added findPropertyInType helper function to handle union types properly (simplified using IsUnion() and Types() methods)
  4. Updated function signature to pass symbol and location for proper context
  5. Updated signature help call site in internal/ls/signaturehelp.go with 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 inheritance
    • TestDestructuredWithOwnJSDoc: 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 ValueDeclaration for 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

  1. 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;
    
  2. hover over properties
  3. no comments
Image

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 -v as 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.

Copilot avatar Dec 03 '25 17:12 Copilot