Port #62361: Make go-to-definition resolve constraint properties for object literals in argument positions#2746
Conversation
…d add self-reference check for go-to-definition on object literal properties Port of TypeScript PR #62361: Make go to definition go to the constraint's properties for object literals in argument positions. Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
|
@copilot No tests got updated, so I don't think this is complete. Maybe some tests are fixed that are in failingTests? Look for the original tests modified in the PR you ported. |
…eNodeInferences for proper inference blocking, update baselines The self-reference check was correctly detecting when property declarations pointed back to the same object literal, but the retry with IgnoreNodeInferences was using the internal getApparentTypeOfContextualType which doesn't run through runWithInferenceBlockedFromSourceNode. Changed to use the public GetContextualType API which properly blocks inference from the source node, matching TypeScript's behavior. Baselines for goToDefinitionObjectLiteralProperties2 and goToDefinitionObjectLiteralProperties3 now match TypeScript's output exactly (diff files deleted). Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Fixed in 8141729. The self-reference detection was working, but the retry was using the internal |
… helper functions Remove unnecessary wrapper functions (GetContextualDeclarationsForObjectLiteralElementWithNode, getContextualDeclarationsForObjectLiteralElementWorker, getDeclarationsFromContextualType, getDeclarationsFromType, hasSelfReferenceDeclaration) and put the logic directly in GetContextualDeclarationsForObjectLiteralElement with the added propertyNameNode parameter. Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Ports TypeScript PR #62361 into the Go-based TypeScript compiler/language server, improving go-to-definition behavior for object literal properties used as generic arguments by resolving to constraint property declarations (and aligning baseline outputs with upstream TypeScript).
Changes:
- Renames
ContextFlagsCompletionstoContextFlagsIgnoreNodeInferencesand updates all call sites to use the new flag. - Updates go-to-definition to detect self-referential object literal property definitions and re-run contextual typing with inference blocked to find constraint declarations.
- Updates fourslash go-to-definition baselines (and removes
.difffiles where Go output now matches TypeScript exactly).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/checker/types.go | Renames contextual typing flag and updates its documentation comment. |
| internal/checker/services.go | Implements inference-blocking behavior for the renamed flag and enhances contextual decl lookup for object literal elements. |
| internal/checker/jsx.go | Updates JSX contextual typing logic to use the renamed flag. |
| internal/ls/completions.go | Uses the renamed flag when requesting contextual types for completion scenarios. |
| internal/ls/string_completions.go | Uses the renamed flag for contextual-type-based string literal completions. |
| internal/ls/definition.go | Passes the property-name node through to contextual declaration lookup to support the new go-to-definition behavior. |
| testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionObjectLiteralProperties2.baseline.jsonc | Baseline updated to reflect corrected go-to-definition targets. |
| testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionObjectLiteralProperties2.baseline.jsonc.diff | Deleted because outputs now match the TypeScript reference. |
| testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionObjectLiteralProperties3.baseline.jsonc | Baseline updated to reflect corrected go-to-definition targets. |
| testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionObjectLiteralProperties3.baseline.jsonc.diff | Deleted because outputs now match the TypeScript reference. |
…lsFromContextualType Revert GetContextualDeclarationsForObjectLiteralElement to its original form. Move the self-reference detection logic from the checker to definition.go's getDeclarationsFromObjectLiteralElement, matching the TypeScript PR pattern: 1. Use GetContextualType (public API) to get the contextual type 2. Use GetPropertySymbolsFromContextualType to get property symbols (handles union discriminant filtering, deduplication, etc.) 3. Check if any property symbol's valueDeclaration self-references 4. If so, retry with ContextFlagsIgnoreNodeInferences 5. Call getDeclarationsFromObjectLiteralElement from the object literal property check path in getDeclarationsFromLocation Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Use else-if to avoid calling getDeclarationsFromObjectLiteralElement twice when the symbol is an object literal property. Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Remove GetContextualDeclarationsForObjectLiteralElement from checker/services.go as it has no equivalent in the original TypeScript code. Simplify getDeclarationsFromLocation to always call getDeclarationsFromObjectLiteralElement (matching TS's getDefinitionFromObjectLiteralElement), falling back to symbol.Declarations. This matches the TypeScript flow where getDefinitionFromObjectLiteralElement is called for all symbols. Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
…object literals in argument positions (#2746) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
ContextFlagsCompletionstoContextFlagsIgnoreNodeInferencesin checker/types.godefinition.go, usingGetPropertySymbolsFromContextualTypeandGetContextualTypeto match the TypeScript PR pattern closelyGetContextualDeclarationsForObjectLiteralElementfrom checker — no equivalent in TS✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.