Файли
openidea/src/platform/fileTemplates.ts
T
Arnaud Ritti f6531542de feat(plugins): add fixed filenames and file template variables (#2032)
Closes #1954

Plugin file templates could only take a typed name plus a fixed extension, so dot-files such as .dockerignore and templates needing more than a name weren't expressible. Templates (API ^1.3) can now declare a fixed `fileName` and named `variables` that the New File dialog asks for, and plugin templates get the same Java/Kotlin/Go/PHP package inference as built-in ones. Unsafe filenames and existing files are refused. The dialog no longer submits on Enter while an IME is composing, and its variable form has proper padding. Adds a file-templates test fixture.

Co-authored-by: arnaud-ritti <[email protected]>
2026-11-08 02:37:26 +08:00

35 рядки
1.2 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
export type NameStyle = "asis" | "snake" | "pascal" | "kebab";
export interface FileTemplateKind {
id: string;
label: string;
body: string;
/** Overrides the template's extension (Stylesheet › CSS / SCSS / Less). */
extension?: string;
}
export interface FileTemplate {
id: string;
/** Menu label, e.g. "Rust File". */
name: string;
icon: string;
/** Without the dot; empty for "File…" (the name carries the extension). */
extension: string;
nameStyle: NameStyle;
/** Package inference: `jvm` (Java/Kotlin source roots) or `go` (directory). */
packageStyle?: "jvm" | "go" | "php";
/** Dotted names (`com.acme.Foo`) create package directories. */
dottedPackages?: boolean;
kinds: FileTemplateKind[];
enabled?: boolean;
/** Prefilled name for fixed-name files (`Dockerfile`, `.editorconfig`). */
defaultName?: string;
/** Exact filename supplied by a plugin; skips the name prompt. */
fileName?: string;
variables?: { name: string; prompt: string }[];
/** Infer package style from the extension using the built-in rules. */
inferPackage?: boolean;
/** Reformat according to style: run Reformat Code on the new file (unset: on, as IDEA). */
reformat?: boolean;
}