Skip to content

Fix panic when hovering over functions with JSDoc links #1339

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 1, 2025

The TypeScript Native Preview extension was crashing with a panic when hovering over functions that contain JSDoc links ({@link}, {@linkcode}, {@linkplain}) in their documentation. This was happening because the Node.Text() method in internal/ast/ast.go didn't handle JSDoc link node types.

Error before fix:

panic handling request textDocument/hover Unhandled case in Node.Text: *ast.JSDocLink

Root cause:
The writeComments function in internal/ls/hover.go calls comment.Text() on JSDoc nodes, which internally calls the Node.Text() method. However, the switch statement in Node.Text() was missing cases for:

  • KindJSDocLink
  • KindJSDocLinkCode
  • KindJSDocLinkPlain

Solution:
Added the missing cases to handle JSDoc link types in the Node.Text() method. Since these types inherit from JSDocCommentBase (which has a text []string field), they follow the same pattern as KindJSDocText:

case KindJSDocLink:
    return strings.Join(n.AsJSDocLink().text, "")
case KindJSDocLinkCode:
    return strings.Join(n.AsJSDocLinkCode().text, "")
case KindJSDocLinkPlain:
    return strings.Join(n.AsJSDocLinkPlain().text, "")

Testing:

  • Added comprehensive test case with all three JSDoc link types in documentation
  • Added unit test that directly verifies the Text() method works for JSDoc link nodes
  • Verified the test reproduces the panic before the fix and passes after
  • Confirmed all existing tests continue to pass

The fix is minimal and surgical - it only adds the missing cases without modifying any existing functionality.

Fixes #1323.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] vscode: Hovering over Effect functions (from 'effect' library) causes InternalError: panic handling request textDocument/hover Fix panic when hovering over functions with JSDoc links Jul 1, 2025
@Copilot Copilot AI requested a review from jakebailey July 1, 2025 21:39
Copilot finished work on behalf of jakebailey July 1, 2025 21:39
@jakebailey
Copy link
Member

Revert everything you just did. Do not make compiler tests, do not make AST unit tests. The bug is in hover, so a compiler test will not reproduce it at all.

Start by making a test next to internal/ls/hover.go which shows this failure, similar to the other tests in the ls package.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 1, 2025

Revert everything you just did. Do not make compiler tests, do not make AST unit tests. The bug is in hover, so a compiler test will not reproduce it at all.

Start by making a test next to `interna...

Done. I've reverted all the previous changes and created a proper hover test in internal/ls/hover_test.go that reproduces the JSDoc links panic and verifies the fix. The test shows the failure occurs in the language service layer when hovering over functions with JSDoc links. Commit 0e79c6c.

Copilot finished work on behalf of jakebailey July 1, 2025 21:58
… JSDoc links

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@Copilot Copilot AI requested a review from jakebailey July 1, 2025 22:12
Copilot finished work on behalf of jakebailey July 1, 2025 22:12
@jakebailey jakebailey marked this pull request as ready for review July 2, 2025 19:44
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.

vscode: Hovering over Effect functions (from 'effect' library) causes InternalError: panic handling request textDocument/hover
2 participants