Skip to content

Commit 14729ad

Browse files
authored
Merge pull request #51 from narumiruna/feat/pi-lsp-language-routing
feat(pi-lsp): route tools by language
2 parents 950f0ca + e97056b commit 14729ad

5 files changed

Lines changed: 470 additions & 202 deletions

File tree

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
# pi-lsp parity checklist
22

3-
`@narumitw/pi-lsp` keeps the public tool Interface from the now-deprecated `@narumitw/pi-biome-lsp` and `@narumitw/pi-python-lsp` packages while moving common LSP behavior into a shared runner Module.
3+
`@narumitw/pi-lsp` keeps Biome, ty, and Ruff behavior from the now-deprecated `@narumitw/pi-biome-lsp` and `@narumitw/pi-python-lsp` packages while exposing a smaller language/file-extension routed public tool interface.
44

55
## Tool names and parameters
66

7-
- [x] `biome_lsp_diagnostics`: `paths?`, `root?`, `limit?`.
8-
- [x] `biome_lsp_format`: `path`, `root?`, `write?`.
9-
- [x] `biome_lsp_fix`: `path`, `root?`, `kind?`, `write?`; default kind `source.fixAll.biome`.
10-
- [x] `ty_lsp_diagnostics`: `paths?`, `root?`, `limit?`.
11-
- [x] `ruff_lsp_diagnostics`: `paths?`, `root?`, `limit?`.
12-
- [x] `ruff_lsp_format`: `path`, `root?`, `write?`.
13-
- [x] `ruff_lsp_fix`: `path`, `root?`, `kind?`, `write?`; default kind `source.fixAll.ruff`.
7+
- [x] `lsp_diagnostics`: `paths?`, `root?`, `limit?`, `language?`, `checker?`.
8+
- [x] Biome-supported web/config diagnostics route to Biome.
9+
- [x] Python `checker: "type"` diagnostics route to ty.
10+
- [x] Python `checker: "lint"` diagnostics route to Ruff.
11+
- [x] Python `checker: "all"` diagnostics route to both ty and Ruff.
12+
- [x] `lsp_format`: `path`, `root?`, `write?`, `language?`.
13+
- [x] Biome-supported web/config files route to Biome.
14+
- [x] Python `.py`/`.pyi` files route to Ruff.
15+
- [x] `lsp_fix`: `path`, `root?`, `kind?`, `write?`, `language?`.
16+
- [x] Biome-supported web/config files route to Biome; default kind `source.fixAll.biome`.
17+
- [x] Python `.py`/`.pyi` files route to Ruff; default kind `source.fixAll.ruff`.
18+
19+
## Migration from deprecated public tool names
20+
21+
- [x] `biome_lsp_diagnostics` maps to `lsp_diagnostics` with `language: "web"` when an override is needed.
22+
- [x] `biome_lsp_format` maps to `lsp_format` for a Biome-supported file.
23+
- [x] `biome_lsp_fix` maps to `lsp_fix` for a Biome-supported file.
24+
- [x] `ty_lsp_diagnostics` maps to `lsp_diagnostics` with `language: "python"`, `checker: "type"`.
25+
- [x] `ruff_lsp_diagnostics` maps to `lsp_diagnostics` with `language: "python"`, `checker: "lint"`.
26+
- [x] `ruff_lsp_format` maps to `lsp_format` for a Python file.
27+
- [x] `ruff_lsp_fix` maps to `lsp_fix` for a Python file.
1428

1529
## Server commands and environment variables
1630

@@ -30,20 +44,22 @@
3044
## LSP behavior
3145

3246
- [x] Shared runner owns JSON-RPC framing, subprocess lifecycle, initialize/shutdown, file open/close, diagnostics, formatting, code actions, action resolution, and workspace edit application.
33-
- [x] Biome Adapter keeps dynamic registration capabilities, publish-diagnostics fallback, workspace-folder request handling, tab size 2, and tabs.
34-
- [x] ty Adapter keeps diagnostic requests without code actions, tab size 4, and spaces.
35-
- [x] Ruff Adapter keeps diagnostic requests, code actions, tab size 4, and spaces.
47+
- [x] Biome adapter keeps dynamic registration capabilities, publish-diagnostics fallback, workspace-folder request handling, tab size 2, and tabs.
48+
- [x] ty adapter keeps diagnostic requests without code actions, tab size 4, and spaces.
49+
- [x] Ruff adapter keeps diagnostic requests, code actions, tab size 4, and spaces.
50+
- [x] Route selection is centralized above the adapters and prevents ty from being selected for format/fix.
3651

3752
## Result shapes and messages
3853

3954
- [x] Tool results still return `{ content: [{ type: "text", text }], details }`.
40-
- [x] Diagnostics details include `root`, `command`, `files`, and `summary`.
55+
- [x] Diagnostics details include root, selected routes, backend details, files, and summaries.
4156
- [x] Format/fix details include `path`, `uri`, `changed`, `write`, `edits`, and preview `text` when `write` is false.
4257
- [x] Fix details include `kind` and resolved `actions`.
4358
- [x] Missing-command errors preserve server-specific install guidance.
59+
- [x] Unsupported extensions and contradictory language overrides produce route errors that name supported language/file-extension classes.
4460

