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

写了一个获取最新 nupkg url 的函数:

(defun lsp-python-ms-latest-nupkg-url (&optional channel)
  (let ((channel (or channel "stable")))
    (unless (member channel '("stable" "beta" "daily"))
      (error (format "Unknown channel: %s" cnannel)))
    (with-temp-buffer
      (url-insert-file-contents
       (concat
        "https://pvsc.blob.core.windows.net/python-language-server-"
        channel
        "?restype=container&comp=list&prefix=Python-Language-Server-"
        (cond (*macos* "osx")
              (*linux* "linux")
              (*winnt* "win")
              (t (error (format "Unknown system: %s" system-type))))
        "-x64"))
      (pcase (xml-parse-region (point) (point-max))
        (`((EnumerationResults
            ((ContainerName . ,_))
            (Prefix nil ,_)
            (Blobs nil . ,blobs)
            (NextMarker nil)))
         (cdar
          (sort
           (mapcar (lambda (blob)
                     (pcase blob
                       (`(Blob
                          nil
                          (Name nil ,_)
                          (Url nil ,url)
                          (Properties nil (Last-Modified nil ,last-modified) . ,_))
                        (cons (encode-time (parse-time-string last-modified)) url))))
                   blobs)
           (lambda (t1 t2)
             (time-less-p (car t2) (car t1))))))))))

把中间判断 system-type 那几行替换城你自己的应该就可以了,以下是在 macOS 的测试结果:

(list
 (lsp-python-ms-latest-nupkg-url)
 (lsp-python-ms-latest-nupkg-url "beta")
 (lsp-python-ms-latest-nupkg-url "daily"))
;; =>
;; ("https://pvsc.blob.core.windows.net/python-language-server-stable/Python-Language-Server-osx-x64.0.3.20.nupkg"
;;  "https://pvsc.blob.core.windows.net/python-language-server-beta/Python-Language-Server-osx-x64.0.3.20.nupkg"
;;  "https://pvsc.blob.core.windows.net/python-language-server-daily/Python-Language-Server-osx-x64.0.3.20.nupkg")

另外需要特别注意的是,输出的原始 xml 里有个 NextMarker 好像是分页标记,我目前直接当作 nil 处理没有问题(如果为 t 则 pcase pattern 不起作用),说明目前是没有分页的。将来有可能会返回分页数据,不过也可能源头控制好了,不产生分页数据,否则 daily 每天一个包早就该分页了。


UPDATE: 2019-06-27 01.43.47

修复排序问题 154楼

UPDATE: 2019-06-28 15.54.21

Replace url-retrieve-synchronously with url-insert-file-contents

3 个赞