From ece2b2a59ea939014350a0a732253d45c596796b Mon Sep 17 00:00:00 2001 From: arookieofc <2128194521@qq.com> Date: Mon, 2 Nov 2026 23:37:41 +0800 Subject: [PATCH] feat(templates): New Go Module template for go.mod files (#884) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New ▸ Go Module creates go.mod with `module $PROJECT_NAME$` and a `go 1.20` directive. The go.mod language, icon and gopls were already registered; only the file template was missing. It also appears in Search Everywhere and Settings ▸ File and Code Templates. Fixes #882 Co-authored-by: a-rookie-of-C-language <186315048+a-rookie-of-C-language@users.noreply.github.com> --- src/features/templates/__tests__/files.test.ts | 6 ++++-- src/features/templates/files/builtins.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/features/templates/__tests__/files.test.ts b/src/features/templates/__tests__/files.test.ts index f1aa7872..431bbddb 100644 --- a/src/features/templates/__tests__/files.test.ts +++ b/src/features/templates/__tests__/files.test.ts @@ -70,15 +70,17 @@ describe("file naming", () => { expect(withKind(css, kind("css"))).toBe(css); }); - it("prefills fixed names (Dockerfile, .editorconfig, .gitignore)", () => { + it("prefills fixed names (Dockerfile, .editorconfig, .gitignore, go.mod)", () => { for (const [id, name] of [ ["dockerfile", "Dockerfile"], ["editorconfig", ".editorconfig"], ["gitignore", ".gitignore"], + ["go-mod", "go"], ] as const) { const t = tpl(id); expect(t.defaultName).toBe(name); - expect(planFile(t, "/p", t.defaultName!)?.path).toBe(`/p/${name}`); + const ext = t.extension ? `.${t.extension}` : ""; + expect(planFile(t, "/p", t.defaultName!)?.path).toBe(`/p/${name}${ext}`); } }); diff --git a/src/features/templates/files/builtins.ts b/src/features/templates/files/builtins.ts index 7f92c16a..6e008311 100644 --- a/src/features/templates/files/builtins.ts +++ b/src/features/templates/files/builtins.ts @@ -140,6 +140,15 @@ export const BUILTIN_FILE_TEMPLATES: readonly FileTemplate[] = [ { id: "main", label: "Main", body: "package main\n\nfunc main() {\n\t$END$\n}\n" }, ], }, + { + id: "go-mod", + name: "Go Module", + icon: "file-gomod", + extension: "mod", + nameStyle: "asis", + defaultName: "go", + kinds: [{ id: "module", label: "Module", body: "module $PROJECT_NAME$\n\ngo 1.20\n" }], + }, { id: "java", name: "Java Class",