Skip to content

Signature help implementation #861

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 45 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f7b2484
initial implementation
navya9singh Apr 1, 2025
202e970
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh Apr 1, 2025
fff762c
adding test setup
navya9singh Apr 18, 2025
cbdb32b
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh Apr 22, 2025
5d8476c
cleanup
navya9singh Apr 22, 2025
dcd021f
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh Apr 22, 2025
473fbed
adding more tests and fixes
navya9singh Apr 29, 2025
0d73105
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh Apr 29, 2025
d68643b
adding more tests and fixes
navya9singh Apr 30, 2025
ed043a8
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh Apr 30, 2025
e8c5dae
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh Apr 30, 2025
0c01e98
adding more tests
navya9singh May 12, 2025
7acd18e
cleanup
navya9singh May 12, 2025
4a359ec
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh May 12, 2025
0ccbd20
removing exported function
navya9singh May 12, 2025
151f03a
removing getSymbolOfDeclaration export
navya9singh May 12, 2025
85cdb01
cleanup
navya9singh May 12, 2025
a22ab20
removing deleted code
navya9singh May 12, 2025
e57cf78
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh May 12, 2025
50a3bbe
removing submodule updates
navya9singh May 12, 2025
4bc1228
fixing tests
navya9singh May 15, 2025
f415ca2
fixing formatting and lint errors
navya9singh May 15, 2025
ace6765
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh May 15, 2025
e836eb1
small fix
navya9singh May 15, 2025
31bfa2a
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh May 15, 2025
aafc78f
adding noembed
navya9singh May 15, 2025
1bf462c
adding exported functions to export.go
navya9singh May 16, 2025
8f34a4f
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh May 16, 2025
7a4c633
addressing pr comments
navya9singh May 19, 2025
d8db5cc
addressing comments
navya9singh May 20, 2025
9c81431
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh May 20, 2025
628f4b4
cleanup
navya9singh May 20, 2025
0ff32ac
addressing comments
navya9singh May 24, 2025
7469666
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh May 24, 2025
e621d71
fixing merge conflicts
navya9singh May 24, 2025
7792a6e
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh May 28, 2025
21b43cd
renames
navya9singh May 28, 2025
c61cf81
removing pointer to slice
navya9singh May 28, 2025
5b1f838
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh May 28, 2025
98de4c1
fixing lint errors
navya9singh May 28, 2025
093ff05
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh May 29, 2025
8fca88c
update with node builder
navya9singh Jun 2, 2025
09d531a
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh Jun 2, 2025
ddb78d2
addressing comments
navya9singh Jun 3, 2025
9a3b8f7
Merge branch 'main' of https://github.com/navya9singh/typescript-go-r…
navya9singh Jun 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@ func IsStringOrNumericLiteralLike(node *Node) bool {
return IsStringLiteralLike(node) || IsNumericLiteral(node)
}

func IsStringTextContainingNode(node *Node) bool {
return node.Kind == KindStringLiteral || IsTemplateLiteralKind(node.Kind)
}

func IsTemplateLiteralKind(kind Kind) bool {
return KindFirstTemplateToken <= kind && kind <= KindLastTemplateToken
}

func IsTemplateLiteralToken(node *Node) bool {
return IsTemplateLiteralKind(node.Kind)
}

