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
31 changes: 31 additions & 0 deletions internal/fourslash/tests/completionImportAttributes_test.go
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a few other completions tests like completionListForImportAttributes.ts that already work on import specifiers via baselineCompletions but I don't think we have VerifyBaselineCompletions 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)
})
}
5 changes: 4 additions & 1 deletion internal/ls/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down