diff --git a/internal/fourslash/tests/completionImportAttributes_test.go b/internal/fourslash/tests/completionImportAttributes_test.go new file mode 100644 index 0000000000..95ecfa2f0e --- /dev/null +++ b/internal/fourslash/tests/completionImportAttributes_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +// !!! can delete, there are similar tests that haven't been ported yet. +func TestCompletionImportAttributes(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +// @target: esnext +// @module: esnext +// @filename: main.ts +import yadda1 from "yadda" with {/*attr*/} +import yadda2 from "yadda" with {attr/*attrEnd1*/: true} +import yadda3 from "yadda" with {attr: /*attrValue*/} + +// @filename: yadda +export default {}; +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + + f.GoToEachMarker(t, nil, func(marker *fourslash.Marker, index int) { + f.VerifyCompletions(t, marker, nil) + }) +} diff --git a/internal/ls/completions.go b/internal/ls/completions.go index a7f38f4afd..2b9f0e7e90 100644 --- a/internal/ls/completions.go +++ b/internal/ls/completions.go @@ -1369,7 +1369,10 @@ func (l *LanguageService) getCompletionData( if importAttributes.AsImportAttributes().Attributes != nil { elements = importAttributes.AsImportAttributes().Attributes.Nodes } - existing := collections.NewSetFromItems(core.Map(elements, (*ast.Node).Text)...) + attributeNames := core.Map(elements, func(el *ast.Node) string { + return el.AsImportAttribute().Name().Text() + }) + existing := collections.NewSetFromItems(attributeNames...) uniques := core.Filter( typeChecker.GetApparentProperties(typeChecker.GetTypeAtLocation(importAttributes)), func(symbol *ast.Symbol) bool {