xiaopanzi
V2EX  ›  Vim

vim/nvim 中是否有能匹敌 pylance 的 Python LSP

By xiaopanzi at 2023 年 2 月 15 日 · 4394 次点击

最近在折腾 nvim 的 Python 开发配置,但是发现能找不到一个衬手的 LSP ,没有能取代 VSCode 的 Pylance 。测试过的包括:

  • pyright
  • python-lsp-server
  • jedi-language-server

第一个pyright是微软出品,但是 hover 操作只有方法签名,没有详细的 doc string ;应该它的定位是个 static type chcker ,只是顺带有点 lsp 的功能。

第二个python-lsp-server缺乏静态分析功能。比如np.arange(15).reshape(3, 5),它不知道 arange 返回的是narray,所以后面的 reshape 无法提示也无法提供 hover 操作。

第三个jedi-language-server今天刚测试,发现它只读取包的pyi信息,导致很多时候提示内容不足。比如它认为np.log(10)的 log 是个变量,因为 pyi 文件中定义的是log: _UFunc_Nin1_Nout1[L['log'], L[10], None]。

大家是否有推荐的 Python LSP ?能做到媲美 Pylance 的那种程度。

5 条回复  •  2023-02-16 14:52:02 +08:00
newbieRenew
   1
newbieRenew  
   2023 年 2 月 15 日 via iPhone
Pylance 没用过。在用 ALE
xiaopanzi
   2
xiaopanzi  
OP
   2023 年 2 月 16 日
@jdhao 大佬有推荐的吗?还是我的配置有问题。
LcDraven
   3
LcDraven  
   2023 年 2 月 16 日
去 vim 电报中文交流群里面问
fannheyward
   4
fannheyward  
   2023 年 2 月 16 日   ❤️ 1
Pyright 是最接近 Pylance 的。Pylance 的 hover document 也只有方法签名,你看到的详细 doc string 是 vscode-python 提供的。

Pyright 对比 Pylance 最大的缺失是 code actions ,比如 add imports, remove unused imports, refactoring 等,另外也没有 semanticTokens, callHierarchy, inlayHint, fileOperation 的支持。
fannheyward
   5
fannheyward  
   2023 年 2 月 16 日
> hover document 也只有方法签名

Pylance 有部分 module 是提供了详细 doc string.
© 2026 V2EX · 36ms · 3.9.8.5