From cb54a696bdde8a9fbcde76d83c5c4acdf8dad037 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 07:31:58 +0000 Subject: [PATCH 1/5] Initial plan From d667a7c8b0cbf9e2e0feb9e044110992a27a99f6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 07:50:09 +0000 Subject: [PATCH 2/5] Fix panic in completions request within import attributes Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com> --- internal/ast/ast.go | 2 + .../tests/completionImportAttributes_test.go | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 internal/fourslash/tests/completionImportAttributes_test.go diff --git a/internal/ast/ast.go b/internal/ast/ast.go index d1d6d62a0a..1b814dd092 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -334,6 +334,8 @@ func (n *Node) Text() string { return strings.Join(n.AsJSDocLinkCode().text, "") case KindJSDocLinkPlain: return strings.Join(n.AsJSDocLinkPlain().text, "") + case KindImportAttribute: + return n.AsImportAttribute().Name().Text() } panic(fmt.Sprintf("Unhandled case in Node.Text: %T", n.data)) } diff --git a/internal/fourslash/tests/completionImportAttributes_test.go b/internal/fourslash/tests/completionImportAttributes_test.go new file mode 100644 index 0000000000..f16cd22dc0 --- /dev/null +++ b/internal/fourslash/tests/completionImportAttributes_test.go @@ -0,0 +1,38 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +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() + + // Test completion at empty attributes + // This should not panic + f.VerifyCompletions(t, "attr", nil) + + // Test completion after attribute name + // This should not panic + f.VerifyCompletions(t, "attrEnd1", nil) + + // Test completion at attribute value position + // This should not panic + f.VerifyCompletions(t, "attrValue", nil) +} From 3584f6a8071d9264bbf653951daaa9ad991aa883 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 07:52:52 +0000 Subject: [PATCH 3/5] Format test file (remove trailing whitespace) Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com> --- internal/fourslash/tests/completionImportAttributes_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/fourslash/tests/completionImportAttributes_test.go b/internal/fourslash/tests/completionImportAttributes_test.go index f16cd22dc0..468e6e30e6 100644 --- a/internal/fourslash/tests/completionImportAttributes_test.go +++ b/internal/fourslash/tests/completionImportAttributes_test.go @@ -27,11 +27,11 @@ export default {}; // Test completion at empty attributes // This should not panic f.VerifyCompletions(t, "attr", nil) - + // Test completion after attribute name // This should not panic f.VerifyCompletions(t, "attrEnd1", nil) - + // Test completion at attribute value position // This should not panic f.VerifyCompletions(t, "attrValue", nil) From c60874787460f4d727b90bc8f8b3695354a2f9e1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 09:00:58 +0000 Subject: [PATCH 4/5] Address review feedback: fix panic in completions code instead of ast.go Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com> --- internal/ast/ast.go | 2 -- internal/fourslash/tests/completionImportAttributes_test.go | 1 + internal/ls/completions.go | 5 ++++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/ast/ast.go b/internal/ast/ast.go index 1b814dd092..d1d6d62a0a 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -334,8 +334,6 @@ func (n *Node) Text() string { return strings.Join(n.AsJSDocLinkCode().text, "") case KindJSDocLinkPlain: return strings.Join(n.AsJSDocLinkPlain().text, "") - case KindImportAttribute: - return n.AsImportAttribute().Name().Text() } panic(fmt.Sprintf("Unhandled case in Node.Text: %T", n.data)) } diff --git a/internal/fourslash/tests/completionImportAttributes_test.go b/internal/fourslash/tests/completionImportAttributes_test.go index 468e6e30e6..a3efadf3ad 100644 --- a/internal/fourslash/tests/completionImportAttributes_test.go +++ b/internal/fourslash/tests/completionImportAttributes_test.go @@ -7,6 +7,7 @@ import ( "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") 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 { From 6037f0797dfef6d9a99f136667e4b323d06317e1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 09:21:01 +0000 Subject: [PATCH 5/5] Use GoToEachMarker for cleaner test iteration Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com> --- .../tests/completionImportAttributes_test.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/internal/fourslash/tests/completionImportAttributes_test.go b/internal/fourslash/tests/completionImportAttributes_test.go index a3efadf3ad..95ecfa2f0e 100644 --- a/internal/fourslash/tests/completionImportAttributes_test.go +++ b/internal/fourslash/tests/completionImportAttributes_test.go @@ -25,15 +25,7 @@ export default {}; f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) defer done() - // Test completion at empty attributes - // This should not panic - f.VerifyCompletions(t, "attr", nil) - - // Test completion after attribute name - // This should not panic - f.VerifyCompletions(t, "attrEnd1", nil) - - // Test completion at attribute value position - // This should not panic - f.VerifyCompletions(t, "attrValue", nil) + f.GoToEachMarker(t, nil, func(marker *fourslash.Marker, index int) { + f.VerifyCompletions(t, marker, nil) + }) }