typescript-lsp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTypeScript LSP Skill
TypeScript LSP 技能
Purpose
用途
This skill provides TypeScript Language Server Protocol integration for exploring and understanding TypeScript/JavaScript codebases.
IMPORTANT: Prefer LSP tools over Grep/Glob when working with , , , files. LSP provides type-aware results that understand imports, exports, and symbol relationships.
*.ts*.tsx*.js*.jsxUse these tools to:
- Explore codebases - Find symbols, understand module structure, discover implementations
- Find references - Type-aware search across the entire codebase (better than grep for symbols)
- Understand types - Get full type signatures, generics, and documentation
- Verify before editing - Check all usages before modifying or deleting exports
- Navigate code - Jump to definitions, find implementations
本技能提供TypeScript语言服务器协议(LSP)集成,用于探索和理解TypeScript/JavaScript代码库。
重要提示:处理、、、文件时,优先使用LSP工具而非Grep/Glob。LSP可提供类型感知的结果,能理解导入、导出及符号间的关系。
*.ts*.tsx*.js*.jsx使用这些工具可以:
- 探索代码库 - 查找符号、理解模块结构、发现实现细节
- 查找引用 - 在整个代码库中进行类型感知的搜索(比grep更适合符号搜索)
- 理解类型 - 获取完整的类型签名、泛型及文档
- 编辑前验证 - 修改或删除导出内容前,检查所有使用场景
- 代码导航 - 跳转到定义、查找实现
When to Use Each Tool
各工具适用场景
| Tool | Purpose |
|---|---|
| Glob | Find files by pattern |
| Grep | Search text content |
| lsp-find | Search TypeScript symbols |
| lsp-hover | Get type info + TSDoc documentation |
| lsp-refs | Find all references to a symbol |
| lsp-analyze | Batch analysis of file structure |
| 工具 | 用途 |
|---|---|
| Glob | 按模式查找文件 |
| Grep | 搜索文本内容 |
| lsp-find | 搜索TypeScript符号 |
| lsp-hover | 获取类型信息 + TSDoc文档 |
| lsp-refs | 查找符号的所有引用 |
| lsp-analyze | 文件结构的批量分析 |
LSP vs Grep/Glob
LSP vs Grep/Glob
| Task | Use LSP | Use Grep/Glob |
|---|---|---|
| Find all usages of a function/type | ✅ | ❌ Misses re-exports, aliases |
| Search for a symbol by name | ✅ | ❌ Matches strings, comments |
| Get type signature + TSDoc | ✅ | ❌ Not possible |
| Understand file exports | ✅ | ❌ Doesn't resolve re-exports |
| Find files by pattern | ❌ | ✅ |
| Search non-TS files (md, json) | ❌ | ✅ |
| Search for text in comments/strings | ❌ | ✅ |
| 任务 | 使用LSP | 使用Grep/Glob |
|---|---|---|
| 查找函数/类型的所有使用场景 | ✅ | ❌ 会遗漏重导出、别名 |
| 按名称搜索符号 | ✅ | ❌ 会匹配字符串、注释 |
| 获取类型签名 + TSDoc | ✅ | ❌ 无法实现 |
| 理解文件导出内容 | ✅ | ❌ 无法解析重导出 |
| 按模式查找文件 | ❌ | ✅ |
| 搜索非TS文件(md、json) | ❌ | ✅ |
| 搜索注释/字符串中的文本 | ❌ | ✅ |
When to Use
使用时机
Exploring code (prefer LSP):
- Run to search for symbols across the workspace
lsp-find - Run to get an overview of file structure
lsp-symbols - Run to see what a module provides
lsp-analyze --exports
Before editing code:
- Run to find all usages of a symbol you plan to modify
lsp-references - Run to verify current type signatures
lsp-hover
Before writing code:
- Run to search for similar patterns or related symbols
lsp-find - Run on APIs you plan to use
lsp-hover
探索代码(优先使用LSP):
- 运行在工作区中搜索符号
lsp-find - 运行获取文件结构概览
lsp-symbols - 运行查看模块提供的内容
lsp-analyze --exports
编辑代码前:
- 运行查找你计划修改的符号的所有使用场景
lsp-references - 运行验证当前的类型签名
lsp-hover
编写代码前:
- 运行搜索类似模式或相关符号
lsp-find - 运行查看你计划使用的API
lsp-hover
Path Resolution
路径解析
All scripts accept three types of file paths:
- Absolute paths:
/Users/name/project/src/file.ts - Relative paths: or
./src/file.ts../other/file.ts - Package export paths: (resolved via
my-package/src/module.ts)Bun.resolve()
Package export paths are recommended for portability and consistency with the package's exports field.
所有脚本支持三种文件路径:
- 绝对路径:
/Users/name/project/src/file.ts - 相对路径:或
./src/file.ts../other/file.ts - 包导出路径:(通过
my-package/src/module.ts解析)Bun.resolve()
推荐使用包导出路径,以保证可移植性,并与包的exports字段保持一致。
Scripts
脚本
Individual Scripts
独立脚本
lsp-hover
lsp-hover
Get type information at a specific position.
bash
bunx @plaited/development-skills lsp-hover <file> <line> <char>Arguments:
- : Path to TypeScript/JavaScript file
file - : Line number (0-indexed)
line - : Character position (0-indexed)
char
Example:
bash
bunx @plaited/development-skills lsp-hover src/utils/parser.ts 42 10获取指定位置的类型信息。
bash
bunx @plaited/development-skills lsp-hover <file> <line> <char>参数:
- :TypeScript/JavaScript文件路径
file - :行号(从0开始计数)
line - :字符位置(从0开始计数)
char
示例:
bash
bunx @plaited/development-skills lsp-hover src/utils/parser.ts 42 10lsp-symbols
lsp-symbols
List all symbols in a file.
bash
bunx @plaited/development-skills lsp-symbols <file>Example:
bash
bunx @plaited/development-skills lsp-symbols src/utils/parser.ts列出文件中的所有符号。
bash
bunx @plaited/development-skills lsp-symbols <file>示例:
bash
bunx @plaited/development-skills lsp-symbols src/utils/parser.tslsp-references
lsp-references
Find all references to a symbol.
bash
bunx @plaited/development-skills lsp-refs <file> <line> <char>Example:
bash
bunx @plaited/development-skills lsp-refs src/utils/parser.ts 42 10查找符号的所有引用。
bash
bunx @plaited/development-skills lsp-refs <file> <line> <char>示例:
bash
bunx @plaited/development-skills lsp-refs src/utils/parser.ts 42 10lsp-find
lsp-find
Search for symbols across the workspace.
bash
bunx @plaited/development-skills lsp-find <query> [context-file]Arguments:
- : Symbol name or partial name
query - : Optional file to open for project context
context-file
Example:
bash
bunx @plaited/development-skills lsp-find parseConfig
bunx @plaited/development-skills lsp-find validateInput src/lib/validator.ts在工作区中搜索符号。
bash
bunx @plaited/development-skills lsp-find <query> [context-file]参数:
- :符号名称或部分名称
query - :可选,用于提供项目上下文的文件
context-file
示例:
bash
bunx @plaited/development-skills lsp-find parseConfig
bunx @plaited/development-skills lsp-find validateInput src/lib/validator.tsBatch Script
批量脚本
lsp-analyze
lsp-analyze
Perform multiple analyses in a single session for efficiency.
bash
bunx @plaited/development-skills lsp-analyze <file> [options]Options:
- : List all symbols
--symbols, -s - : List only exported symbols
--exports, -e - : Get type info (repeatable)
--hover <line:char> - : Find references (repeatable)
--refs <line:char> - : Run symbols + exports analysis
--all
Examples:
bash
undefined在单个会话中执行多项分析,提升效率。
bash
bunx @plaited/development-skills lsp-analyze <file> [options]选项:
- :列出所有符号
--symbols, -s - :仅列出导出的符号
--exports, -e - :获取类型信息(可重复使用)
--hover <line:char> - :查找引用(可重复使用)
--refs <line:char> - :运行符号+导出分析
--all
示例:
bash
undefinedGet file overview
获取文件概览
bunx @plaited/development-skills lsp-analyze src/utils/parser.ts --all
bunx @plaited/development-skills lsp-analyze src/utils/parser.ts --all
Check multiple positions
检查多个位置
bunx @plaited/development-skills lsp-analyze src/utils/parser.ts --hover 50:10 --hover 75:5
bunx @plaited/development-skills lsp-analyze src/utils/parser.ts --hover 50:10 --hover 75:5
Before refactoring: find all references
重构前:查找所有引用
bunx @plaited/development-skills lsp-analyze src/utils/parser.ts --refs 42:10
undefinedbunx @plaited/development-skills lsp-analyze src/utils/parser.ts --refs 42:10
undefinedCommon Workflows
常见工作流
Understanding a File
理解文件内容
bash
undefinedbash
undefined1. Get exports overview
1. 获取导出内容概览
bunx @plaited/development-skills lsp-analyze path/to/file.ts --exports
bunx @plaited/development-skills lsp-analyze path/to/file.ts --exports
2. For specific type info, hover on interesting symbols
2. 针对感兴趣的符号,使用hover获取具体类型信息
bunx @plaited/development-skills lsp-hover path/to/file.ts <line> <char>
undefinedbunx @plaited/development-skills lsp-hover path/to/file.ts <line> <char>
undefinedBefore Modifying an Export
修改导出内容前
bash
undefinedbash
undefined1. Find all references first
1. 先查找所有引用
bunx @plaited/development-skills lsp-refs path/to/file.ts <line> <char>
bunx @plaited/development-skills lsp-refs path/to/file.ts <line> <char>
2. Check what depends on it
2. 检查依赖关系
Review the output to understand impact
查看输出内容以了解修改影响
undefinedundefinedFinding Patterns
查找模式
bash
undefinedbash
undefinedSearch for similar implementations
搜索类似实现
bunx @plaited/development-skills lsp-find handleRequest
bunx @plaited/development-skills lsp-find parseConfig
undefinedbunx @plaited/development-skills lsp-find handleRequest
bunx @plaited/development-skills lsp-find parseConfig
undefinedPre-Implementation Verification
实现前验证
bash
undefinedbash
undefinedBefore writing code that uses an API, verify its signature
编写使用某API的代码前,验证其签名
bunx @plaited/development-skills lsp-hover path/to/api.ts <line> <char>
undefinedbunx @plaited/development-skills lsp-hover path/to/api.ts <line> <char>
undefinedOutput Format
输出格式
All scripts output JSON to stdout. Errors go to stderr.
Hover output:
json
{
"contents": {
"kind": "markdown",
"value": "```typescript\nconst parseConfig: (options: Options) => Config\n```"
},
"range": { "start": {...}, "end": {...} }
}Symbols output:
json
[
{
"name": "symbolName",
"kind": 13,
"range": { "start": {...}, "end": {...} }
}
]Analyze output:
json
{
"file": "path/to/file.ts",
"exports": [
{ "name": "exportName", "kind": "Constant", "line": 139 }
]
}所有脚本均向标准输出(stdout)输出JSON格式内容,错误信息输出至标准错误(stderr)。
Hover输出示例:
json
{
"contents": {
"kind": "markdown",
"value": "```typescript\nconst parseConfig: (options: Options) => Config\n```"
},
"range": { "start": {...}, "end": {...} }
}Symbols输出示例:
json
[
{
"name": "symbolName",
"kind": 13,
"range": { "start": {...}, "end": {...} }
}
]Analyze输出示例:
json
{
"file": "path/to/file.ts",
"exports": [
{ "name": "exportName", "kind": "Constant", "line": 139 }
]
}Performance
性能
Each script invocation:
- Starts TypeScript Language Server (~300-500ms)
- Initializes LSP connection
- Opens document
- Performs query
- Closes and stops
For multiple queries on the same file, use to batch operations in a single session.
lsp-analyze每次脚本调用会执行以下步骤:
- 启动TypeScript语言服务器(约300-500ms)
- 初始化LSP连接
- 打开文档
- 执行查询
- 关闭并停止服务
若需对同一文件执行多次查询,建议使用在单个会话中批量处理操作。
lsp-analyzeRelated Skills
相关技能
- code-documentation: TSDoc standards for documentation
- code-documentation: TSDoc文档标准