-
Notifications
You must be signed in to change notification settings - Fork 941
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
Changes from 43 commits
f7b2484
202e970
fff762c
cbdb32b
5d8476c
dcd021f
473fbed
0d73105
d68643b
ed043a8
e8c5dae
0c01e98
7acd18e
4a359ec
0ccbd20
151f03a
85cdb01
a22ab20
e57cf78
50a3bbe
4bc1228
f415ca2
ace6765
e836eb1
31bfa2a
aafc78f
1bf462c
8f34a4f
7a4c633
d8db5cc
9c81431
628f4b4
0ff32ac
7469666
e621d71
7792a6e
21b43cd
c61cf81
5b1f838
98de4c1
093ff05
8fca88c
09d531a
ddb78d2
9a3b8f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
|
@@ -299,10 +300,17 @@ func runWithInferenceBlockedFromSourceNode[T any](c *Checker, node *ast.Node, fn | |
| return result | ||
| } | ||
|
|
||
| func GetResolvedSignatureForSignatureHelp(node *ast.Node, argumentCount int, c *Checker) (*Signature, []*Signature) { | ||
| var candidatesOutArray []*Signature | ||
| return runWithoutResolvedSignatureCaching(c, node, func() *Signature { | ||
| var res *Signature | ||
| res, candidatesOutArray = c.getResolvedSignatureWorker(node, CheckModeIsForSignatureHelp, argumentCount) | ||
| return res | ||
| }), candidatesOutArray | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this technically works due to the evaluation order of multi-returns, but it kinda hurts my head. I'd personally rather this callback return a struct with the two results (which are then unpacked or returned as-is), or this call be split out into its own line before the return.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e.g. func GetResolvedSignatureForSignatureHelp(node *ast.Node, argumentCount int, c *Checker) (*Signature, []*Signature) {
type result struct {
signature *signature
candidates []*signature
}
result := runWithoutResolvedSignatureCaching(c, node, func() result {
signature, candidates := c.getResolvedSignatureWorker(node, CheckModeIsForSignatureHelp, argumentCount)
return result{signature, candidates}
})
return result.signature, result.candidates
} |
||
| } | ||
|
|
||
| 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) | ||
| }) | ||
| ancestorNode := ast.FindAncestor(node, ast.IsCallLikeOrFunctionLikeExpression) | ||
| if ancestorNode != nil { | ||
| cachedResolvedSignatures := make(map[*SignatureLinks]*Signature) | ||
| cachedTypes := make(map[*ValueSymbolLinks]*Type) | ||
|
|
@@ -506,3 +514,15 @@ func (c *Checker) GetConstantValue(node *ast.Node) any { | |
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (c *Checker) getResolvedSignatureWorker(node *ast.Node, checkMode CheckMode, argumentCount int) (*Signature, []*Signature) { | ||
| parsedNode := printer.NewEmitContext().ParseNode(node) | ||
| c.apparentArgumentCount = &argumentCount | ||
|
andrewbranch marked this conversation as resolved.
|
||
| candidatesOutArray := &[]*Signature{} | ||
| var res *Signature | ||
| if parsedNode != nil { | ||
| res = c.getResolvedSignature(parsedNode, candidatesOutArray, checkMode) | ||
| } | ||
| c.apparentArgumentCount = nil | ||
| return res, *candidatesOutArray | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.