Language Server Protocol (LSP) implementation for Pascal/Delphi - Bringing modern IDE features to Pascal development!
- 🔄 Auto-generates LSP types from official Microsoft metaModel.json
- 📚 Preserves documentation - All comments and descriptions maintained
- 🔮 Future-proof - Automatically supports new LSP versions
- 🎨 Clean Pascal code - Generates readable, well-structured types
- ✅ Document Synchronization - Real-time file tracking
- 🔍 Hover Information - Context-aware help on symbols
- ⚡ Code Completion - Smart autocomplete for Pascal keywords
- 🌐 JSON-RPC Communication - Standard LSP protocol support
- 🔧 Extensible Architecture - Easy to add new features
- 📁 File Support -
.pas,.pp,.incfiles - 🎛️ Configuration - Customizable server settings
- 🔄 Server Management - Start/stop/restart commands
- 📊 Output Channel - Debug and logging information
- FreePascal 3.2+ or Delphi 10.4+
- Node.js 16+ (for VS Code extension)
- VS Code 1.60+ (optional, for editor integration)
# Clone the repository
git clone https://github.com/mmfbr/pascal-lsp-types.git
cd pascal-lsp
# Compile and run the generator
fpc -Mobjfpc src/LSPCodeGenerator.pas
./LSPCodeGenerator
# This creates LSPTypes.pas with all LSP 3.17 types# Compile the server
fpc -Mobjfpc src/BasicLSPServer.pas
# Test the server
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | ./BasicLSPServercd vscode-extension
npm install
npm run compile
# Install locally
code --install-extension .program HelloLSP;
{$mode objfpc}{$H+}
uses
Classes, SysUtils;
type
// Hover over TPerson to see documentation
TPerson = record
Name: string;
Age: Integer;
end;
var
Person: TPerson;
begin
// Type "beg" and see completion suggesting "begin"
Person.Name := 'Pascal Developer';
Person.Age := 30;
WriteLn('Hello from ', Person.Name);
// Hover over Person to see type information
end.{
"jsonrpc": "2.0",
"id": 1,
"result": {
"capabilities": {
"textDocumentSync": 2,
"hoverProvider": true,
"completionProvider": {
"triggerCharacters": [".", ":"]
}
},
"serverInfo": {
"name": "Basic Pascal LSP",
"version": "1.0.0"
}
}
}pascal-lsp/
├── src/
│ ├── LSPCodeGenerator.pas # Generates types from metaModel.json
│ ├── BasicLSPServer.pas # Core LSP server implementation
│ └── LSPTypes.pas # Generated LSP types (auto-created)
├── vscode-extension/
│ ├── src/extension.ts # VS Code client
│ ├── package.json # Extension manifest
│ └── language-configuration.json
├── examples/
│ ├── test.pas # Example Pascal files
│ └── server-test.js # Server testing script
└── docs/
├── CONTRIBUTING.md
└── API.md
{
"pascalLSP.serverPath": "./BasicLSPServer",
"pascalLSP.trace.server": "verbose"
}// Current LSP 3.17 support
capabilities := TJSONObject.Create([
'textDocumentSync', 2, // ✅ Incremental sync
'hoverProvider', True, // ✅ Hover information
'completionProvider', TJSONObject.Create([
'triggerCharacters', TJSONArray.Create(['.', ':'])
])
]);- Extend the server: Add handlers in
BasicLSPServer.pas - Use generated types: All LSP types available in
LSPTypes.pas - Test thoroughly: Use the provided test scripts
procedure TLSPServer.HandleTextDocumentDefinition(const AId: TJSONData; const AParams: TJSONObject);
var
Location: TJSONObject;
begin
// Your implementation here
Location := TJSONObject.Create;
Location.Add('uri', 'file:///path/to/definition.pas');
Location.Add('range', CreateRange(lineNum, colNum, lineNum, colNum + length));
SendResponse(AId, Location);
end;# When LSP specification updates
./LSPCodeGenerator # Downloads latest metaModel.json
# LSPTypes.pas is automatically updated with new types- Type generation from metaModel.json
- Basic LSP server structure
- VS Code extension
- Document synchronization
- Hover provider
- Basic completion
- Real Pascal parsing (using FPC parser or custom)
- Go to Definition
- Find References
- Document Symbols (outline view)
- Diagnostics (syntax errors, warnings)
- Code Formatting
- Semantic highlighting
- Rename symbol
- Code actions (quick fixes)
- Signature help (function parameters)
- Workspace symbols (project-wide search)
- Call hierarchy
- Type hierarchy
- Lazarus integration
- Delphi IDE plugin
- Vim/Neovim support
- Emacs support
- Web-based editor
We welcome contributions! Here's how you can help:
- Use GitHub Issues
- Include Pascal code samples
- Describe expected vs actual behavior
- Check existing issues first
- Describe the use case
- Consider implementation complexity
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
# Clone your fork
git clone https://github.com/mmfbr/pascal-lsp-types.git
cd pascal-lsp
# Install dependencies
cd vscode-extension && npm install
# Build everything
make build # or manually compile Pascal files
# Run tests
make test- LSP Specification - Official protocol docs
- FreePascal Manual - Pascal language reference
- VS Code Extensions - Extension development guide
- Contributing Guide - Detailed contribution guidelines
# Start server manually
./BasicLSPServer
# Send initialize request
curl -X POST -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' // After running LSPCodeGenerator, use generated types:
var
Position: TPosition;
Range: TRange;
begin
Position.Line := 10;
Position.Character := 5;
Range.Start := Position;
Range.End_ := CreatePosition(10, 15);
end;- Anders Hejlsberg - Creator of Pascal, Delphi, C#, and TypeScript
- Microsoft LSP Team - LSP specification and tools
- FreePascal Team - Amazing Pascal compiler
- mmfbr - Project creator and maintainer
- Community Contributors - Thank you! 🙏
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2024 Pascal LSP Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- GitHub Repository - Source code
- Issues - Bug reports and feature requests
- Discussions - Community chat
- Wiki - Additional documentation
- Releases - Download stable versions
Made with ❤️ for the Pascal community