Python code quality checking and LSP integration using pylsp. Provides code diagnostics, completion, hover tips, and style analysis. Use when: checking Pytho...
数据来源:ClawHub。 在 ClawSkills 查看
选择你使用的 Agent
方法一:命令行安装(推荐)
推荐(无需提前安装 clawhub)
npx clawhub@latest --dir ~/.claude/skills install lsp-python或使用 clawhub CLI(需提前安装)
clawhub --dir ~/.claude/skills install lsp-python⚠️ 需要 Node.js 18+,没有 Node?请使用下方方法二直接下载 ZIP。 安装 Node.js →
方法二:手动下载安装(无需 Node)
下载 ZIP,解压后将文件夹放到以下路径,重启 Agent 即可:
安装路径
~/.claude/skills/lsp-python/💡解压后将文件夹放到上方路径,重启 Agent 即可生效
--- name: lsp-python description: "Python code quality checking and LSP integration using pylsp. Provides code diagnostics, completion, hover tips, and style analysis. Use when: checking Python errors/warnings, getting code completions, viewing function signatures, analyzing code quality, or fixing style issues." ---
使用 Python Language Server Protocol (LSP) 进行代码质量检查和智能分析。
# 单个文件
python3 scripts/lsp-service.py check <文件路径>
# 批量检查 (推荐)
python3 scripts/check_python.py <文件或目录>
# 批量检查并自动修复
python3 scripts/check_python.py --auto-fix <文件或目录>
示例:
python3 scripts/lsp-service.py check my_script.py
python3 scripts/check_python.py src/
python3 scripts/check_python.py --auto-fix src/
python3 scripts/lsp-service.py complete <文件> <行号> <字符位置>
python3 scripts/lsp-service.py info <文件> <行号> <字符位置>
pip install python-lsp-server - pip install python-lsp-server[all] - 完整插件集 - pip install pylsp-mypy - 类型检查 - pip install pylsp-black - black 格式化
检查 Python 文件中的错误和警告:
输出示例:
⚠️ 第 3 行 [pyflakes]: 'os' imported but unused
⚠️ 第 6 行 [pycodestyle]: E302 expected 2 blank lines, found 1
✅ 没有发现问题
获取指定位置的代码补全建议:
python3 scripts/lsp-service.py complete script.py 5 10
输出:
补全建议:
• json (模块)
• jsonpatch (模块)
• requests (模块)
查看函数签名、文档字符串等信息:
python3 scripts/lsp-service.py info script.py 10 5
查找符号的定义位置:
python3 scripts/lsp-service.py goto script.py 15 10
pip install autoflake
autoflake --remove-all-unused-imports --in-place --recursive .
pip install black
black .
# 1. 备份
cp -r project/ project.backup
# 2. 清理导入
autoflake --remove-all-unused-imports --in-place --recursive project/
# 3. 格式化
black project/
# 4. 验证
python3 scripts/lsp-service.py check project/main.py
| 级别 | 代码 | 含义 | |------|------|------| | ❌ | 1 | Error (错误) | | ⚠️ | 2 | Warning (警告) | | ℹ️ | 3 | Information (信息) | | 💡 | 4 | Hint (提示) |
| 代码 | 含义 | 修复方法 | |------|------|----------| | E402 | 导入不在文件顶部 | 移动导入到文件开头 | | E501 | 行太长 (>79 字符) | 拆分长行或使用括号 | | W293 | 空行包含空白字符 | 删除行尾空格 | | E302 | 缺少空行 | 函数/类定义前加 2 个空行 | | E712 | 布尔比较风格 | if x is True → if x |
exec: python3 /path/to/lsp-python/scripts/lsp-service.py check <file>
# 检查所有 Python 文件
find . -name "*.py" -exec python3 scripts/lsp-service.py check {} \;
# 仅显示有问题的文件
for f in $(find . -name "*.py"); do
result=$(python3 scripts/lsp-service.py check "$f" 2>&1)
if ! echo "$result" | grep -q "✅ 没有发现问题"; then
echo "=== $f ==="
echo "$result"
fi
done
references/lsp-protocol.mdreferences/pylsp-config.mdreferences/pep8-guide.md# 检查安装
which pylsp
pylsp --version
# 重新安装
pip install --upgrade python-lsp-server
增加脚本中的 LSP_TIMEOUT 值 (默认 10 秒)。
确保文件使用 UTF-8 编码,脚本已设置 ensure_ascii=False。
安装 LSP Python 后,可以对 AI 说这些话来触发它
Help me get started with LSP Python
Explains what LSP Python does, walks through the setup, and runs a quick demo based on your current project
Use LSP Python to python code quality checking and LSP integration using pylsp
Invokes LSP Python with the right parameters and returns the result directly in the conversation
What can I do with LSP Python in my developer & devops workflow?
Lists the top use cases for LSP Python, with example commands for each scenario
将技能文件夹放到 ~/.claude/skills/lsp-python/ 目录(个人级,所有项目可用),或 .claude/skills/lsp-python/(项目级)。重启 AI 客户端后,用 /lsp-python 主动调用,或让 AI 根据上下文自动发现并使用。
LSP Python 支持 Claude、Cursor、OpenClaw,可与这些 AI 平台无缝集成,扩展其能力。
LSP Python 可免费安装使用。请查阅仓库了解许可证信息。
Python code quality checking and LSP integration using pylsp. Provides code diagnostics, completion, hover tips, and style analysis. Use when: checking Pytho...
LSP Python 属于「Developer & DevOps」分类,该分类的技能帮助 AI 智能体在此领域执行专业任务。
Automate my developer & devops tasks using LSP Python
Identifies repetitive steps in your workflow and sets up LSP Python to handle them automatically