Skip to main content

pyre-lsp

Python LSP License Editors

面向 sqlalchemy_db / pyre_starlette.models 的 Language Server(不是只绑 VS Code)。 同一套服务可被 VS Code、Cursor、Windsurf、Neovim、Zed 接入。

✨ 特点

  • ⚡ 字段补全 — User.query.filter_by( 直接补字段 kwargs,User( 补构造参数。
  • 🎯 签名提示 — SignatureHelp 随光标位置给出参数名与类型。
  • 💬 类型 Hover — first() → User | None,all() → list[User]。
  • 🧠 混入字段合并 — 继承 PkMixin / TimestampMixin 时字段自动合并到模型。
  • 🔎 DTO 感知 — .from_entity( 补工作区内的 Pydantic DTO。
  • 🔌 编辑器无关 — 标准 LSP 协议,VS Code / Cursor / Windsurf / Neovim / Zed / PyCharm 通用。
  • 🚀 轻量 — 只依赖 pygls 与 lsprotocol,索引完全在本地完成。

📦 安装

pip install pyre-lsp

本地开发:

cd pyre_lsp
pip install -e .

验证:

python -m pyre_lsp --help
python tests/test_smoke.py

💡 效果一览

场景 效果
User( SignatureHelp + 补全 username=
User.query.filter_by( 补全字段 kwargs
User.query.filter( 补全 User.username / == / .like( / .in_(
User.query.order_by( 补全 User.username.desc()
User.query.first() Hover → User | None
User.query.all() Hover → list[User]
User.query.get_by_id() Hover → User | None
.update({ 补全字段键
.from_entity( 补全工作区内 Pydantic DTO

对本仓库实测索引:约 71 个 Model、128 个 DTO;Department 会合并 OmnModel 混入字段(id / create_time / 软删等)。

👩‍💻 目录结构

pyre-lsp
├── pyre_lsp
│   ├── __init__.py
│   ├── __main__.py    # python -m pyre_lsp
│   ├── server.py      # LSP 入口与能力注册
│   ├── parser.py      # 扫描 Model / Field / DTO
│   ├── cache.py       # 模型缓存与字段合并
│   ├── context.py     # 光标上下文(filter_by / first / …)
│   └── providers/     # Completion / Hover / SignatureHelp
├── vscode/            # 薄客户端(LanguageClient)
├── jetbrains/         # LSP4IJ 配置示例
├── tests/
└── pyproject.toml

🧩 VS Code / Cursor 扩展

cd pyre_lsp/vscode
npm install
npm run compile

然后任选其一:

  1. 开发调试:用仓库根目录 .vscode/launch.json → Launch Pyre LSP Extension
  2. 本机加载:命令面板 “Developer: Install Extension from Location…” 选 pyre_lsp/vscode

设置(可选):

  • pyreLsp.pythonPath:跑 python -m pyre_lsp 的解释器(默认 python)
  • pyreLsp.serverPath:若已把 pyre-lsp 装进 PATH,可直接填可执行文件路径

🧩 PyCharm / IntelliJ(LSP4IJ)

PyCharm 本身不内置任意 LSP,用官方生态插件 LSP4IJ 接入即可(Community / Professional 都行)。

1. 安装 Language Server

在你项目用的那个 Python 解释器里:

cd pyre_lsp
pip install -e .

确认能启动:

pyre-lsp --help
# 或
python -m pyre_lsp --help

Windows 上若 pyre-lsp 不在 PATH,下面命令里用完整路径,例如:

D:\Python\Python311\Scripts\pyre-lsp.EXE

或统一用解释器模块方式(更稳):

D:\Python\Python311\python.exe -m pyre_lsp

2. 安装 LSP4IJ

Settings → Plugins → Marketplace 搜索 LSP4IJ → Install → 重启。

插件页:LSP4IJ

3. 注册 User-defined Language Server

Settings → Languages & Frameworks → Language Servers → + → New user-defined language server

项 填法
Name Pyre LSP
Command python -m pyre_lsp(或上面的完整路径)

Mappings 页:

  • Language / File type 选 Python(或 File name patterns:*.py)

保存后打开任意 .py,在 View → Tool Windows → Language Servers / LSP Consoles 里应能看到 Pyre LSP 已连接。

4. 验证

在代码里输入:

AdminUser.query.filter_by(

应出现字段 kwargs(如 avatar=)。鼠标悬停 first / all 应有返回类型提示。

5. 常见问题

  • 没有补全:确认 Command 用的是「项目解释器」那套 Python(和 pip install -e . 同一环境)。
  • 和官方 Python 补全抢位置:正常现象;Pyre 项会带字段语义,可继续输入字段名前缀过滤。
  • 想看通信日志:Language Servers → 选中 Pyre LSP → Debug → Trace 调到 verbose,在 LSP Console 查看。

更细的 User-defined 配置说明见:LSP4IJ User-defined LS。

📌 说明

  • 不会改写 Pylance 的类型推导;变量 user = User.query.first() 的类型仍由 Pylance 决定。
  • 本 LSP 负责「写到 User( / filter_by( 时」的参数提示、字段补全,以及 first/all 等方法上的 Hover。
  • 若以后要让 Pylance 也认识构造参数,可再加 .pyi 生成(与 LSP 互补)。

📄 许可

本项目基于 MIT 许可开源。

Metadata

Release files for pyre-lsp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyre-lsp 0.1.0
File Size Uploaded Provenance
pyre_lsp-0.1.0.tar.gz 21.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyre-lsp 0.1.0
File Interpreter ABI Platform
pyre_lsp-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 41.7 kB

Release files / pyre_lsp-0.1.0.tar.gz

Download URL pyre_lsp-0.1.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2b885c933734587924c5a3f9de727c3c7fed01486192a81cc6c47f6238ddcd72
BLAKE2b-256 checksum
How to use checksums
8621c82817f0ec901c63795b85c309a198a19d680db241bfc503639f45aba7b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyre_lsp-0.1.0-py3-none-any.whl

Download URL pyre_lsp-0.1.0-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5552809e455f662e6a1de1748f80c09bf30a69b342c54eccb9c61eac56b8b58d
BLAKE2b-256 checksum
How to use checksums
02689604190d94c4a4e845d6fdf3b0a5b30d4f70cd6be0bb0994c42dea1f8a9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for pyre-lsp 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page