Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

pastree-lsp

PasTree LSP Server and Delphi IDE/VS Code LSP clients

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

PasTree LSP

Object Pascal code intelligence out of process, built on PasTree. One product, three pieces: a Win64 analysis server speaking the Language Server Protocol over JSON-RPC 2.0, a RAD Studio IDE package, and a VS Code extension - both clients of the same server and the same protocol.

What the RAD Studio plugin does - every feature it adds to the IDE, one paragraph each.

Installing it

Unpack the release archive and run install.bat in it, with RAD Studio closed. It builds both halves from source and registers the IDE package - with RAD Studio 13's 64-bit IDE as well, where it is installed; pastree-lsp\uninstall.bat takes it back out.

The archive holds two directories side by side - pastree-lsp and object-pascal-tree - which is the same arrangement this repository is developed in, so the build script users run is the one that is tested here rather than a release-only variant. Keep them beside each other.

Nothing in it is prebuilt. Shipping a compiled pastree-server.exe would mean shipping an unsigned binary - GitHub neither scans release assets for malware nor signs them - and the IDE package has to be compiled locally in any case, since a designtime BPL loads only in the Delphi version that produced it. Building from source removes that question rather than answering it.

Working from a clone instead: the same install.bat, and build.bat fetches PasTree beside the repository if it is not already there. release.bat packs the archive.

The server (pastree-server.exe)

  • Analyzes an Object Pascal project (.dproj/.dpr) out of process and answers standard LSP requests over it: go to definition/declaration, find references, the decl-impl toggle, outline, hover, diagnostics, completion, signature help, rename, workspace symbol search, and more.
  • Runs an edit through incremental reanalysis of the one changed module instead of rebuilding the whole closure, whenever the change qualifies.
  • Analyzes library units (RTL, VCL, third-party - the IDE's library paths) interface-only by default: on a 3,782-unit closure 2.1 s and 1.2 GB instead of 3.8 s and 2.1 GB, the project's own units answered exactly as before. Every answer is still the full analysis's: a library unit is analyzed in full when it is opened, and a request that needs library bodies - Find References, the Find All family, Find All Defines, rename, Unused Units - makes them full first, with progress, through PasTree's workspace. lightLibraries: false turns it off - see SPEC.md, "Light libraries".

Install / requirements

  • Delphi 11.3 or newer (Win64 target). The PasTree repo must sit beside this one as ..\object-pascal-tree; build.bat clones it there if it is missing, and prints the directory, commit and version it compiled against.
  • build.bat at the repository root builds the server (and the RAD Studio package and test harnesses in the same pass - one script produces both halves of the product, which is what makes the version-equality check between them meaningful). RAD Studio must be closed while it runs.
  • No separate install step for the server: it lands in out\, above the IDE packages built alongside it.

Status / docs

Phases 1-2 of the protocol are complete and exercised live; most of phase 3 has landed too. Full protocol coverage, architecture, key decisions and their costs, and the incremental-reanalysis mechanism are in SPEC.md.

The RAD Studio IDE package (clients/rad-studio/)

  • A thin LSP client over ToolsAPI, replacing RAD Studio's own DelphiLSP-based navigation with the server's answers.
  • Ships the Find All submenu - References, Overrides (the VMT chain of a class method), Implementations (of an interface or one of its methods), Descendants (as a tree), Assignments, Creations, Destructions - all project-group-wide and greyed per caret, Go to Declaration/Ctrl+Click, the decl-impl toggle, rename (form files included - through the form designer when the form is loaded), class completion (Ctrl+Shift+C: missing bodies and property accessors), prototype sync, and block completion - each with its own on/off switch in Tools > PasTree > Settings.

Install / requirements

  • install.bat at the repository root, with RAD Studio closed: it builds both halves and registers the package with the IDE. It asks which RAD Studio only when more than one suitable installation is present; install.bat 37.0 or install.bat --yes answers in advance. uninstall.bat unregisters it again without deleting anything built.
  • Both IDEs of RAD Studio 13. Where the 64-bit IDE (bin64\bds.exe) is installed, the package is built for Win64 too and registered with it as well; install.bat 37.0 win32 or ... win64 limits it to one. Delphi
    1. 's 64-bit IDE is not offered yet - the package compiles for it but has not been run in it.
  • Nothing is copied anywhere and no environment variable is needed. The BPL is built into out\<RAD Studio version>\win32\ (and ...\win64\) and pastree-server.exe into out\, two levels above it, and the plugin looks for its server in both places - so the matched pair is where the build put it rather than something a deployment step has to arrange. PASTREE_LSP_SERVER still overrides that, for running a server from somewhere else.
  • Several RAD Studio versions can have it installed at once. Each IDE gets its own BPL directory, since a designtime package loads only in the compiler and bitness that built it; they all share the one server, which is a separate Win64 process. Run install.bat once per version.
  • Restart RAD Studio after every rebuild of the package - hot reload (Uninstall/Install) is unreliable here; see docs/diagnosing.md.

Status / docs

Working and confirmed in a running IDE; most features are verified against a real multi-thousand-unit project, not only the harnesses. What each ToolsAPI surface could still present, and what it would cost, is in clients/rad-studio/SPEC.md; what the package does today, file by file, is in clients/rad-studio/README.md.

The VS Code extension (clients/vscode/)

  • A standard LSP client (vscode-languageclient) for the objectpascal language, plus statement-skeleton snippets and the editor.formatOnType default that block completion needs.
  • Proof that the protocol is genuinely editor-agnostic, not just shaped around the RAD Studio client's needs.

Install / requirements

  • cd clients/vscode && npm install && npx vsce package produces a .vsix; install it into VS Code from there. Requires Node.js and the server binary built separately (build.bat at the repository root) - the extension does not bundle or build it.
  • Point the pastree.serverPath setting (or the relevant pastree.* config) at the built pastree-server.exe and at the target project.

Status / docs

Verified live against the demo project's 197-unit closure: go-to-definition, find-all-references, outline, hover and diagnostics all work. Syntax colouring comes in two layers: a TextMate grammar shipped with the extension for what a lexer can know, and textDocument/semanticTokens from the server for what each identifier resolved to. Extension-specific notes are in clients/vscode/SPEC.md.

Requirements at a glance

  • Windows, Delphi 11.3 or newer (Win64 target) to build the server and the RAD Studio package.
  • The PasTree repo checked out as a sibling: ..\object-pascal-tree.
  • Node.js only if building the VS Code extension.

More

  • SPEC.md - the protocol-side specification: architecture, why the analysis runs out of process, versioning policy, full protocol coverage, key decisions, and what the log contains.
  • clients/rad-studio/SPEC.md - the ToolsAPI-side specification.
  • clients/vscode/SPEC.md - the VS Code extension's own specification.
  • docs/diagnosing.md - procedures for symptoms that have already cost an investigation.