Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix missing JSDoc comments on destructured interface properties#2195

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Copilot wants to merge9 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-inherited-jsdoc-comments

Conversation

Copy link
Contributor

CopilotAI commentedDec 3, 2025
edited
Loading

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 wherefubar has an interface type), the hover information was showing type information but omitting JSDoc comments from the source interface properties.

Changes Made

  1. ModifiedgetDocumentationFromDeclaration ininternal/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. AddedfindPropertyInType helper function to handle union types properly (simplified usingIsUnion() andTypes() methods)
  4. Updated function signature to pass symbol and location for proper context
  5. Updated signature help call site ininternal/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 insymbolDisplay.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
  • UsesValueDeclaration 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:
    interfaceFooBar{/** foo comment */foo:number;/** bar comment */bar:string;/** baz comment */baz:string;}declareconstfubar:FooBar;const{foo, bar, baz}=fubar;
  2. hover over properties
  3. no comments
Image

Issue

Should have hovers, as is present innormal 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 withgo test -v as well.</agent_instructions>

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


✨ Let Copilot coding agentset things up for you — coding agent works faster and does higher quality work when set up for your repo.

CopilotAIand others added4 commitsDecember 3, 2025 17:56
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>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
CopilotAI changed the title[WIP] Fix issue with inherited JSDoc comments in destructured membersFix missing JSDoc comments on destructured interface propertiesDec 3, 2025
CopilotAI requested a review fromjakebaileyDecember 3, 2025 18:17
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
CopilotAI requested a review fromjakebaileyDecember 3, 2025 19:10
@jakebaileyjakebailey marked this pull request as ready for reviewDecember 3, 2025 19:12
CopilotAI review requested due to automatic review settingsDecember 3, 2025 19:12
Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an issue where destructured interface members were not showing their inherited JSDoc comments when hovering over them in the editor. The fix adds special handling for binding elements (variables created from destructuring) in the hover implementation to retrieve documentation from the corresponding property in the source type.

Key Changes

  • ModifiedgetDocumentationFromDeclaration to detect binding elements and retrieve documentation from the interface property
  • Added helper functionfindPropertyInType to handle union types when searching for properties
  • Updated function signature to pass symbol and location context
  • Added comprehensive tests for both basic and renamed destructuring scenarios

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

FileDescription
internal/ls/hover.goAdded binding element detection logic and helper function to find property documentation in source types, updated function signature
internal/ls/signaturehelp.goUpdated call togetDocumentationFromDeclaration with new signature
internal/fourslash/tests/destructuredInterfaceJSDoc_test.goAdded new tests for destructured interface JSDoc comments, including renamed properties
testdata/baselines/reference/fourslash/quickInfo/*.baselineUpdated 4 baseline tests to correctly show JSDoc comments for destructured properties

Copy link
Member

@jakebaileyjakebailey left a comment

Choose a reason for hiding this comment

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

I think this is not unreasonable; it is the same code, but things are shifted around in the Go version.

Copy link
Member

@DanielRosenwasserDanielRosenwasser left a comment

Choose a reason for hiding this comment

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

@copilot address

declare const fubar: FooBar;
const {/*1*/foo, /*2*/bar, /*3*/baz} = fubar;

Choose a reason for hiding this comment

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

Change the test case to use a renamed destructuring

const {/*1*/foo, /*2*/bar, /*3*/baz: /*4*/biz} = fubar;

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done inf6b3006. Updated the test to include renamed destructuring:const {foo, bar, baz: biz} = fubar; wherebiz is tested to ensure it shows the JSDoc comment frombaz.

return"",""
}
returnquickInfo,l.getDocumentationFromDeclaration(c,declaration,contentFormat)
returnquickInfo,l.getDocumentationFromDeclaration(c,symbol,declaration,node,contentFormat)

Choose a reason for hiding this comment

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

I'm not so familiar with this, so it could be right, but what I would say is that maybe this needs to be more general and look at all declarations nodes from a given symbol likegetDocumentationComment did in the original codebase.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done inf6b3006. Made the implementation more general by iterating through allsymbol.Declarations (instead of just checkingsymbol.ValueDeclaration) to find binding elements. This matches the pattern in TypeScript wheregetDocumentationComment processes all declarations from a symbol.

…est with renamed destructuringCo-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Comment on lines 25 to 31
const {/*1*/foo, /*2*/bar, baz: /*3*/biz} = fubar;
`
f,done:=fourslash.NewFourslash(t,nil/*capabilities*/,content)
deferdone()
f.VerifyQuickInfoAt(t,"1","const foo: number","foo comment")
f.VerifyQuickInfoAt(t,"2","const bar: string","bar comment")
f.VerifyQuickInfoAt(t,"3","const biz: string","baz comment")

Choose a reason for hiding this comment

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

Add a marker beforebaz:

Choose a reason for hiding this comment

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

@copilot do it

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done in8a13eab. Added marker beforebaz: to test that hovering over the property name shows(property) FooBar.baz: string with the JSDoc comment, while hovering overbiz showsconst biz: string with the same JSDoc comment.

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Comment on lines 91 to 92
ifpropertySymbol!=nil&&propertySymbol.ValueDeclaration!=nil {
declaration=propertySymbol.ValueDeclaration

Choose a reason for hiding this comment

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

@copilot I was actually expecting all comments for a given symbol to be smushed together, but that's not what the old codebase does either.

So I think we actually should switch back to theValueDeclaration approach if we're doing anything like this.

Also, look for, or add, a test for quick info at1 and2.

interfaceFoo{/** This is bar from the interface */bar:string;/** This is baz from the interface */baz:number;}declarevarfoo:Foo;/** Comment on the variable statement. */const{/** Comment on bar destructuring. *//*1*/bar,/** Comment on baz destructuring. *//*2*/baz}=foo;

@copilot go.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done in73c9497. Switched back to theValueDeclaration approach and restructured the logic to match TypeScript's behavior: first try to get JSDoc from the binding element itself, only fall back to the property's JSDoc if none is found.

Added testTestDestructuredWithOwnJSDoc that verifies the behavior when binding elements have JSDoc comments before them. The test shows that TypeScript doesn't currently attach JSDoc to individual binding elements in destructuring patterns, so bothbar andbaz correctly fall back to showing the interface property's JSDoc ("This is bar from the interface" and "This is baz from the interface").

…JSDocCo-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@jakebaileyjakebaileyAwaiting requested review from jakebailey

@gabrittogabrittoAwaiting requested review from gabritto

@DanielRosenwasserDanielRosenwasserAwaiting requested review from DanielRosenwasser

At least 1 approving review is required to merge this pull request.

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Destructured interface members lack inherited JSDoc comments

3 participants

@DanielRosenwasser@jakebailey

[8]ページ先頭

©2009-2025 Movatter.jp