Skip to content

Commit ed79f5d

Browse files
Fix panic in completions within import attributes (#2293)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: DanielRosenwasser <[email protected]>
1 parent b0b5d75 commit ed79f5d

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// !!! can delete, there are similar tests that haven't been ported yet.
11+
func TestCompletionImportAttributes(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `
15+
// @target: esnext
16+
// @module: esnext
17+
// @filename: main.ts
18+
import yadda1 from "yadda" with {/*attr*/}
19+
import yadda2 from "yadda" with {attr/*attrEnd1*/: true}
20+
import yadda3 from "yadda" with {attr: /*attrValue*/}
21+
22+
// @filename: yadda
23+
export default {};
24+
`
25+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
26+
defer done()
27+
28+
f.GoToEachMarker(t, nil, func(marker *fourslash.Marker, index int) {
29+
f.VerifyCompletions(t, marker, nil)
30+
})
31+
}

internal/ls/completions.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,10 @@ func (l *LanguageService) getCompletionData(
13691369
if importAttributes.AsImportAttributes().Attributes != nil {
13701370
elements = importAttributes.AsImportAttributes().Attributes.Nodes
13711371
}
1372-
existing := collections.NewSetFromItems(core.Map(elements, (*ast.Node).Text)...)
1372+
attributeNames := core.Map(elements, func(el *ast.Node) string {
1373+
return el.AsImportAttribute().Name().Text()
1374+
})
1375+
existing := collections.NewSetFromItems(attributeNames...)
13731376
uniques := core.Filter(
13741377
typeChecker.GetApparentProperties(typeChecker.GetTypeAtLocation(importAttributes)),
13751378
func(symbol *ast.Symbol) bool {

0 commit comments

Comments
 (0)