V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiaopanzi
V2EX  ›  Vim

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

  •  
  •   xiaopanzi · 2023-02-15 21:56:43 +08:00 · 2312 次点击
    这是一个创建于 433 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在折腾 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-02-15 22:00:49 +08:00 via iPhone
    Pylance 没用过。在用 ALE
    xiaopanzi
        2
    xiaopanzi  
    OP
       2023-02-16 09:25:08 +08:00
    @jdhao 大佬有推荐的吗?还是我的配置有问题。
    LcDraven
        3
    LcDraven  
       2023-02-16 10:58:27 +08:00
    去 vim 电报中文交流群里面问
    fannheyward
        4
    fannheyward  
       2023-02-16 14:26:14 +08:00   ❤️ 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-02-16 14:52:02 +08:00
    > hover document 也只有方法签名

    Pylance 有部分 module 是提供了详细 doc string.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2829 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 00:21 · PVG 08:21 · LAX 17:21 · JFK 20:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.