[LSP] 试用Python开发新包 lsp-pyright

我的理解, 这个函数只要pyright提供“workspace/symbol”这个功能就能直接用, 不需要个人配置的.

哦,你是指这个,要看server是否支持。我研究下

Update:刚试了下,是支持的啊

lsp-ivy-workspace-symbol无法工作…

发现通过 tramp 远程补全无法启动:

Server pyright-remote:91291 status:starting exited with status exit. Do you want to restart it? (y or n) n
  (lsp-register-client
   (make-lsp-client :new-connection (lsp-tramp-connection "pyright")
                    :major-modes '(python-mode)
                    :remote? t
                    :server-id 'pyright-remote))

看看error log

lsp-log

Command "pyright" is present on the path.
Command "pyright" is present on the path.
Found the following clients for /ssh:is:/home/wts/ISWC-2020/product_matching/get_vocab.py: (server-id pyright-remote, priority 0)
The following clients were selected based on priority: (server-id pyright-remote, priority 0)

lsp-log: pyright-remote

[Trace - 11:09:20 PM] Sending request 'initialize - (3)'.
Params: {
  "processId": null,
  "rootPath": "/home/wts/ISWC-2020",
  "clientInfo": {
    "name": "emacs",
    "version": "GNU Emacs 27.1 (build 1, x86_64-apple-darwin19.6.0, NS appkit-1894.60 Version 10.15.6 (Build 19G73))\n of 2020-08-11"
  },
  "rootUri": "file:///home/wts/ISWC-2020",
  "capabilities": {
    "workspace": {
      "workspaceEdit": {
        "documentChanges": true,
        "resourceOperations": [
          "create",
          "rename",
          "delete"
        ]
      },
      "applyEdit": true,
      "symbol": {
        "symbolKind": {
          "valueSet": [
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12,
            13,
            14,
            15,
            16,
            17,
            18,
            19,
            20,
            21,
            22,
            23,
            24,
            25,
            26
          ]
        }
      },
      "executeCommand": {
        "dynamicRegistration": false
      },
      "workspaceFolders": true,
      "configuration": true
    },
    "textDocument": {
      "declaration": {
        "linkSupport": true
      },
      "definition": {
        "linkSupport": true
      },
      "implementation": {
        "linkSupport": true
      },
      "typeDefinition": {
        "linkSupport": true
      },
      "synchronization": {
        "willSave": true,
        "didSave": true,
        "willSaveWaitUntil": true
      },
      "documentSymbol": {
        "symbolKind": {
          "valueSet": [
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12,
            13,
            14,
            15,
            16,
            17,
            18,
            19,
            20,
            21,
            22,
            23,
            24,
            25,
            26
          ]
        },
        "hierarchicalDocumentSymbolSupport": true
      },
      "formatting": {
        "dynamicRegistration": true
      },
      "rangeFormatting": {
        "dynamicRegistration": true
      },
      "rename": {
        "dynamicRegistration": true,
        "prepareSupport": true
      },
      "codeAction": {
        "dynamicRegistration": true,
        "isPreferredSupport": true,
        "codeActionLiteralSupport": {
          "codeActionKind": {
            "valueSet": [
              "",
              "quickfix",
              "refactor",
              "refactor.extract",
              "refactor.inline",
              "refactor.rewrite",
              "source",
              "source.organizeImports"
            ]
          }
        }
      },
      "completion": {
        "completionItem": {
          "snippetSupport": true,
          "documentationFormat": [
            "markdown"
          ],
          "resolveAdditionalTextEditsSupport": true
        },
        "contextSupport": true
      },
      "signatureHelp": {
        "signatureInformation": {
          "parameterInformation": {
            "labelOffsetSupport": true
          }
        }
      },
      "documentLink": {
        "dynamicRegistration": true,
        "tooltipSupport": true
      },
      "hover": {
        "contentFormat": [
          "markdown",
          "plaintext"
        ]
      },
      "foldingRange": null,
      "callHierarchy": {
        "dynamicRegistration": false
      },
      "publishDiagnostics": {
        "relatedInformation": true,
        "tagSupport": {
          "valueSet": [
            1,
            2
          ]
        },
        "versionSupport": true
      }
    },
    "window": {
      "workDoneProgress": true
    }
  },
  "initializationOptions": null,
  "workDoneToken": "1"
}

pyright-remote-1-stderr

stubPath /home/wts/test/typings is not a valid directory.

尝试创建这个目录了没?

试了下,这个不报了,还是不行。感觉应该不是这个问题,我在服务器那个目录运行 pyright,即使没有那个目录(虽然会提示)但是后面也能正常检查。

我没有测试过lsp-tramp-connection,可能需要咨询在lsp-mode core team。

看看类似的issue

哈哈,你看这个头像是不是和我的一样。按照下面老哥那个可以了

lsp-python-mslsp-python-ms-cache设置缓存无效,每次启动重新索引有点慢,查了查是服务的原因

@seagle0128 看了下lsp-pyright没有找到缓存相关的配置,也不能缓存吗?系统、类库也要每次重新索引吗?

lsp-pyright 没有缓存的选项,但是没有发现每次启动都要重建索引。你可以试试看到底有没有这现象。

大佬请问一个问题,在pyrightconfig文件里设置python版本为3.0 但是lsp-log里显示pyright最后设置的pythonpath还是指向了python2, pyright中相关输出好像来自这里。我怎么检查lsp-pyright传入的参数呢? 谢谢!

非直接回答。python的版本,我是通过conda进行管理,在Emacs中,一个python项目会切换到相应的conda环境里,这样pyright就会利用当前的python。这个比你修改config是不是能更直接,也更灵活些?

虽然我不用conda,请问是怎么实现环境控制的,类似venv?

conda的不同python环境在各自独立的目录里;在emacs python mode里, 我利用pyvenv-workon 切换不同环境。我就是直接使用spacemacs的python layer。切换后,我运行lsp-workspace-restart 再重启更新下lsp。

看看这个是什么值:M-! python --version

我这通过 pyrightconfig.json 设置也有些问题,具体可见下面 issue owner 的最后一个回复

python2.7.16