Skip to content

Commit 0fb0d6e

Browse files
authored
Merge pull request #52 from narumiruna/feat/pi-lsp-config-routes
feat(lsp): use simple server config
2 parents 14729ad + 7b1bac1 commit 0fb0d6e

10 files changed

Lines changed: 473 additions & 625 deletions

File tree

extensions/pi-lsp/README.md

Lines changed: 81 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
# 🧠 pi-lsp — Shared Language Server Tools for Pi
1+
# 🧠 pi-lsp — Configurable Language Server Tools for Pi
22

33
[![npm](https://img.shields.io/npm/v/@narumitw/pi-lsp)](https://www.npmjs.com/package/@narumitw/pi-lsp) [![Pi extension](https://img.shields.io/badge/Pi-extension-blue)](https://pi.dev) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
44

5-
`@narumitw/pi-lsp` is a native [Pi coding agent](https://pi.dev) extension that exposes Biome, ty, and Ruff language-server behavior through language/file-extension routed Pi tools.
5+
`@narumitw/pi-lsp` is a native [Pi coding agent](https://pi.dev) extension that exposes diagnostics and source-fix tools through configurable Language Server Protocol routes.
66

7-
It supersedes the older split packages `@narumitw/pi-biome-lsp` and `@narumitw/pi-python-lsp`, which now live under `extensions/deprecated/` and are excluded from active workspace scripts.
7+
The extension is language-agnostic: servers are selected by config and file extension instead of hard-coded language families.
88

99
## ✨ Features
1010

11-
- Routes Biome-supported web/config files to `biome lsp-proxy` for diagnostics, formatting, import organization, and source fixes.
12-
- Routes Python `.py` and `.pyi` type diagnostics to `ty server`.
13-
- Routes Python `.py` and `.pyi` lint diagnostics, formatting, import organization, and source fixes to `ruff server`.
14-
- Uses one internal LSP runner for JSON-RPC framing, subprocess lifecycle, diagnostics, formatting, code actions, and workspace edit application.
15-
- Keeps Biome, ty, and Ruff behavior in small server adapters.
16-
- Supports workspace roots, file limits, recursive file discovery, language overrides, and write-or-preview edits.
11+
- Configure LSP servers with simple JSON keyed by server name.
12+
- Routes diagnostics and source fixes by configured file extensions.
13+
- Supports multiple servers for the same extension, for example `ty` and `ruff` for `.py`/`.pyi` diagnostics.
14+
- Uses one internal LSP runner for JSON-RPC framing, subprocess lifecycle, diagnostics, code actions, and workspace edit application.
15+
- Supports workspace roots, file limits, recursive file discovery, server overrides, and write-or-preview edits.
1716
- Starts language servers only for tool calls, then shuts them down.
1817
- Shows statusline activity only while LSP tools are running.
1918

@@ -23,182 +22,127 @@ It supersedes the older split packages `@narumitw/pi-biome-lsp` and `@narumitw/p
2322
pi install npm:@narumitw/pi-lsp
2423
```
2524

26-
Try without installing permanently:
27-
28-
```bash
29-
pi -e npm:@narumitw/pi-lsp
30-
```
31-
3225
Try this package locally from the repository root:
3326

3427
```bash
3528
pi -e ./extensions/pi-lsp
3629
```
3730

38-
## ⚠️ Tool-name compatibility
39-
40-
This package now exposes three language/file-extension routed tools instead of the old backend-specific tool names:
31+
## ⚙️ Configuration
4132

42-
| Old tool | New call |
43-
| --- | --- |
44-
| `biome_lsp_diagnostics` | `lsp_diagnostics` with `language: "web"` when an override is needed |
45-
| `biome_lsp_format` | `lsp_format` for a Biome-supported file |
46-
| `biome_lsp_fix` | `lsp_fix` for a Biome-supported file |
47-
| `ty_lsp_diagnostics` | `lsp_diagnostics` with `language: "python"`, `checker: "type"` |
48-
| `ruff_lsp_diagnostics` | `lsp_diagnostics` with `language: "python"`, `checker: "lint"` |
49-
| `ruff_lsp_format` | `lsp_format` for a Python file |
50-
| `ruff_lsp_fix` | `lsp_fix` for a Python file |
33+
If no config is provided, pi-lsp ships compatible defaults for Biome, ty, and Ruff.
5134

52-
Avoid installing `@narumitw/pi-lsp` side by side with the older deprecated LSP packages unless you have verified how your Pi version handles overlapping capabilities.
35+
Custom config can be supplied in one of these locations:
5336

54-
## ✅ Requirements
37+
1. `PI_LSP_CONFIG` as inline JSON or a path to a JSON file
38+
2. `<workspace>/.pi/lsp.json`
39+
3. `~/.pi/agent/lsp.json`
5540

56-
Install the language servers you want to use somewhere on `PATH`:
41+
`lsp.json` can be a plain object keyed by server name:
5742

58-
```bash
59-
uv tool install ty
60-
uv tool install ruff
43+
```json
44+
{
45+
"ty": {
46+
"command": ["ty", "server"],
47+
"extensions": [".py", ".pyi"]
48+
},
49+
"ruff": {
50+
"command": ["ruff", "server"],
51+
"extensions": [".py", ".pyi"]
52+
},
53+
"biome": {
54+
"command": ["biome", "lsp-proxy"],
55+
"extensions": [
56+
".astro",
57+
".css",
58+
".graphql",
59+
".gql",
60+
".html",
61+
".js",
62+
".jsx",
63+
".json",
64+
".jsonc",
65+
".ts",
66+
".tsx",
67+
".vue"
68+
]
69+
}
70+
}
6171
```
6272

63-
For Biome, either install it globally/on `PATH`, add your project's `node_modules/.bin` to `PATH`, or point the extension at a project-local command. For example:
73+
Use `servers` when you need global pi-lsp options such as timeout:
6474

65-
```bash
66-
npm install -D @biomejs/biome
67-
PI_BIOME_LSP_COMMAND="./node_modules/.bin/biome lsp-proxy" pi -e ./extensions/pi-lsp
75+
```json
76+
{
77+
"timeout": 30000,
78+
"servers": {
79+
"ty": {
80+
"command": ["ty", "server"],
81+
"extensions": [".py", ".pyi"],
82+
"env": {
83+
"LSP_LOG": "debug"
84+
},
85+
"initialization": {
86+
"settings": {}
87+
}
88+
}
89+
}
90+
}
6891
```
6992

70-
Or provide custom server commands:
93+
Each server entry supports:
7194

72-
```bash
73-
PI_BIOME_LSP_COMMAND="npx biome lsp-proxy" \
74-
PI_TY_LSP_COMMAND="uvx ty server" \
75-
PI_RUFF_LSP_COMMAND="uvx ruff server" \
76-
pi -e ./extensions/pi-lsp
77-
```
95+
- `command`: argv array used to start the LSP server.
96+
- `extensions`: file extensions that should route to this server.
97+
- `env`: extra environment variables for the LSP server process.
98+
- `initialization`: LSP initialization options and workspace configuration values.
7899

79-
Optional timeout overrides:
100+
Global options:
101+
102+
- `timeout`: request timeout in milliseconds. Defaults to `20000`.
103+
104+
pi-lsp infers `languageId` from common extensions and falls back to the extension without the leading dot.
105+
106+
Per-server command overrides still use the normalized server name:
80107

81108
```bash
82-
PI_BIOME_LSP_TIMEOUT_MS=30000 \
83-
PI_TY_LSP_TIMEOUT_MS=30000 \
84-
PI_RUFF_LSP_TIMEOUT_MS=30000 \
109+
PI_TY_LSP_COMMAND="uvx ty server" \
110+
PI_RUFF_LSP_COMMAND="uvx ruff server" \
85111
pi -e ./extensions/pi-lsp
86112
```
87113

88114
## 🛠️ Pi tools
89115

90116
### `lsp_diagnostics`
91117

92-
Run diagnostics through language/file-extension routes.
118+
Run diagnostics through configured servers.
93119

94120
Parameters:
95121

96122
- `paths?`: files or directories to check. Defaults to the workspace root.
97123
- `root?`: workspace root. Defaults to cwd.
98-
- `limit?`: maximum files to open per selected route.
99-
- `language?`: optional override, either `"web"` for Biome-supported web/config files or `"python"` for `.py`/`.pyi` files.
100-
- `checker?`: Python diagnostics checker, one of `"type"`, `"lint"`, or `"all"`. Defaults to `"all"`.
101-
102-
Routes:
103-
104-
- Biome-supported web/config files → Biome diagnostics.
105-
- Python `.py`/`.pyi` + `checker: "type"` → ty diagnostics.
106-
- Python `.py`/`.pyi` + `checker: "lint"` → Ruff diagnostics.
107-
- Python `.py`/`.pyi` + `checker: "all"` → both ty and Ruff diagnostics.
108-
109-
### `lsp_format`
110-
111-
Format one file through the route selected from its file extension.
112-
113-
Parameters:
114-
115-
- `path`: file to format.
116-
- `root?`: workspace root. Defaults to cwd.
117-
- `write?`: write formatted text back to the file. Defaults to false.
118-
- `language?`: optional route override, either `"web"` or `"python"`.
119-
120-
Routes:
121-
122-
- Biome-supported web/config files → Biome formatting.
123-
- Python `.py`/`.pyi` files → Ruff formatting.
124+
- `limit?`: maximum files to open per selected server.
125+
- `server?`: configured server name, or an array of names. Defaults to all matching servers.
124126

125127
### `lsp_fix`
126128

127-
Apply source fixes or import organization through the route selected from the file extension.
129+
Apply source fixes or import organization through a configured server that matches its extension. If multiple servers match, pass `server` explicitly.
128130

129131
Parameters:
130132

131133
- `path`: file to fix.
132134
- `root?`: workspace root. Defaults to cwd.
133-
- `kind?`: source action kind. Defaults to the routed backend's fix-all action.
135+
- `kind?`: source action kind. Defaults to `source.fixAll`.
134136
- `write?`: write fixed text back to the file. Defaults to false.
135-
- `language?`: optional route override, either `"web"` or `"python"`.
136-
137-
Routes:
138-
139-
- Biome-supported web/config files → Biome source fixes such as `source.fixAll.biome` or `source.organizeImports.biome`.
140-
- Python `.py`/`.pyi` files → Ruff source fixes such as `source.fixAll.ruff` or `source.organizeImports.ruff`.
141-
142-
## 🚀 Examples
143-
144-
Check a mixed project subset and run all applicable diagnostics:
145-
146-
```json
147-
{
148-
"paths": ["src", "extensions/pi-lsp/src"],
149-
"limit": 100
150-
}
151-
```
152-
153-
Check only Biome-supported web/config files:
154-
155-
```json
156-
{
157-
"language": "web",
158-
"paths": ["extensions/pi-lsp/src"],
159-
"limit": 100
160-
}
161-
```
162-
163-
Check Python type diagnostics only:
164-
165-
```json
166-
{
167-
"language": "python",
168-
"checker": "type",
169-
"paths": ["src", "tests"],
170-
"limit": 100
171-
}
172-
```
173-
174-
Format a TypeScript file with the inferred Biome route:
175-
176-
```json
177-
{
178-
"path": "src/index.ts",
179-
"write": true
180-
}
181-
```
182-
183-
Organize Python imports with the inferred Ruff route:
184-
185-
```json
186-
{
187-
"path": "src/app.py",
188-
"kind": "source.organizeImports.ruff",
189-
"write": true
190-
}
191-
```
192-
193-
If `paths` is omitted for diagnostics, the tool recursively discovers supported files under the workspace root while skipping common generated, dependency, cache, and virtualenv directories.
137+
- `server?`: optional configured server name.
194138

195139
## 💬 Command
196140

197141
```text
198142
/lsp
199143
```
200144

201-
Shows the configured Biome, ty, and Ruff LSP commands and whether each command is available on `PATH`.
145+
Shows configured LSP commands and whether each command is available on `PATH`.
202146

203147
## 🗂️ Package layout
204148

@@ -220,10 +164,6 @@ extensions/pi-lsp/
220164
└── package.json
221165
```
222166

223-
## 🔎 Keywords
224-
225-
Pi extension, Pi coding agent, Language Server Protocol, Biome LSP, ty, Ruff, Python LSP, formatter, linter, import organization, AI coding tools.
226-
227167
## 📄 License
228168

229169
MIT. See [`LICENSE`](./LICENSE).

extensions/pi-lsp/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@narumitw/pi-lsp",
33
"version": "0.1.26",
4-
"description": "Pi extension that exposes language-server tools for Biome, ty, and Ruff through a shared LSP runner.",
4+
"description": "Pi extension that exposes configurable, language-agnostic LSP tools through a shared runner.",
55
"type": "module",
66
"license": "MIT",
77
"private": false,
@@ -10,12 +10,11 @@
1010
"pi-extension",
1111
"pi",
1212
"lsp",
13-
"biome",
14-
"python",
15-
"ty",
16-
"ruff",
13+
"language-server-protocol",
14+
"configurable",
1715
"lint",
18-
"format"
16+
"diagnostics",
17+
"code-action"
1918
],
2019
"files": [
2120
"src",

0 commit comments

Comments
 (0)