2

The problem is fairly straightforward: pylsp can't deal with editable packages. To create an environment that reproduces my problem:

$ 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']

I open script.py from my editor and try to jump to the definition with my cursor on jaxtyping, but it claims it can't find the definition even though python is demonstrably aware of the package.

the relevant parts of my editor log:

[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: []

I haven't used python in many years, so I don't know much about pylsp but this seems like a very trivial use case, so I am inclined to believe that it is not a bug but an error on my part.

PS. I have the same problem with non-editable packages, but I am not interested in those for the time being.

fakedrake
  • 6,528
  • 8
  • 41
  • 64

0 Answers0