原始内容
pi TypeScript LSP extension
High-level TypeScript language-server tools for coding agents.
Agents usually work with files, symbols, tasks, and edits—not editor cursor offsets. This extension wraps TypeScript LSP features into a small tool set for semantic code work:
- find/understand symbols
- check TypeScript errors
- fix or organize imports
- rename symbols safely
Use normal filesystem tools (read, edit, bash/rg/find) for file discovery, text search, docs, config, and surgical edits. Use LSP tools when TypeScript semantics matter.
Installation
From npm:
pi install npm:pi-typescript-lsp
From GitHub:
pi install git:git@github.com:IbrahimMohammed47/pi-typescript-lsp.git
Manual development install:
mkdir -p ~/.pi/agent/extensions
cd ~/.pi/agent/extensions
git clone git@github.com:IbrahimMohammed47/pi-typescript-lsp.git pi-typescript-lsp
cd pi-typescript-lsp
npm install
Reload running pi session after install/update:
/reload
Tools
ts_symbol_context
Understand known TS/JS symbol. Defaults to hover/type info + definition. Add references, implementations, type definition, or call hierarchy only when needed.
{ "target": { "file": "src/auth.ts", "symbol": "getAccessToken" } }
{
"target": { "file": "src/auth.ts", "symbol": "getAccessToken" },
"include": { "references": true, "hover": false, "definition": false }
}
{
"target": { "query": "CacheStore" },
"include": { "implementation": true }
}
If multiple candidates return, retry with selectIndex.
ts_find_symbols
Language-aware symbol search or file outline.
{ "query": "SessionManager", "limit": 20 }
{ "file": "src/router.ts" }
Not for filename or plain text search; use rg/filesystem tools.
ts_errors_check
Check TypeScript errors. Pass file for recent/known changes; omit for project check.
{ "file": "src/session.ts" }
{ "maxErrors": 50 }
With file, extension checks file diagnostics first, then project typecheck if file is clean. Project check uses npm run typecheck when available, otherwise bundled tsc --noEmit --pretty false. Output is capped by maxErrors (default 20).
ts_import_fix
Fix imports in one TS/JS file via LSP code actions.
{ "file": "src/session.ts", "diagnosticIndex": 0 }
{ "file": "src/session.ts", "diagnosticIndex": 0, "applyIndex": 0 }
{ "file": "src/session.ts", "diagnosticIndex": 0, "applyIndex": 0, "apply": true }
Organize imports by omitting diagnosticIndex:
{ "file": "src/session.ts", "apply": true }
Previews by default; writes only with apply: true.
ts_rename
Safely rename symbol across files.
{
"target": { "file": "src/auth.ts", "symbol": "getAccessToken" },
"newName": "readAccessToken"
}
{
"target": { "file": "src/auth.ts", "symbol": "getAccessToken" },
"newName": "readAccessToken",
"apply": true
}
Prefer over manual search/replace for symbol renames.
Automatic diagnostics
After successful native write or edit calls on TS/JS source files, extension can run same checks as ts_errors_check: edited file first, then project typecheck if clean.
Controlled by config.
/lsp command and config
/lsp is read-only. It shows current config, defaults, option docs, default sources, and example override file.
Project override file:
.pi/typescript-lsp.json
Defaults come from:
- built-ins
- nearest
tsconfig.json,jsconfig.json, ortsconfig.*.json(excludeonly) - project-local
node_modules/.bin/typescript-language-server, when found .pi/typescript-lsp.json, when present
Example:
{
"enabled": true,
"autoDiagnostics": true,
"autoDiagnosticsWaitMs": 800,
"maxFileSizeBytes": 2097152,
"serverPath": "auto",
"exclude": ["node_modules", "dist", "build", "coverage"]
}
Same example: examples/typescript-lsp.json.
Config options
enabled(boolean, defaulttrue): master switch for tools and automatic diagnostics.autoDiagnostics(boolean, defaulttrue): append diagnostics after successful nativewrite/editcalls.autoDiagnosticsWaitMs(number, default800): wait time before project typecheck fallback.maxFileSizeBytes(number, default2097152): max file size opened by LSP client.serverPath(string, default"auto"): bundled server by default; relative/absolute override allowed.exclude(string[]): ignored paths/globs for discovery and automatic diagnostics. Override replaces currentexclude.
Development
Dependencies:
typescript-language-servertypescript
Reinstall if needed:
cd ~/.pi/agent/extensions/pi-typescript-lsp
npm install
Checks:
npm run typecheck
npm test
npm run pack:dry-run
Notes and limitations
- Server starts lazily on first LSP tool call.
- Server root is current pi working directory.
- File paths can be absolute or relative to pi cwd.
- Documents sync from disk before symbol/file requests.
- Files larger than
maxFileSizeBytesare rejected. - Server shuts down on pi session shutdown/reload, with kill fallback.
- Workspace symbol search depends on TypeScript server indexing/warmup; fallback scan opens likely source files.
- Project typecheck can be slow on large repositories.
- JavaScript projects work best with
jsconfig.json. - Text search is intentionally out of scope; use
rg/filesystem tools.
Good agent behavior
Good:
Use ts_symbol_context for getAccessToken in src/auth.ts to understand type/definition.
Use ts_symbol_context include.references=true to find semantic usages before changing behavior.
Use ts_errors_check with changed file after TS edits to catch local and downstream errors.
Avoid:
Use LSP to search all files containing "token".
Use rg/filesystem tools for broad text search.
License
MIT. See LICENSE.