pi-lsp-extension
v0.1.1
Published
Pi coding agent extension for LSP (Language Server Protocol) integration
Downloads
189
Readme
pi-lsp-extension
A pi coding agent extension that integrates Language Server Protocol (LSP) servers, giving the LLM access to the same language intelligence that powers your IDE.
Tools
| Tool | Description |
|------|-------------|
| lsp_diagnostics | Compilation errors and warnings for a file |
| lsp_hover | Type information and documentation at a position |
| lsp_definition | Go to definition of a symbol |
| lsp_references | Find all references to a symbol |
| lsp_symbols | List file symbols or search workspace symbols |
| lsp_rename | Preview rename refactoring (returns planned edits) |
LSP servers start lazily — they only spin up when a tool is first used on a file of that language.
Auto-diagnostics
After a successful write or edit, if an LSP server is already running for that file type, the extension automatically appends compilation errors to the tool result. This gives the LLM immediate feedback without requiring a separate lsp_diagnostics call.
- Scoped to the single changed file (no workspace-wide noise)
- Only errors, max 10 lines — keeps context lean
- Only fires when a server is already running (no lazy startup)
Installation
git clone https://github.com/samfoy/pi-lsp-extension.git
cd pi-lsp-extension
npm installAdd to your pi settings.json:
{
"extensions": ["/path/to/pi-lsp-extension/src/index.ts"]
}Or run directly:
pi -e /path/to/pi-lsp-extension/src/index.tsSupported Languages
Install the language server you need, then it works automatically:
| Language | Server | Install |
|----------|--------|---------|
| TypeScript/JavaScript | typescript-language-server | npm i -g typescript-language-server typescript |
| Python | pyright-langserver | pip install pyright |
| Rust | rust-analyzer | rustup |
| Go | gopls | go install golang.org/x/tools/gopls@latest |
| Java | jdtls | Eclipse JDT.LS |
Add more at runtime:
/lsp-config ruby solargraph stdio
/lsp-config lua lua-language-serverCommands
| Command | Description |
|---------|-------------|
| /lsp | Show status of running LSP servers |
| /lsp-config <lang> <cmd> [args] | Configure a language server |
| /lsp-lombok [path] | Set Lombok jar path for Java (or show current) |
| /bemol [run\|watch\|stop\|status] | Manage bemol (Brazil workspaces) |
How it Works
- Lazy startup — servers start on first tool use for a file type
- File sync — pi's
read/write/editoperations are automatically synced to the LSP viadidOpen/didChange - Diagnostics cache — the server pushes diagnostics asynchronously; tools read from a local cache
- Auto-diagnostics — errors are appended to write/edit results when a server is running
- Shared daemons — in supported workspaces, LSP servers run as background daemons shared across pi sessions
Lombok Support (Java)
If your Java project uses Lombok, jdtls needs the Lombok agent jar to understand generated code. The extension resolves the jar in this order:
/lsp-lombokcommand — set the path at runtime:/lsp-lombok /path/to/lombok.jarLOMBOK_JARenvironment variable — set before starting pi:export LOMBOK_JAR=/path/to/lombok.jar piAuto-detection — in Brazil workspaces, the extension searches
env/Lombok-*/runtime/lib/andenv/gradle-cache-2/automatically.
Run /lsp-lombok with no arguments to see which jar is currently configured.
Architecture
src/
├── index.ts # Extension entry point
├── lsp-client.ts # JSON-RPC client (stdio + socket modes)
├── lsp-manager.ts # Server lifecycle, per-language instances
├── file-sync.ts # didOpen/didChange tracking
├── lsp-daemon.ts # Background daemon for shared servers
├── lsp-daemon-launcher.cjs
├── bemol.ts # Brazil workspace support
├── locks.ts # File-based locking for daemon coordination
└── tools/
├── diagnostics.ts
├── hover.ts
├── definition.ts
├── references.ts
├── symbols.ts
└── rename.tsTips
- Position parameters are 1-indexed (line 1, column 1 = first character)
lsp_renamereturns a preview — the LLM usesedit/writeto apply changes- The extension adds a system prompt guideline nudging the LLM to check diagnostics after edits
License
MIT
