Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions tsc/internal/fourslash/tests/signatureHelpUnclosedParen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/TypeScript/tsc/internal/fourslash"
"github.com/microsoft/TypeScript/tsc/internal/testutil"
)

func TestSignatureHelpUnclosedTypeArgumentHang(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `<()(/**/`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.GoToMarker(t, "")

f.VerifyNoSignatureHelp(t)
}
5 changes: 3 additions & 2 deletions tsc/internal/ls/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,12 +1161,13 @@ func findPrecedingMatchingToken(token *ast.Node, matchingTokenKind ast.Kind, sou
matchingTokenText := scanner.TokenToString(matchingTokenKind)
// Text-scan based fast path - can be bamboozled by comments and other trivia, but often provides
// a good, fast approximation without too much extra work in the cases where it fails.
bestGuessIndex := strings.LastIndex(sourceFile.Text(), matchingTokenText)
precedingText := sourceFile.Text()[:token.Pos()]
bestGuessIndex := strings.LastIndex(precedingText, matchingTokenText)
if bestGuessIndex == -1 {
return nil // if the token text doesn't appear in the file, there can't be a match - super fast bail
}
// we can only use the textual result directly if we didn't have to count any close tokens within the range
if strings.LastIndex(sourceFile.Text(), closeTokenText) < bestGuessIndex {
if strings.LastIndex(precedingText, closeTokenText) < bestGuessIndex {
nodeAtGuess := astnav.FindPrecedingToken(sourceFile, bestGuessIndex+1)
if nodeAtGuess != nil && nodeAtGuess.Kind == matchingTokenKind {
return nodeAtGuess
Expand Down
Loading