func IsSignedNumericLiteral(node *Node) bool {
if node.Kind == KindPrefixUnaryExpression {
node := node.AsPrefixUnaryExpression()
Expand Down Expand Up @@ -2952,3 +2964,75 @@ func GetPropertyNameForPropertyNameNode(name *Node) string {
}
panic("Unhandled case in getPropertyNameForPropertyNameNode")
}

func HasQuestionToken(node *Node) bool {
switch node.Kind {
case KindParameter:
return node.AsParameterDeclaration().QuestionToken != nil
case KindMethodDeclaration:
return IsQuestionToken(node.AsMethodDeclaration().PostfixToken)
case KindShorthandPropertyAssignment:
return IsQuestionToken(node.AsShorthandPropertyAssignment().PostfixToken)
case KindMethodSignature:
return IsQuestionToken(node.AsMethodSignatureDeclaration().PostfixToken)
case KindPropertySignature:
return IsQuestionToken(node.AsPropertySignatureDeclaration().PostfixToken)
case KindPropertyAssignment:
return IsQuestionToken(node.AsPropertyAssignment().PostfixToken)
case KindPropertyDeclaration:
return IsQuestionToken(node.AsPropertyDeclaration().PostfixToken)
}
return false
}

func IsJsxOpeningLikeElement(node *Node) bool {
return IsJsxOpeningElement(node) || IsJsxSelfClosingElement(node)
}

func GetInvokedExpression(node *Node) *Node {
switch node.Kind {
case KindTaggedTemplateExpression:
return node.AsTaggedTemplateExpression().Tag
case KindJsxOpeningElement, KindJsxSelfClosingElement:
return node.TagName()
case KindBinaryExpression:
return node.AsBinaryExpression().Right
default:
return node.Expression()
}
}

func IsCallOrNewExpression(node *Node) bool {
return IsCallExpression(node) || IsNewExpression(node)
}

func CanHaveSymbol(node *Node) bool {
switch node.Kind {
case KindArrowFunction, KindBinaryExpression, KindBindingElement, KindCallExpression, KindCallSignature,
KindClassDeclaration, KindClassExpression, KindClassStaticBlockDeclaration, KindConstructor, KindConstructorType,
KindConstructSignature, KindElementAccessExpression, KindEnumDeclaration, KindEnumMember, KindExportAssignment, KindJSExportAssignment,
KindExportDeclaration, KindExportSpecifier, KindFunctionDeclaration, KindFunctionExpression, KindFunctionType,
KindGetAccessor, KindIdentifier, KindImportClause, KindImportEqualsDeclaration, KindImportSpecifier,
KindIndexSignature, KindInterfaceDeclaration, KindJSDocSignature, KindJSDocTypeLiteral,
KindJsxAttribute, KindJsxAttributes, KindJsxSpreadAttribute, KindMappedType, KindMethodDeclaration,
KindMethodSignature, KindModuleDeclaration, KindNamedTupleMember, KindNamespaceExport, KindNamespaceExportDeclaration,
KindNamespaceImport, KindNewExpression, KindNoSubstitutionTemplateLiteral, KindNumericLiteral, KindObjectLiteralExpression,
KindParameter, KindPropertyAccessExpression, KindPropertyAssignment, KindPropertyDeclaration, KindPropertySignature,
KindSetAccessor, KindShorthandPropertyAssignment, KindSourceFile, KindSpreadAssignment, KindStringLiteral,
KindTypeAliasDeclaration, KindJSTypeAliasDeclaration, KindTypeLiteral, KindTypeParameter, KindVariableDeclaration:
return true
}
return false
}

func IndexOfNode(nodes []*Node, node *Node) int {
index, ok := slices.BinarySearchFunc(nodes, node, compareNodePositions)
if ok {
return index
}
return -1
}

func compareNodePositions(n1, n2 *Node) int {
return n1.Pos() - n2.Pos()
}
45 changes: 26 additions & 19 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7703,7 +7703,7 @@ func (c *Checker) createArrayLiteralType(t *Type) *Type {

func isSpreadIntoCallOrNew(node *ast.Node) bool {
parent := ast.WalkUpParenthesizedExpressions(node.Parent)
return ast.IsSpreadElement(parent) && isCallOrNewExpression(parent.Parent)
return ast.IsSpreadElement(parent) && ast.IsCallOrNewExpression(parent.Parent)
}

func (c *Checker) checkQualifiedName(node *ast.Node, checkMode CheckMode) *Type {
Expand Down Expand Up @@ -7943,7 +7943,7 @@ func (c *Checker) checkDeprecatedSignature(sig *Signature, node *ast.Node) {
}
if sig.declaration != nil && sig.declaration.Flags&ast.NodeFlagsDeprecated != 0 {
suggestionNode := c.getDeprecatedSuggestionNode(node)
name := tryGetPropertyAccessOrIdentifierToString(getInvokedExpression(node))
name := tryGetPropertyAccessOrIdentifierToString(ast.GetInvokedExpression(node))
c.addDeprecatedSuggestionWithSignature(suggestionNode, sig.declaration, name, c.signatureToString(sig))
}
}
Expand Down Expand Up @@ -8409,7 +8409,7 @@ type CallState struct {
func (c *Checker) resolveCall(node *ast.Node, signatures []*Signature, candidatesOutArray *[]*Signature, checkMode CheckMode, callChainFlags SignatureFlags, headMessage *diagnostics.Message) *Signature {
isTaggedTemplate := node.Kind == ast.KindTaggedTemplateExpression
isDecorator := node.Kind == ast.KindDecorator
isJsxOpeningOrSelfClosingElement := isJsxOpeningLikeElement(node)
isJsxOpeningOrSelfClosingElement := ast.IsJsxOpeningLikeElement(node)
isInstanceof := node.Kind == ast.KindBinaryExpression
reportErrors := !c.isInferencePartiallyBlocked && candidatesOutArray == nil
var s CallState
Expand Down Expand Up @@ -8715,7 +8715,7 @@ func (c *Checker) hasCorrectArity(node *ast.Node, args []*ast.Node, signature *S
argCount = c.getDecoratorArgumentCount(node, signature)
case ast.IsBinaryExpression(node):
argCount = 1
case isJsxOpeningLikeElement(node):
case ast.IsJsxOpeningLikeElement(node):
callIsIncomplete = node.Attributes().End() == node.End()
if callIsIncomplete {
return true
Expand Down Expand Up @@ -8835,7 +8835,7 @@ func (c *Checker) checkTypeArguments(signature *Signature, typeArgumentNodes []*
}

func (c *Checker) isSignatureApplicable(node *ast.Node, args []*ast.Node, signature *Signature, relation *Relation, checkMode CheckMode, reportErrors bool, inferenceContext *InferenceContext, diagnosticOutput *[]*ast.Diagnostic) bool {
if isJsxOpeningLikeElement(node) {
if ast.IsJsxOpeningLikeElement(node) {
return c.checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors, diagnosticOutput)
}
thisType := c.getThisTypeOfSignature(signature)
Expand Down Expand Up @@ -8976,7 +8976,7 @@ func (c *Checker) getEffectiveCheckNode(argument *ast.Node) *ast.Node {
}

func (c *Checker) inferTypeArguments(node *ast.Node, signature *Signature, args []*ast.Node, checkMode CheckMode, context *InferenceContext) []*Type {
if isJsxOpeningLikeElement(node) {
if ast.IsJsxOpeningLikeElement(node) {
return c.inferJsxTypeArguments(node, signature, checkMode, context)
}
// If a contextual type is available, infer from that type to the return type of the call expression. For
Expand Down Expand Up @@ -10825,7 +10825,7 @@ func (c *Checker) isMethodAccessForCall(node *ast.Node) bool {
for ast.IsParenthesizedExpression(node.Parent) {
node = node.Parent
}
return isCallOrNewExpression(node.Parent) && node.Parent.Expression() == node
return ast.IsCallOrNewExpression(node.Parent) && node.Parent.Expression() == node
}

// Lookup the private identifier lexically.
Expand Down Expand Up @@ -11041,7 +11041,7 @@ func (c *Checker) isUncalledFunctionReference(node *ast.Node, symbol *ast.Symbol
parent = node.Parent
}
if ast.IsCallLikeExpression(parent) {
return isCallOrNewExpression(parent) && ast.IsIdentifier(node) && c.hasMatchingArgument(parent, node)
return ast.IsCallOrNewExpression(parent) && ast.IsIdentifier(node) && c.hasMatchingArgument(parent, node)
}
return core.Every(symbol.Declarations, func(d *ast.Node) bool {
return !ast.IsFunctionLike(d) || c.IsDeprecatedDeclaration(d)
Expand Down Expand Up @@ -14158,7 +14158,7 @@ func (c *Checker) getTargetOfAliasLikeExpression(expression *ast.Node, dontResol
}

func (c *Checker) getTargetOfNamespaceExportDeclaration(node *ast.Node, dontResolveAlias bool) *ast.Symbol {
if canHaveSymbol(node.Parent) {
if ast.CanHaveSymbol(node.Parent) {
resolved := c.resolveExternalModuleSymbol(node.Parent.Symbol(), dontResolveAlias)
c.markSymbolOfAliasDeclarationIfTypeOnly(node, nil /*immediateTarget*/, resolved, false /*overwriteEmpty*/, nil, "")
return resolved
Expand Down Expand Up @@ -25962,16 +25962,23 @@ func (c *Checker) markPropertyAsReferenced(prop *ast.Symbol, nodeForCheckWriteOn
c.symbolReferenceLinks.Get(target).referenceKinds |= ast.SymbolFlagsAll
}

func (c *Checker) GetExpandedParameters(signature *Signature /* !!! skipUnionExpanding */) []*ast.Symbol {
func (c *Checker) getExpandedParameters(signature *Signature, skipUnionExpanding bool) [][]*ast.Symbol {
if signatureHasRestParameter(signature) {
restIndex := len(signature.parameters) - 1
restSymbol := signature.parameters[restIndex]
restType := c.getTypeOfSymbol(restSymbol)
if isTupleType(restType) {
return c.expandSignatureParametersWithTupleMembers(signature, restType.AsTypeReference(), restIndex, restSymbol)
return [][]*ast.Symbol{c.expandSignatureParametersWithTupleMembers(signature, restType.AsTypeReference(), restIndex, restSymbol)}
} else if !skipUnionExpanding && restType.flags&TypeFlagsUnion != 0 && core.Every(restType.AsUnionType().Types(), isTupleType) {
result := [][]*ast.Symbol{}
for _, t := range restType.AsUnionType().Types() {
result = append(result, c.expandSignatureParametersWithTupleMembers(signature, t.AsTypeReference(), restIndex, restSymbol))
}
return result
}

}
return signature.parameters
return [][]*ast.Symbol{signature.parameters}
}

func (c *Checker) expandSignatureParametersWithTupleMembers(signature *Signature, restType *TypeReference, restIndex int, restSymbol *ast.Symbol) []*ast.Symbol {
Expand Down Expand Up @@ -26452,7 +26459,7 @@ func (c *Checker) markLinkedReferences(location *ast.Node, hint ReferenceHint, p
c.markExportAssignmentAliasReferenced(location)
return
}
if isJsxOpeningLikeElement(location) || ast.IsJsxOpeningFragment(location) {
if ast.IsJsxOpeningLikeElement(location) || ast.IsJsxOpeningFragment(location) {
c.markJsxAliasReferenced(location)
return
}
Expand Down Expand Up @@ -26617,7 +26624,7 @@ func (c *Checker) markJsxAliasReferenced(node *ast.Node /*JsxOpeningLikeElement
jsxFactoryRefErr := core.IfElse(c.compilerOptions.Jsx == core.JsxEmitReact, diagnostics.This_JSX_tag_requires_0_to_be_in_scope_but_it_could_not_be_found, nil)
jsxFactoryNamespace := c.getJsxNamespace(node)
jsxFactoryLocation := node
if isJsxOpeningLikeElement(node) {
if ast.IsJsxOpeningLikeElement(node) {
jsxFactoryLocation = node.TagName()
}
// allow null as jsxFragmentFactory
Expand Down Expand Up @@ -27259,7 +27266,7 @@ func (c *Checker) getContextualType(node *ast.Node, contextFlags ContextFlags) *
return c.getContextualType(parent.Parent, contextFlags)
case ast.KindArrayLiteralExpression:
t := c.getApparentTypeOfContextualType(parent, contextFlags)
elementIndex := indexOfNode(parent.AsArrayLiteralExpression().Elements.Nodes, node)
elementIndex := ast.IndexOfNode(parent.AsArrayLiteralExpression().Elements.Nodes, node)
firstSpreadIndex, lastSpreadIndex := c.getSpreadIndices(parent)
return c.getContextualTypeForElementExpression(t, elementIndex, len(parent.AsArrayLiteralExpression().Elements.Nodes), firstSpreadIndex, lastSpreadIndex)
case ast.KindConditionalExpression:
Expand Down Expand Up @@ -27662,7 +27669,7 @@ func (c *Checker) getContextualTypeForArgumentAtIndex(callTarget *ast.Node, argI
} else {
signature = c.getResolvedSignature(callTarget, nil, CheckModeNormal)
}
if isJsxOpeningLikeElement(callTarget) && argIndex == 0 {
if ast.IsJsxOpeningLikeElement(callTarget) && argIndex == 0 {
return c.getEffectiveFirstArgumentForJsxSignature(signature, callTarget)
}
restIndex := len(signature.parameters) - 1
Expand Down Expand Up @@ -27908,7 +27915,7 @@ func (c *Checker) getEffectiveCallArguments(node *ast.Node) []*ast.Node {
case ast.IsBinaryExpression(node):
// Handles instanceof operator
return []*ast.Node{node.AsBinaryExpression().Left}
case isJsxOpeningLikeElement(node):
case ast.IsJsxOpeningLikeElement(node):
if len(node.Attributes().AsJsxAttributes().Properties.Nodes) != 0 || (ast.IsJsxOpeningElement(node) && len(node.Parent.Children().Nodes) != 0) {
return []*ast.Node{node.Attributes()}
}
Expand Down Expand Up @@ -29761,7 +29768,7 @@ func (c *Checker) getTypeOfNode(node *ast.Node) *Type {
}

if isTypeDeclaration(node) {
// In this case, we call getSymbolOfDeclaration instead of getSymbolAtLocation because it is a declaration
// In this case, we call GetSymbolOfDeclaration instead of getSymbolAtLocation because it is a declaration
symbol := c.getSymbolOfDeclaration(node)
return c.getDeclaredTypeOfSymbol(symbol)
}
Expand All @@ -29783,7 +29790,7 @@ func (c *Checker) getTypeOfNode(node *ast.Node) *Type {
}

if ast.IsDeclaration(node) {
// In this case, we call getSymbolOfDeclaration instead of getSymbolLAtocation because it is a declaration
// In this case, we call GetSymbolOfDeclaration instead of getSymbolLAtocation because it is a declaration
symbol := c.getSymbolOfDeclaration(node)
if symbol != nil {
return c.getTypeOfSymbol(symbol)
Expand Down
36 changes: 36 additions & 0 deletions internal/checker/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,39 @@ func GetDeclarationModifierFlagsFromSymbol(s *ast.Symbol) ast.ModifierFlags {
func (c *Checker) WasCanceled() bool {
return c.wasCanceled
}

func (c *Checker) GetSignaturesOfType(t *Type, kind SignatureKind) []*Signature {
return c.getSignaturesOfType(t, kind)
}

func (c *Checker) GetTypePredicateOfSignature(sig *Signature) *TypePredicate {
return c.getTypePredicateOfSignature(sig)
}

func IsTupleType(t *Type) bool {
return isTupleType(t)
}

func (c *Checker) GetReturnTypeOfSignature(sig *Signature) *Type {
return c.getReturnTypeOfSignature(sig)
}

func (c *Checker) HasEffectiveRestParameter(signature *Signature) bool {
return c.hasEffectiveRestParameter(signature)
}

func (c *Checker) GetLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol *ast.Symbol) []*Type {
return c.getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol)
}

func (c *Checker) GetContextualTypeForObjectLiteralElement(element *ast.Node, contextFlags ContextFlags) *Type {
return c.getContextualTypeForObjectLiteralElement(element, contextFlags)
}

func (c *Checker) TypePredicateToString(t *TypePredicate) string {
return c.typePredicateToString(t)
}

func (c *Checker) GetExpandedParameters(signature *Signature, skipUnionExpanding bool) [][]*ast.Symbol {
return c.getExpandedParameters(signature, skipUnionExpanding)
}
2 changes: 1 addition & 1 deletion internal/checker/jsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (c *Checker) checkJsxAttributes(node *ast.Node, checkMode CheckMode) *Type
}

func (c *Checker) checkJsxOpeningLikeElementOrOpeningFragment(node *ast.Node) {
isNodeOpeningLikeElement := isJsxOpeningLikeElement(node)
isNodeOpeningLikeElement := ast.IsJsxOpeningLikeElement(node)
if isNodeOpeningLikeElement {
c.checkGrammarJsxElement(node)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ func (p *Printer) printSignature(sig *Signature, returnSeparator string) {
p.printType(p.c.getTypeOfSymbol(sig.thisParameter))
tail = true
}
expandedParameters := p.c.GetExpandedParameters(sig)
expandedParameters := p.c.getExpandedParameters(sig, true)[0]
// If the expanded parameter list had a variadic in a non-trailing position, don't expand it
parameters := core.IfElse(core.Some(expandedParameters, func(s *ast.Symbol) bool {
return s != expandedParameters[len(expandedParameters)-1] && s.CheckFlags&ast.CheckFlagsRestParameter != 0
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/relater.go
Original file line number Diff line number Diff line change
Expand Up @@ -2693,7 +2693,7 @@ func (r *Relater) hasExcessProperties(source *Type, target *Type, reportErrors b
if r.errorNode == nil {
panic("No errorNode in hasExcessProperties")
}
if ast.IsJsxAttributes(r.errorNode) || isJsxOpeningLikeElement(r.errorNode) || isJsxOpeningLikeElement(r.errorNode.Parent) {
if ast.IsJsxAttributes(r.errorNode) || ast.IsJsxOpeningLikeElement(r.errorNode) || ast.IsJsxOpeningLikeElement(r.errorNode.Parent) {
// JsxAttributes has an object-literal flag and undergo same type-assignablity check as normal object-literal.
// However, using an object-literal error message will be very confusing to the users so we give different a message.
if prop.ValueDeclaration != nil && ast.IsJsxAttribute(prop.ValueDeclaration) && ast.GetSourceFileOfNode(r.errorNode) == ast.GetSourceFileOfNode(prop.ValueDeclaration.Name()) {
Expand Down
21 changes: 18 additions & 3 deletions internal/checker/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/printer"
)

func (c *Checker) GetSymbolsInScope(location *ast.Node, meaning ast.SymbolFlags) []*ast.Symbol {
Expand Down Expand Up @@ -303,10 +304,14 @@ func runWithInferenceBlockedFromSourceNode[T any](c *Checker, node *ast.Node, fn
return result
}

func runWithoutResolvedSignatureCaching[T any](c *Checker, node *ast.Node, fn func() T) T {
ancestorNode := ast.FindAncestor(node, func(n *ast.Node) bool {
return ast.IsCallLikeOrFunctionLikeExpression(n)
func GetResolvedSignatureForSignatureHelp(node *ast.Node, candidatesOutArray *[]*Signature, argumentCount int, c *Checker) *Signature {
return runWithoutResolvedSignatureCaching(c, node, func() *Signature {
return c.getResolvedSignatureWorker(node, candidatesOutArray, CheckModeIsForSignatureHelp, argumentCount)
})
}

func runWithoutResolvedSignatureCaching[T any](c *Checker, node *ast.Node, fn func() T) T {
ancestorNode := ast.FindAncestor(node, ast.IsCallLikeOrFunctionLikeExpression)
if ancestorNode != nil {
cachedResolvedSignatures := make(map[*SignatureLinks]*Signature)
cachedTypes := make(map[*ValueSymbolLinks]*Type)
Expand Down Expand Up @@ -481,3 +486,13 @@ func (c *Checker) GetJsxIntrinsicTagNamesAt(location *ast.Node) []*ast.Symbol {
func (c *Checker) GetContextualTypeForJsxAttribute(attribute *ast.JsxAttributeLike) *Type {
return c.getContextualTypeForJsxAttribute(attribute, ContextFlagsNone)
}

func (c *Checker) getResolvedSignatureWorker(node *ast.Node, candidatesOutArray *[]*Signature, checkMode CheckMode, argumentCount int) *Signature {
parsedNode := printer.NewEmitContext().ParseNode(node)
c.apparentArgumentCount = &argumentCount
var res *Signature = nil
if parsedNode != nil {
res = c.getResolvedSignature(parsedNode, candidatesOutArray, checkMode)
}
return res
}
Loading