pylsp无法识别已安装可编辑包,跳转定义失败求助
pylsp无法定位可编辑安装包的定义
pylsp无法处理通过pip install -e安装的可编辑Python包,具体表现为:Python能正常识别并导入该包,但在编辑器中尝试跳转至包定义时,pylsp返回空结果,无法找到目标位置。
复现步骤
$ mkdir /tmp/pyslp_test $ cd /tmp/pylsp_test $ echo "import jaxtyping" > script.py $ mkdir editable_packages $ git clone https://github.com/google/jaxtyping editable_packages/jaxtyping $ pip3 install -e editable_packages/jaxtyping/ $ python3 -c 'import jaxtyping; print(jaxtyping.__path__)' ['/private/tmp/pylsp_test/editable_packages/jaxtyping/jaxtyping']
执行上述步骤后,打开script.py,将光标放在jaxtyping上尝试跳转至定义,pylsp提示无法找到该定义,但Python明确能识别这个包。
编辑器日志相关内容
[Trace - 04:05:16 PM] Sending request 'initialize - (2148)'. Params: { "processId": null, "rootPath": "/tmp", "clientInfo": { "name": "emacs", "version": "GNU Emacs 28.2 (build 1, aarch64-apple-darwin21.1.0, NS appkit-2113.00 Version 12.0.1 (Build 21A559))\n of 2022-09-12" }, "rootUri": "file:///tmp", "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 }, "didChangeWatchedFiles": { "dynamicRegistration": true }, "workspaceFolders": true, "configuration": true, "fileOperations": { "didCreate": false, "willCreate": false, "didRename": false, "willRename": false, "didDelete": false, "willDelete": false } }, "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" ] } }, "resolveSupport": { "properties": [ "edit", "command" ] }, "dataSupport": true }, "completion": { "completionItem": { "snippetSupport": false, "documentationFormat": [ "markdown", "plaintext" ], "resolveAdditionalTextEditsSupport": true, "insertReplaceSupport": true, "deprecatedSupport": true, "resolveSupport": { "properties": [ "documentation", "details", "additionalTextEdits", "command" ] }, "insertTextModeSupport": { "valueSet": [ 1, 2 ] } }, "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 }, "linkedEditingRange": { "dynamicRegistration": true } }, "window": { "workDoneProgress": true, "showMessage": null, "showDocument": { "support": true } } }, "initializationOptions": null, "workDoneToken": "1" } [Trace - 04:05:16 PM] Received response 'initialize - (2148)' in 747ms. Result: { "capabilities": { "codeActionProvider": true, "codeLensProvider": { "resolveProvider": null }, "completionProvider": { "resolveProvider": true, "triggerCharacters": [ "." ] }, "documentFormattingProvider": true, "documentHighlightProvider": true, "documentRangeFormattingProvider": true, "documentSymbolProvider": true, "definitionProvider": true, "executeCommandProvider": { "commands": [] }, "hoverProvider": true, "referencesProvider": true, "renameProvider": true, "foldingRangeProvider": true, "signatureHelpProvider": { "triggerCharacters": [ "(", ",", "=" ] }, "textDocumentSync": { "change": 2, "save": { "includeText": true }, "openClose": true }, "workspace": { "workspaceFolders": { "supported": true, "changeNotifications": true } }, "experimental": {} }, "serverInfo": { "name": "pylsp", "version": "1.4.1" } } [Trace - 04:05:16 PM] Sending notification 'initialized'. Params: {} [Trace - 04:05:16 PM] Sending notification 'workspace/didChangeConfiguration'. Params: { "settings": { "pylsp": { "plugins": { "rope_rename": { "enabled": false }, "autopep8": { "enabled": false }, "yapf": { "enabled": false }, "rope_completion": { "enabled": false }, "pyflakes": { "enabled": false }, "pydocstyle": { "matchDir": "[^\\.].*", "match": "(?!test_).*\\.py", "enabled": true }, "pycodestyle": { "hangClosing": false, "enabled": false }, "pylint": { "enabled": false, "args": [] }, "flake8": { "enabled": true }, "preload": { "enabled": true }, "mccabe": { "threshold": 15, "enabled": true }, "jedi_symbols": { "all_scopes": true, "enabled": true }, "jedi_signature_help": { "enabled": true }, "jedi_references": { "enabled": true }, "jedi_hover": { "enabled": true }, "jedi_definition": { "follow_builtin_imports": true, "follow_imports": true, "enabled": true }, "jedi_completion": { "include_params": true, "enabled": true, "include_class_objects": true, "fuzzy": false }, "jedi_rename": { "enabled": true } }, "configurationSources": [ "flake8" ] } } } [Trace - 04:05:16 PM] Sending notification 'textDocument/didOpen'. Params: { "textDocument": { "uri": "file:///tmp/pylsp_test/script.py", "languageId": "python", "version": 19, "text": "import jaxtyping\n" } } ... [Trace - 04:05:44 PM] Sending request 'textDocument/definition - (2154)'. Params: { "textDocument": { "uri": "file:///tmp/pylsp_test/script.py" }, "position": { "line": 0, "character": 15 } } [Trace - 04:05:44 PM] Received response 'textDocument/definition - (2154)' in 7ms. Result: []
本人多年未使用Python,对pylsp了解有限,但这是基础使用场景,倾向于是自身操作失误而非bug。另外非可编辑包也存在同样问题,但目前暂不关注此类情况。
内容的提问来源于stack exchange,提问作者fakedrake
相关产品推荐
相关产品推荐

