Skip to content

Improve go-to-definition and implement go-to-type-definition #1405

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

Merged
merged 2 commits into from
Jul 17, 2025

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Jul 15, 2025

This PR implements

  • Go-to-def on override keyword selects the overridden method declaration.
  • Go-to-def on a modifier or keyword that starts a declaration works the same as go-to-def on the declaration name.
  • Go-to-def on label in break or continue statement selects the label definition.
  • Go-to-def on case or default keyword selects the containing switch statement.
  • Go-to-def on return, yield or await keyword selects the containing function declaration.
  • Go-to-def on a call expression selects the the signature chosen by overload resolution.
  • Go-to-def on a property in an object literal with a contextual type selects the declaration in the contextual type.
  • Go-to-def on a property with no explicit declaration selects the index signature(s) for the property.
  • Go-to-type-definition on a variable or property selects the associated type(s).
  • Go-to-type-definition on a variable with a generic type such as T[] selects both declarations of T and Array.

The PR also moves getErrorRangeForArrowFunction and GetErrorRangeForNode from binder.go to scanner.go (where other similar functions reside).

@Copilot Copilot AI review requested due to automatic review settings July 15, 2025 20:27
Copy link
Contributor

@Copilot Copilot AI 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 enhances the go-to-definition functionality and implements go-to-type-definition for the TypeScript language server. It adds support for navigating to definitions from various language constructs including override keywords, labels, control flow statements, and call expressions, while also introducing type definition capabilities.

Key changes:

  • Extended go-to-definition to handle keywords (override, case, default, return, yield, await) and jump statements
  • Added comprehensive go-to-type-definition support with type argument handling
  • Moved error range calculation utilities from binder to scanner for better organization

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/scanner/scanner.go Moved GetErrorRangeForNode function from binder and simplified GetTokenPosOfNode
internal/lsp/server.go Added type definition endpoint handling and server capability registration
internal/ls/utilities.go Updated range creation to use token position and fixed label handling return type
internal/ls/findallreferences.go Updated label reference functions to work with generic nodes instead of identifiers
internal/ls/definition.go Major expansion with keyword-based definitions, call resolution, and type definition implementation
internal/checker/utilities.go Updated diagnostic creation to use scanner's error range function
internal/checker/services.go Added contextual declarations and type argument extraction utilities
internal/checker/exports.go Exported new checker methods for index signatures and symbol resolution
internal/checker/checker.go Implemented index signature location resolution
internal/binder/binder.go Removed GetErrorRangeForNode function (moved to scanner)
internal/ast/ast.go Added IsSwitchStatement helper function

"Required": {},
"Readonly": {},
"Pick": {},
"Omit": {},
Copy link
Member

@RyanCavanaugh RyanCavanaugh Jul 15, 2025

Choose a reason for hiding this comment

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

Suggested change
"Omit": {},
"Omit": {},
"Exclude": {},

Copy link
Member Author

Choose a reason for hiding this comment

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

The types in this list generally operate on object types for which we record source locations. Exclude and Extract are almost always used with (unions of) literal types, and we don't record source locations for those.

Copy link
Member Author

Choose a reason for hiding this comment

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

However, we should include NonNullable<T>.

@ahejlsberg ahejlsberg added this pull request to the merge queue Jul 17, 2025
Merged via the queue into main with commit 4fd6eb1 Jul 17, 2025
22 checks passed
@ahejlsberg ahejlsberg deleted the more-go-to-def branch July 17, 2025 22:15
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.

2 participants