FreePascal Toolkit is a VS Code extension for developing FreePascal programs.
For Chinese documentation, see 中文文档.
- Install Lazarus or FreePascal.
- The extension will automatically search for the FPC path. If not found, please add FPC to your system PATH, or set
fpctoolkit.env.PPin the extension settings. - Install GDB Debugger - Beyond for debugging.
- Project Management - Build, rebuild, and clean FreePascal and Lazarus programs
- Project Templates - Create new projects from built-in or custom templates with variable substitution
- Lazarus LPI Support - Full project file support with multi-mode build management and lazbuild integration
- Advanced Build System - Customizable tasks with inheritance and cross-platform compilation
- Code Intelligence - Auto-completion, go-to-definition, and symbol references
- Code Snippets - Rich templates for rapid development
- Syntax Highlighting - Pascal syntax with conditional compilation support
- Code Formatting - Integrated jcf cli formatter
- Quick Fixes - Smart suggestions and auto-corrections
- Refactoring - Symbol renaming and code actions
- MCP Server - Model Context Protocol server for AI assistant integration
- Project Templates: Template-based project creation system
- Built-in templates for console applications and modular programs
- Custom template support with variable substitution (date, time, username, project name)
- Multi-file templates with pre-configured build tasks
- Template initialization and management commands
- Lazarus LPI Project Support: Automatically detects and parses
.lpiproject files, extracts all build modes, and supports multi-mode build management with intelligent compiler selection (lazbuild preferred, fpc fallback) - Advanced Task System:
- Customize build tasks with inheritance
- Support for custom build options (target platform/CPU, output directory, compiler flags, etc.)
- Cross-platform and multi-architecture compilation (Linux/Windows/macOS, x86_64/i386, etc.)
- Pre/post build event support for automation and integration
- Seamless management of mixed FreePascal and Lazarus projects
-
Smart Auto-completion: Intelligent completion for functions, procedures, classes, variables, and keywords
-
Navigation:
- Use
Ctrl+UpandCtrl+Downto jump between declaration and implementation - Class and function references with document outline
- Use
-
Syntax Highlighting:
- Advanced Pascal syntax highlighting
- Identify compilation conditions such as
{$IFDEF} {$ELSE} {$ENDIF}
-
Code Formatting:
- Format source code using integrated jcf cli
- Uses
jcfsettings.cfgas config, or Lazarus config if installed
-
Quick Fixes: Smart suggestions for common issues
- Quick fix for
(5025) Local variable "xxx" not used
- Quick fix for
-
Refactoring Tools:
- Auto rename symbols (functions, classes, variables, and their references)
- Use
Ctrl+Shift+Cto auto-implement procedures - Remove unused units and clean up code
-
Code Snippets: Rich templates including class, if-else, begin-end, and more
Create new Pascal projects quickly using built-in or custom templates:
- Simple Console App: Basic console application with greeting message
- Program with Unit: Demonstrates modular programming with separate unit files
- Variable Substitution: Automatic replacement of
{{DATE}},{{TIME}},{{USER}},{{PROJECT_NAME}} - Multi-file Support: Templates can include multiple source files, documentation, and configuration
- Pre-configured Tasks: Templates include debug and release build configurations
- Custom Templates: Create your own templates in the
templates/directory
- Click the "+" button in FPC Projects view or use
Ctrl+Shift+P→ "FpcToolkit: Create New Project" - Select from available templates
- Project files are created with variables automatically replaced
- Build tasks are configured and ready to use
For detailed template creation and customization, see the Template Guide.
- MCP Server: Model Context Protocol server for AI assistants
- Get compile commands for Pascal files
- Project information extraction
- Source file analysis
- Enable with
fpctoolkit.mcp.enabledsetting
Based on pascal-language-server
An LSP server implementation for Pascal variants supported by FreePascal, including Object Pascal. It uses CodeTools from Lazarus as the backend.
You can add FreePascal or Lazarus compile tasks by editing tasks.json in your .vscode folder.
The task's type is fpc. The following configuration options are available:
| Field | Type | Description |
|---|---|---|
| file | string | Free Pascal project file (.lpr, .dpr) |
| type | string | Always fpc |
| cwd | string | Working directory. Uses workspace root if not set. |
| cleanExt | string | File extensions to clean when cleaning the project. Use * to clear all files. Default: (.o, .ppu, .lfm, .a, .or, .res) |
| buildOption | object | Build options |
| inherited | string | Inherit from another task |
| Field | Type | Description |
|---|---|---|
| before_build | string[] | Commands to run before the build starts |
| after_build_success | string[] | Commands to run after a successful build |
| after_build_failure | string[] | Commands to run after a failed build |
| Field | Type | Description |
|---|---|---|
| targetOS | string | Target OS (-T), e.g. linux, win64 |
| targetCPU | string | Target CPU family (-P), e.g. x86_64, i386 |
| customOptions | string[] | Any compile options for FPC |
| libPath | string[] | Library search path (-Fl) |
| outputFile | string | Target file name (-o) |
| unitOutputDir | string | Unit output directory (-FU) |
| optimizationLevel | number | Optimization level (-O) |
| searchPath | string[] | Unit search path (-Fu) |
| syntaxMode | string | Syntax mode (-M) |
| forceRebuild | boolean | Re-compile all used units, even if the unit sources didn’t change since the last compilation (-B) |
| msgIgnore | number[] | List of message numbers to ignore (-vmxxx) |
| Field | Type | Description |
|---|---|---|
| cleanExt | string | File extensions to clean when cleaning the project. Use * to clear all files. Default: (.o, .ppu, .lfm, .a, .or, .res) |
| inherited | string | Inherit from another task |
| buildEvent | object | Pre/post build event commands (e.g., before_build, after_build_success, after_build_failure) |
{
"version": "2.0.0",
"tasks": [
{
"label": "debug",
"file": "main.lpr",
"type": "fpc",
"buildOption": {
"unitOutputDir": "./out",
"customOptions": [
"-dDEBUG",
"-gw2"
]
}
}
]
}For detailed documentation, see:
- Configuration Guide (English) / 配置指南 (中文)
- Template Guide (English) / 模板指南 (中文)
- Lazbuild Usage Guide (English) / Lazbuild 使用指南 (中文)
Syntax files from https://github.com/maresmar/ST-Pascal
Modified from https://github.com/git-bee/jcf-cli
Modified from: https://github.com/genericptr/pascal-language-server https://github.com/arjanadriaanse/pascal-language-server