亲测:lsp-python-ms vs pyls 性能

大神,lsp-python-ms 是不是需要额外配置?

我们配合适配一下 nox 吧。:wink:

可以移植过去,适配下 eglot。如果不用自动下载功能,只需要注册 mspyls 的客户端就好了。

直接填dotnet和mspyls的dll路径不行

一直用python-ms,感觉比pyls速度快。加油。

感觉是不是 initializationOptions 的问题,我看了下 nox 用 mspyls 时候好像是 nil, 我记得 lsp-python-ms 要去解析 python 的位置,版本等等的。

ms-python-language-server 并不是标准的协议实现,需要调整一些参数才能工作。

谁在Linux下成功起来 mspyls ?

我感觉Linux版本有bug,服务器一直报错误:

server-reply (id:10) ERROR Mon Mar 30 18:44:46 2020: (:jsonrpc “2.0” :id 10 :error (:code -32000 :message “Object reference not set to an instance of an object.” :data " at Microsoft.Python.LanguageServer.Documents.Document.GetAnalysisAsync(Uri uri, IServiceContainer services, Int32 msTimeout, CancellationToken cancellationToken) in /home/andy/python-language-server/src/LanguageServer/Impl/Documents/Document.cs:line 28\n at Microsoft.Python.LanguageServer.Implementation.Server.Completion(CompletionParams params, CancellationToken cancellationToken) in /home/andy/python-language-server/src/LanguageServer/Impl/Implementation/Server.Editor.cs:line 41\n at Microsoft.Python.LanguageServer.Implementation.LanguageServer.Completion(JToken token, CancellationToken cancellationToken) in /home/andy/python-language-server/src/LanguageServer/Impl/LanguageServer.cs:line 163"))

你是Linux版本?

lsp-python-ms 里面有下载脚本。 下载的是 vscode 打包好的。

你在Linux下用过吗?我和作者交流过,我是从微软网站上下载直接可以用的。

没有 linux,不过我在 mac 试过 nox + mspyls 的,没指定其他,只指定了 executable, 报错和你这里一样,暂时没时间继续研究。相同的 mspyls 在 lsp-python-ms 和 vscode 下面都是可用的。

可以在 VSCode 上验证一下。

我电脑安装 VSCode 最大用途就是这个了。

mspyls在windows和linux都可以,用的是lsp-mode。好久没在linux上用了。自己编译的版本。

commit 352feccc04b57579bccf90ddfa9f5ba2e69da2b7
Author: Jake Bailey <[email protected]>
Date:   Mon Aug 5 14:40:31 2019 -0700

奇怪了,我这边 mspyls 一直不响应 textDocument/completion 请求。

就是这个commit以前的版本在centos上很快,cpu也低,但是这个commit编译的一启动mspyls就非常吃cpu,分析完代码后,就正常了。

lsp-mode是自动显示函数帮助和变量类型。速度很快,不卡顿。

偶尔在windows上通过x server用一下linux的emacs和lsp-mode。

死磕了一下午,我终于明白了。

pyls不需要索引,支持单文件,比如我在 HOME 目录下创建 test.py 可以直接补全工作 mspyls需要建索引,当我在 HOME 目录下创建 test.py 文件时,mspyls 会分析我整个HOME目录,我的HOME目录超多源代码,这也是为啥我一直没法得到 mspyls 对 textDocument/completion 请求的回应,因为他没有索引完。

创建一个 ~/test/test.py 的目录包裹一下 test.py , mspyls 马上就好了。

天啊,折磨死我了,知道原因就好让Nox默认支持 mspyls 了。

王哥,nox 的 mspyls 跑起来了。我找了 eglot 的 issue,然后调整了下,也不知道哪个参数的鬼。

(defvar lsp-python "/usr/local/bin/python")
(defvar lsp-search-paths [])

(defclass nox-mspyls (nox-lsp-server) ()
  :documentation "MS Python Language Server.")

(setq-default nox-workspace-configuration
              '((:python :autoComplete (:extraPaths nil)
                         :analysis (:autoSearchPaths :json-false :usePYTHONPATH :json-false))))

(cl-defmethod nox-initialization-options ((_server nox-mspyls))
  `(:interpreter
    (:properties
     (:InterpreterPath ,lsp-python))
     :searchPaths ,lsp-search-paths))

(add-to-list 'nox-server-programs
             `(python-mode nox-mspyls 
                           "Microsoft.Python.LanguageServer"))

我把 “Microsoft.Python.LanguageServer” 放 PATH 了。

可以看看 Microsoft's python language server sending non-standard keys · Issue #144 · joaotavora/eglot · GitHub

看我上面的帖子,因为mspyls要建立索引,等我半个小时,我把 mspyls 的支持内置了。

又一个被 mspyls 扫描 HOME 目录坑到的例子。

哈哈哈,mspyls索引一开始没懂确实很头痛