Skip to content

Commit 473b341

Browse files
authored
Fix crash in import statement completions (#2805)
1 parent c2908f5 commit 473b341

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/testutil"
8+
)
9+
10+
func TestCompletionsAtTopLevelImportAssignmentNoCrash1(t *testing.T) {
11+
t.Parallel()
12+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
13+
14+
const content = `// @filename: /a.ts
15+
import x =/*1*/
16+
class Foo {}
17+
// @filename: /b.ts
18+
import x = /*2*/
19+
class Foo {}
20+
// @filename: /c.ts
21+
import x =/*3*/
22+
`
23+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
24+
defer done()
25+
26+
f.VerifyCompletions(t, []string{"1", "2", "3"}, &fourslash.CompletionsExpectedList{
27+
IsIncomplete: false,
28+
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
29+
CommitCharacters: &[]string{},
30+
},
31+
Items: &fourslash.CompletionsExpectedItems{
32+
Includes: []fourslash.CompletionsExpectedItem{}, // no crash check
33+
},
34+
})
35+
}

internal/ls/completions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ func (l *LanguageService) getCompletionData(
670670
symbolToSortTextMap := map[ast.SymbolId]SortText{}
671671
var seenPropertySymbols collections.Set[ast.SymbolId]
672672
isTypeOnlyLocation := insideJSDocTagTypeExpression || insideJsDocImportTag ||
673-
importStatementCompletion != nil && ast.IsTypeOnlyImportOrExportDeclaration(location.Parent) ||
673+
importStatementCompletion != nil && location.Parent != nil && ast.IsTypeOnlyImportOrExportDeclaration(location.Parent) ||
674674
!isContextTokenValueLocation(contextToken) &&
675675
(isPossiblyTypeArgumentPosition(contextToken, file, typeChecker) ||
676676
ast.IsPartOfTypeNode(location) ||

0 commit comments

Comments
 (0)