FPC Toolkit now supports a template-based project creation system that allows users to quickly create new projects using predefined templates and supports custom templates.
- Built-in Default Templates: Includes standard FPC project templates
- Custom Template Support: Users can create and use their own project templates
- Template Variable Substitution: Supports automatic replacement of variables like date, time, username, etc.
- Multi-file Templates: Supports complex project templates containing multiple files
- Task Configuration: Templates can include pre-configured build tasks
- Click the "+" button in the FPC Projects view, or use the command
FpcToolkit: Create New Project - Select a template from the available template list
- The project will be created based on the template, including files and build configuration
If no templates are found, the system will prompt to initialize the default template directory:
- Select "Initialize Templates"
- The system will create a
templatesfolder in the workspace root directory - Includes a sample console application template
templates/
├── console-app/
│ ├── template.json
│ ├── main.lpr
│ └── README.md
└── my-custom-template/
├── template.json
├── program.lpr
├── unit1.pas
└── config.ini
{
"name": "Console Application",
"description": "A simple console application template",
"files": [
{
"source": "main.lpr",
"target": "main.lpr",
"cursorPosition": { "line": 6, "column": 4 }
},
{
"source": "README.md",
"target": "README.md"
}
],
"tasks": [
{
"label": "debug",
"file": "main.lpr",
"type": "fpc",
"presentation": {
"showReuseMessage": false,
"clear": true,
"revealProblems": "onProblem"
},
"buildOption": {
"unitOutputDir": "./out",
"customOptions": ["-dDEBUG", "-gw2"]
}
}
]
}- name: Template display name
- description: Template description
- files: Template file list
- source: Source file name in template directory
- target: Target file name when creating project
- cursorPosition: Optional, cursor position when file is opened
- tasks: Optional, pre-configured build tasks
The following variables can be used in template files and will be automatically replaced when creating projects:
{{DATE}}: Current date{{TIME}}: Current time{{YEAR}}: Current year{{MONTH}}: Current month (two digits){{DAY}}: Current day (two digits){{USER}}: Current username{{PROJECT_NAME}}: Project name
program {{PROJECT_NAME}};
{$mode objfpc}{$H+}
uses
Classes, SysUtils;
begin
WriteLn('Hello from {{PROJECT_NAME}}!');
WriteLn('Created on: {{DATE}} at {{TIME}}');
WriteLn('Author: {{USER}}');
// Add your code here
WriteLn('Press Enter to exit...');
ReadLn;
end.program {{PROJECT_NAME}};
{$mode objfpc}{$H+}
uses
Classes, SysUtils,
{{PROJECT_NAME}}unit;
begin
WriteLn('Program with Unit Example');
WriteLn('Created by {{USER}} on {{DATE}}');
// Call function from our unit
SayHello('{{USER}}');
WriteLn('Current year: ', GetCurrentYear);
WriteLn('Press Enter to exit...');
ReadLn;
end.unit {{PROJECT_NAME}}unit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
// Public procedures and functions
procedure SayHello(const Name: string);
function GetCurrentYear: Integer;
implementation
procedure SayHello(const Name: string);
begin
WriteLn('Hello, ', Name, '! Welcome to Pascal programming.');
end;
function GetCurrentYear: Integer;
begin
Result := CurrentYear;
end;
end.Configure fpctoolkit.project.templateDirectories in VS Code settings to specify additional template search directories:
{
"fpctoolkit.project.templateDirectories": [
"/path/to/my/templates",
"./project-templates",
"~/my-pascal-templates"
]
}Supports:
- Absolute paths
- Paths relative to workspace root
- User home directory paths (~)
fpctoolkit.project.newproject: Create new project (shows template selection)fpctoolkit.project.newfromtemplate: Create new project from template (alias)fpctoolkit.project.inittemplatedir: Initialize default template directory
- Template Naming: Use descriptive template names
- File Organization: Keep related files in the same template directory
- Task Configuration: Provide appropriate build configurations for templates
- Documentation: Include README files in templates explaining usage
- Variable Usage: Use template variables appropriately to improve reusability
Migrating from old project creation methods:
- The old "New FPC Project" functionality is now provided as a built-in template
- "New Custom Project" functionality is replaced by the template system
- Existing projects are not affected, only new project creation is impacted
- Check if template directory exists
- Confirm template.json file format is correct
- Check VS Code developer console for error messages
- Check file paths and permissions
- Confirm template files exist and are readable
- Verify target directory is writable
- Check tasks.json syntax
- Confirm build options are correct
- Verify file path references
-
Open VS Code and Load Project
- Make sure you're in the FPC Toolkit project root directory
-
Test Template System
- Press F5 to start extension development host
- Open an empty workspace in the new window
- Click the "+" button in FPC Projects view
- Should see available template list including:
- "New FPC Project" (built-in default template)
- "Simple Console App" (if templates directory exists)
- "Program with Unit" (if templates directory exists)
-
Create Project
- Select a template
- Project files should be created
- Template variables should be correctly replaced
- Build tasks should be added to tasks.json
-
Test Initialization Feature
- In a workspace without templates
- Run "Create New Project" command
- Should prompt to initialize template directory
- Select "Initialize Templates"
- Should create default template directory and sample templates
- ✅ Template list displays correctly
- ✅ File creation successful
- ✅ Variable substitution works normally
- ✅ Task configuration added correctly
- ✅ Cursor position set correctly
- ✅ Custom template directory support
- ✅ Initialization feature works normally
- Template Validation: Currently no strict template format validation
- Error Handling: Error messages when template loading fails may not be detailed enough
- Variable Expansion: Currently only supports basic date/time/user variables
- File Overwrite: Does not check if files already exist when creating projects
- More Variables: Support project name, workspace path and other variables
- Template Validation: Add template format validation and error reporting
- Template Management: Provide template management interface
- Online Templates: Support downloading templates from remote repositories
- Template Wizard: Provide interactive template creation wizard