Python Delphi/Object Pascal parser, semantic indexer, and language server.
Project description
Python Delphi LSP
Python Delphi LSP is a standalone Python package for Delphi/Object Pascal parsing, semantic indexing, diagnostics, and Language Server Protocol support.
The distributable package is named python-delphi-lsp. The import package keeps
the established delphiast name, and the language-server executable is
delphi-lsp.
What It Provides
- Parser support for
.pas,.dpr,.dpk, and.incfiles - Delphi preprocessor handling for include files, conditionals, and compiler directives
- Semantic symbols for units, types, methods, fields, properties, variables, constants, and references
- Workspace indexing across Delphi projects
- LSP support for document symbols, workspace symbols, hover, definition, references, rename, completion, and diagnostics
- opencode integration through the experimental LSP tool
Installation
Install the package from a built distribution or from PyPI once published:
python -m pip install python-delphi-lsp
For development from a checkout:
python -m venv .venv
. .venv/bin/activate
python -m pip install -e ".[dev]"
python -m pytest -q
On Windows PowerShell:
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -e ".[dev]"
python -m pytest -q
Python API Example
from delphiast import parse
result = parse("unit Unit1; interface implementation end.", "Unit1.pas")
print(result.root)
Enable semantic analysis when you need symbols or diagnostics:
from delphiast import parse
source = """
unit Unit1;
interface
type
TGreeter = class
public
procedure SayHello;
end;
implementation
procedure TGreeter.SayHello;
begin
end;
end.
"""
result = parse(source, "Unit1.pas", build_semantic=True)
for symbol in result.semantic.symbols:
print(symbol.name, symbol.kind)
Language Server Usage
Start the LSP server over stdio:
delphi-lsp
From a checkout, the equivalent command is:
python -m delphiast.lsp_server
The server expects normal LSP JSON-RPC over stdio. Editors and tools should set the workspace root to the Delphi project directory and pass any include paths or compiler defines through LSP initialization options when needed.
opencode Usage
This repository includes an opencode.json that registers the Delphi LSP tool
and model aliases for local Ollama and vLLM endpoints.
For normal local opencode work, use the Ollama alias with a larger context:
opencode run --dir . --model ollama/ornith-lspctx
For large Delphi files, prefer LSP operations over reading the file into the
model prompt. The reduced vllm-lsp agent disables filesystem and shell tools
and leaves only the LSP tool enabled:
OPENCODE_EXPERIMENTAL_LSP_TOOL=true \
python scripts/run_opencode_lsp_probe.py \
--cwd output/mega_lsp_chain_project \
--model vllm/ornith-lspctx \
--agent vllm-lsp \
--require-tool lsp.workspaceSymbol:MegaProc02500 \
--forbid-tool bash --forbid-tool read --forbid-tool glob --forbid-tool grep \
--forbid-tool edit --forbid-tool write --forbid-tool task \
--forbid-tool webfetch --forbid-tool todowrite --forbid-tool skill \
'Use only the Delphi LSP tool. In file Mega100kUnit.pas, run workspaceSymbol with filePath "Mega100kUnit.pas", line 1, character 1, and query "MegaProc02500".'
For an LSP-first edit proof, use vllm-lsp-edit. It permits the opencode edit
tool after LSP lookup while still forbidding shell and direct file-reading tools:
OPENCODE_EXPERIMENTAL_LSP_TOOL=true \
python scripts/run_opencode_lsp_probe.py \
--cwd output/mega_lsp_chain_project \
--model vllm/ornith-lspctx \
--agent vllm-lsp-edit \
--require-tool lsp.workspaceSymbol:MegaProc02500 \
--require-tool 'edit:Edit applied successfully' \
--forbid-tool bash --forbid-tool read --forbid-tool glob --forbid-tool grep \
--forbid-tool write --forbid-tool task --forbid-tool webfetch \
--forbid-tool todowrite --forbid-tool skill \
'Use LSP first, then edit the exact MegaProc02500 block.'
Reproducing the vLLM opencode Test
The vLLM test is designed to prove that opencode can work on Delphi files larger than the model context by calling LSP instead of loading the source file into the prompt.
The test does the following:
- Creates
output/mega_lsp_chain_project/Mega100kUnit.pas, a generated Delphi unit with more than 100,000 lines and the symbolMegaProc02500. - Writes an opencode sandbox config with an absolute
delphi-lspcommand andPYTHONPATHpointing at the checkout. - Uses
vllm/ornith-lspctxwith the reducedvllm-lspagent. - Requires a completed
lsp.workspaceSymboltool call that returnsMegaProc02500. - Fails immediately if opencode calls
read,bash,glob,grep,edit,write,task,webfetch,todowrite, orskill.
On macOS, start the local vLLM helper and run the proof:
scripts/bootstrap_vllm_opencode_test.sh --start-vllm
By default the vLLM helper is offline-only. It checks the Hugging Face cache and
does not download model shards. Pass --allow-download only when you explicitly
want the helper to fill missing cache files.
On Windows PowerShell, use an already running vLLM-compatible endpoint:
.\scripts\bootstrap_vllm_opencode_test.ps1 -UseRunningServer
Use a custom endpoint when vLLM runs in WSL, Docker, or on another machine:
.\scripts\bootstrap_vllm_opencode_test.ps1 -UseRunningServer -BaseUrl "http://127.0.0.1:8001/v1"
The macOS helper uses these defaults:
MODEL_ID=deepreinforce-ai/Ornith-1.0-9BSERVED_MODEL_NAME=ornith-vllm-metalMAX_MODEL_LEN=44352MAX_NUM_SEQS=1VLLM_METAL_MEMORY_FRACTION=0.97TOOL_CALL_PARSER=qwen3_xml
The release evidence from the local proof recorded:
- default opencode request: 29,318 system-prompt characters and 10 tool schemas
- reduced LSP-only request: 8,978 system-prompt characters and 1 tool schema
- generated test unit: 117k lines
- GitHub corpus file: 14,309 lines
context_budget.status = "pass"goal_audit.status = "pass"
Verification
Run the local test suite:
python -m pytest -q
Generate the Delphi language-feature matrix:
python scripts/audit_delphi_language_features.py
Build and check distributable artifacts:
python -m build
python -m twine check dist/*
Repository Layout
delphiast/- parser, preprocessor, semantic model, workspace indexer, and LSP serverscripts/- release evidence, cache checks, opencode probes, and bootstrap helperstests/- parser, semantic, workspace, diagnostics, packaging, and LSP teststests/fixtures/- Delphi/Object Pascal fixtures and legacy DelphiAST snippets
License
This project is licensed under the Mozilla Public License 2.0. See
LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_delphi_lsp-1.0.0.tar.gz.
File metadata
- Download URL: python_delphi_lsp-1.0.0.tar.gz
- Upload date:
- Size: 125.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff92b44477b3a72061f4b108f724165e399b7762718ea58b142e104c8c0169a3
|
|
| MD5 |
a65866fa19e63b3aa969601d610efb25
|
|
| BLAKE2b-256 |
01156246fe2a1e233b5d436425598003d784294adbc7661cb3ee2fd8dcd359ff
|
File details
Details for the file python_delphi_lsp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: python_delphi_lsp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 72.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf00717dd117bbb36a2317525e88d50e1de6f643ebca7df6e5d4be98094746de
|
|
| MD5 |
640fcbfd7dd445966c8e8be2204ff33b
|
|
| BLAKE2b-256 |
0aeadbd7e848aa7ed14cfaabc349316fdbc1a8752e8be282a2b41c731f1a133c
|