Skip to content

Commit 6f58807

Browse files
Fix panic when auto-importing relative .css augmentation from ESM file (#3845)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
1 parent dd3d9c7 commit 6f58807

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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/fourslash/tests/util"
8+
"github.com/microsoft/typescript-go/internal/ls"
9+
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
10+
"github.com/microsoft/typescript-go/internal/testutil"
11+
)
12+
13+
func TestAutoImportCssModule(t *testing.T) {
14+
t.Parallel()
15+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
16+
const content = `
17+
// @Filename: /tsconfig.json
18+
{ "compilerOptions": { "module": "nodenext", "moduleResolution": "nodenext" } }
19+
20+
// @Filename: /package.json
21+
{ "type": "module" }
22+
23+
// @Filename: /augmentations.ts
24+
export {};
25+
declare module "./styles.css" {
26+
export const myClass: string;
27+
}
28+
29+
// @Filename: /index.ts
30+
myClass/**/
31+
`
32+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
33+
defer done()
34+
// Verify auto-import completions don't panic when importing from .css module augmentation
35+
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
36+
IsIncomplete: false,
37+
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
38+
CommitCharacters: &DefaultCommitCharacters,
39+
EditRange: Ignored,
40+
},
41+
Items: &fourslash.CompletionsExpectedItems{
42+
Includes: []fourslash.CompletionsExpectedItem{
43+
&lsproto.CompletionItem{
44+
Label: "myClass",
45+
Data: &lsproto.CompletionItemData{
46+
AutoImport: &lsproto.AutoImportFix{
47+
ModuleSpecifier: "./styles.css",
48+
},
49+
},
50+
AdditionalTextEdits: fourslash.AnyTextEdits,
51+
SortText: new(string(ls.SortTextAutoImportSuggestions)),
52+
},
53+
},
54+
},
55+
})
56+
}

internal/tspath/extension.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package tspath
22

33
import (
4-
"path/filepath"
54
"slices"
65
"strings"
76
)
@@ -50,8 +49,8 @@ func RemoveFileExtension(path string) string {
5049
return path[:len(path)-len(ext)]
5150
}
5251
}
53-
// Otherwise just remove single dot extension, if any
54-
return path[:len(path)-len(filepath.Ext(path))] //nolint:forbidigo
52+
53+
return path
5554
}
5655

5756
func TryGetExtensionFromPath(p string) string {

0 commit comments

Comments
 (0)