4561
## Documentation and compatibility
4662

47-
- [x] `extensions/pi-lsp/README.md` documents tool-name compatibility, environment variables, and the deprecated status for the old packages.
63+
- [x] `extensions/pi-lsp/README.md` documents the three routed tools, environment variables, and migration from old tool names.
4864
- [x] Root `README.md`, `package.json`, and `justfile` include `pi-lsp` integration.
4965
- [x] `pi-biome-lsp` and `pi-python-lsp` now live under `extensions/deprecated/` and are excluded from active workspace scripts.

extensions/pi-lsp/README.md

Lines changed: 84 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
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 tools through one shared LSP runner Module.
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.
66

77
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.
88

99
## ✨ Features
1010

11-
- Runs `biome lsp-proxy` on demand for diagnostics, formatting, import organization, and source fixes.
12-
- Runs `ty server` on demand for Python type diagnostics.
13-
- Runs `ruff server` on demand for Python lint diagnostics, formatting, import organization, and source fixes.
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`.
1414
- 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, and write-or-preview edits.
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.
1717
- Starts language servers only for tool calls, then shuts them down.
1818
- Shows statusline activity only while LSP tools are running.
1919

@@ -37,17 +37,19 @@ pi -e ./extensions/pi-lsp
3737

3838
## ⚠️ Tool-name compatibility
3939

40-
This package intentionally registers the same tool names as `@narumitw/pi-biome-lsp` and `@narumitw/pi-python-lsp`:
40+
This package now exposes three language/file-extension routed tools instead of the old backend-specific tool names:
4141

42-
- `biome_lsp_diagnostics`
43-
- `biome_lsp_format`
44-
- `biome_lsp_fix`
45-
- `ty_lsp_diagnostics`
46-
- `ruff_lsp_diagnostics`
47-
- `ruff_lsp_format`
48-
- `ruff_lsp_fix`
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 |
4951

50-
Avoid installing `@narumitw/pi-lsp` side by side with the older deprecated LSP packages unless you have verified how your Pi version handles duplicate tool names.
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.
5153

5254
## ✅ Requirements
5355

@@ -85,22 +87,61 @@ pi -e ./extensions/pi-lsp
8587

8688
## 🛠️ Pi tools
8789

88-
### Biome
90+
### `lsp_diagnostics`
8991

90-
- `biome_lsp_diagnostics` — start `biome lsp-proxy`, open supported files, and return diagnostics.
91-
- `biome_lsp_format` — compute or write formatting edits for one Biome-supported file.
92-
- `biome_lsp_fix` — compute or write source actions such as `source.fixAll.biome` or `source.organizeImports.biome`.
92+
Run diagnostics through language/file-extension routes.
9393

94-
### Python
94+
Parameters:
9595

96-
- `ty_lsp_diagnostics` — start `ty server`, open Python files, and return type diagnostics.
97-
- `ruff_lsp_diagnostics` — start `ruff server`, open Python files, and return lint diagnostics.
98-
- `ruff_lsp_format` — compute or write Ruff formatting edits for one Python file.
99-
- `ruff_lsp_fix` — compute or write Ruff source actions such as `source.fixAll.ruff` or `source.organizeImports.ruff`.
96+
- `paths?`: files or directories to check. Defaults to the workspace root.
97+
- `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+
125+
### `lsp_fix`
126+
127+
Apply source fixes or import organization through the route selected from the file extension.
128+
129+
Parameters:
130+
131+
- `path`: file to fix.
132+
- `root?`: workspace root. Defaults to cwd.
133+
- `kind?`: source action kind. Defaults to the routed backend's fix-all action.
134+
- `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`.
100141

101142
## 🚀 Examples
102143

103-
Check a project subset with Biome diagnostics:
144+
Check a mixed project subset and run all applicable diagnostics:
104145

105146
```json
106147
{
@@ -109,25 +150,37 @@ Check a project subset with Biome diagnostics:
109150
}
110151
```
111152

112-
Format a TypeScript file with Biome:
153+
Check only Biome-supported web/config files:
113154

114155
```json
115156
{
116-
"path": "src/index.ts",
117-
"write": true
157+
"language": "web",
158+
"paths": ["extensions/pi-lsp/src"],
159+
"limit": 100
118160
}
119161
```
120162

121-
Check a Python project with ty or Ruff diagnostics:
163+
Check Python type diagnostics only:
122164

123165
```json
124166
{
167+
"language": "python",
168+
"checker": "type",
125169
"paths": ["src", "tests"],
126170
"limit": 100
127171
}
128172
```
129173

130-
Organize Python imports with Ruff:
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:
131184

132185
```json
133186
{
@@ -157,6 +210,7 @@ extensions/pi-lsp/
157210
│ ├── files.ts
158211
│ ├── lsp-client.ts
159212
│ ├── pi-lsp.ts
213+
│ ├── routes.ts
160214
│ ├── runner.ts
161215
│ ├── text-edits.ts
162216
│ └── types.ts

0 commit comments

Comments
 (0)