microsoft / pyright

Static Type Checker for Python
Other
13.27k stars 1.44k forks source link

pyright shuts down on opening python file - used with eglot and emacs 29.1 #5689

Closed simonsjw closed 1 year ago

simonsjw commented 1 year ago

I am trying to use pyright with eglot and emacs. I have emacs 29.1 and have pyright installed via pip in an anaconda environment called pythonProject.

I initially didn't have a pyrightconfig.json file but added one in an attempt to clarify the issue. It made no difference to the error. I also get the same error regardless of Python file opened. I normally use a softlink to put a directory from another location directly under my profile. If I open the source directory following the full map rather than the shortcut, I get the same error.

This is the error I get:

[internal] Fri Aug 11 15:44:01 2023:
(:message "Running language server: /home/simon/anaconda3/envs/pythonProject/bin/pyright-langserver --stdio")
[client-request] (id:1) Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :id 1 :method "initialize" :params
          (:processId 19032 :rootPath "/home/simon/bin/" :rootUri "file:///home/simon/sync/primary/bin" :initializationOptions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data
                                                                                                                                             ())
                      :capabilities
                      (:workspace
                       (:applyEdit t :executeCommand
                                   (:dynamicRegistration :json-false)
                                   :workspaceEdit
                                   (:documentChanges t)
                                   :didChangeWatchedFiles
                                   (:dynamicRegistration t)
                                   :symbol
                                   (:dynamicRegistration :json-false)
                                   :configuration t :workspaceFolders t)
                       :textDocument
                       (:synchronization
                        (:dynamicRegistration :json-false :willSave t :willSaveWaitUntil t :didSave t)
                        :completion
                        (:dynamicRegistration :json-false :completionItem
                                              (:snippetSupport t :deprecatedSupport t :resolveSupport
                                                               (:properties
                                                                ["documentation" "details" "additionalTextEdits"])
                                                               :tagSupport
                                                               (:valueSet
                                                                [1]))
                                              :contextSupport t)
                        :hover
                        (:dynamicRegistration :json-false :contentFormat
                                              ["markdown" "plaintext"])
                        :signatureHelp
                        (:dynamicRegistration :json-false :signatureInformation
                                              (:parameterInformation
                                               (:labelOffsetSupport t)
                                               :activeParameterSupport t))
                        :references
                        (:dynamicRegistration :json-false)
                        :definition
                        (:dynamicRegistration :json-false :linkSupport t)
                        :declaration
                        (:dynamicRegistration :json-false :linkSupport t)
                        :implementation
                        (:dynamicRegistration :json-false :linkSupport t)
                        :typeDefinition
                        (:dynamicRegistration :json-false :linkSupport t)
                        :documentSymbol
                        (:dynamicRegistration :json-false :hierarchicalDocumentSymbolSupport t :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]))
                        :documentHighlight
                        (:dynamicRegistration :json-false)
                        :codeAction
                        (:dynamicRegistration :json-false :codeActionLiteralSupport
                                              (:codeActionKind
                                               (:valueSet
                                                ["quickfix" "refactor" "refactor.extract" "refactor.inline" "refactor.rewrite" "source" "source.organizeImports"]))
                                              :isPreferredSupport t)
                        :formatting
                        (:dynamicRegistration :json-false)
                        :rangeFormatting
                        (:dynamicRegistration :json-false)
                        :rename
                        (:dynamicRegistration :json-false)
                        :inlayHint
                        (:dynamicRegistration :json-false)
                        :publishDiagnostics
                        (:relatedInformation :json-false :codeDescriptionSupport :json-false :tagSupport
                                             (:valueSet
                                              [1 2])))
                       :window
                       (:workDoneProgress t)
                       :general
                       (:positionEncodings
                        ["utf-32" "utf-8" "utf-16"])
                       :experimental #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data
                                                   ()))
                      :workspaceFolders
                      [(:uri "file:///home/simon/sync/primary/bin" :name "~/bin/")]))
[server-notification] Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params
          (:type 3 :message "Pyright language server 1.1.321 starting"))
[server-notification] Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params
          (:type 3 :message "Server root directory: /home/simon/.cache/pyright-python/1.1.321/node_modules/pyright/dist/"))
[server-notification] Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params
          (:type 3 :message "Starting service instance \"~/bin/\""))
[server-reply] (id:1) Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :id 1 :result
          (:capabilities
           (:textDocumentSync 2 :definitionProvider
                              (:workDoneProgress t)
                              :declarationProvider
                              (:workDoneProgress t)
                              :typeDefinitionProvider
                              (:workDoneProgress t)
                              :referencesProvider
                              (:workDoneProgress t)
                              :documentSymbolProvider
                              (:workDoneProgress t)
                              :workspaceSymbolProvider
                              (:workDoneProgress t)
                              :hoverProvider
                              (:workDoneProgress t)
                              :documentHighlightProvider
                              (:workDoneProgress t)
                              :renameProvider
                              (:prepareProvider t :workDoneProgress t)
                              :completionProvider
                              (:triggerCharacters
                               ["." "[" "\"" "'"]
                               :resolveProvider t :workDoneProgress t :completionItem
                               (:labelDetailsSupport t))
                              :signatureHelpProvider
                              (:triggerCharacters
                               ["(" "," ")"]
                               :workDoneProgress t)
                              :codeActionProvider
                              (:codeActionKinds
                               ["quickfix" "source.organizeImports"]
                               :workDoneProgress t)
                              :executeCommandProvider
                              (:commands
                               []
                               :workDoneProgress t)
                              :callHierarchyProvider t :workspace
                              (:workspaceFolders
                               (:supported t :changeNotifications t)))))
[client-notification] Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :method "initialized" :params #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data
                                                            ()))
[client-notification] Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :method "textDocument/didOpen" :params
          (:textDocument
           (:uri "file:///home/simon/sync/primary/bin/nfsDisconnect.py" :version 0 :languageId "python" :text "#! /usr/bin/env python3\n\nimport argparse\nimport logging\nimport subprocess\nimport os\nimport sys\nfrom systemd.journal import JournalHandler\nfrom argparse import Namespace\n\n\ndef parse_args() -> Namespace:\n    \"\"\"      This function collects arguments passed to it's parent using the argparse module.\n\n            :return: The argument namespace.\n            \"\"\"\n    parser = argparse.ArgumentParser(prog=\"nfsConnect\", description=main.__doc__)\n\n    parser.add_argument(\"-i\", \"--ip\", type=str, default=\"192.168.0.175\",\n                        help=\"The IP address to connect to.\")\n    args = parser.parse_args()\n    return args\n\n\ndef main() -> None:\n    \"\"\"This executable takes in an IP address and disconnects from it over nfs using umount.\n    It is assumed that the connection is present at a folder  /media/user/IPAddress.\n    \"\"\"\n    # Collect commandline arguments.\n    args = parse_args()\n\n    # Set up the Python logger\n    logger = logging.getLogger('nfsDisonnect')\n    logger.setLevel('DEBUG')\n    log_fmt = logging.Formatter(\"%(levelname)s %(message)s\")\n    log_ch = JournalHandler()\n    log_ch.setFormatter(log_fmt)\n    logger.addHandler(log_ch)\n    logger.info(\"attempting to disconnect \" + args.ip + \" nfs using nfsDisonnect.\")\n\n    # check that command is run under root.\n    try:\n        if os.getenv('USER') != \"root\":\n            raise PermissionError(\"nfsConnect needs root permissions to run.\")\n    except PermissionError as e:\n        logger.error(\"exception id; 13; type: Command not run under root permissions; \" +\n                      e.args[0] + \"; Unable to connect to IP \" + args.ip + \".\")\n        print(\"Command not run under root permissions; \" +\n              e.args[0] + \"; Unable to connect to WatsonNas Lun.\")\n        sys.exit(13)\n\n    try:\n        s_folder_path = \"/media/\" + os.getenv('USER') + \"/\" + args.ip\n\n        subprocess.run(['sudo umount -t nfs ' + s_folder_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE,\n                       check=True, shell=True)\n        logger.info(\"Unmounted \" + args.ip + \":/ at \" + s_folder_path + \" over nfs.\")\n\n        subprocess.run(['rmdir', s_folder_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)\n        logger.info(\"Deleted folder \" + s_folder_path + \".\")\n\n    except subprocess.CalledProcessError as e:\n        n = e.args[0]\n        logger.error('exception id; ' + str(n) + '; type: ' + str(e.stderr))\n        print(str(e.stderr))\n        sys.exit(n)\n\n    # exit with code 0 as script didn't thrown an error.\n    logger.info(\"nfsDisconnect successful.\")\n    print(\"nfsDisconnect successful. \" + s_folder_path + \" unmounted and mountpoint deleted.\")\n    sys.exit(0)\n\n\n# Run the program.\nif __name__ == \"__main__\":\n    main()\n")))
[client-notification] Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :method "workspace/didChangeConfiguration" :params
          (:settings #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data
                                   ())))
[server-request] (id:0) Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :id 0 :method "client/registerCapability" :params
          (:registrations
           [(:id "40984283-616c-4db0-8896-cc459169921a" :method "workspace/didChangeWatchedFiles" :registerOptions
                 (:watchers
                  [(:globPattern "**/pyrightconfig.json" :kind 7)
                   (:globPattern "**" :kind 7)]))]))
[client-reply] (id:0) ERROR Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :id 0 :error
          (:code -32603 :message "Internal error"))
[server-request] (id:1) Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :id 1 :method "workspace/configuration" :params
          (:items
           [(:scopeUri "file:///home/simon/sync/primary/bin" :section "python")]))
[client-reply] (id:1) Fri Aug 11 15:44:01 2023:
(:jsonrpc "2.0" :id 1 :result
          [nil])
[stderr] Error: Internal error
[stderr]     at handleResponse (/home/simon/.cache/pyright-python/1.1.321/node_modules/pyright/dist/pyright-internal/node_modules/vscode-jsonrpc/lib/common/connection.js:565:48)
[stderr]     at handleMessage (/home/simon/.cache/pyright-python/1.1.321/node_modules/pyright/dist/pyright-internal/node_modules/vscode-jsonrpc/lib/common/connection.js:345:13)
[stderr]     at processMessageQueue (/home/simon/.cache/pyright-python/1.1.321/node_modules/pyright/dist/pyright-internal/node_modules/vscode-jsonrpc/lib/common/connection.js:362:17)
[stderr]     at Immediate.<anonymous> (/home/simon/.cache/pyright-python/1.1.321/node_modules/pyright/dist/pyright-internal/node_modules/vscode-jsonrpc/lib/common/connection.js:334:13)
[stderr]     at processImmediate (node:internal/timers:478:21)
[internal] Fri Aug 11 15:44:01 2023:
(:message "Connection state changed" :change "exited abnormally with code 1\n")

----------b---y---e---b---y---e----------
[stderr] 
[stderr] 
[stderr] nil
[stderr] nil
[stderr] Process EGLOT (bin/(python-mode)) stderr finished

Below is the content of the pyrightconfig.json file I used. I had previously been using Pyright without a config file with no issues.

{
  "defineConstant": {
    "DEBUG": true
  },

  "stubPath": "src/stubs",
  "venv": "pythonProject",
  "venvPATH": "/home/simon/anaconda3/envs"

  "reportMissingImports": true,
  "reportMissingTypeStubs": false,

  "pythonVersion": "3.9",
  "pythonPlatform": "Linux",

  "executionEnvironments": [

    {
      "root": "/home/simon/bin"
    }
  ]
}

The error occurs whether I use this file or not. I am happy to provide any further information or carry out any tests that might be useful.

Thanks and regards,

Simon

erictraut commented 1 year ago

The pyright language server runs fine with other clients, so it's most likely a problem with your client or the LSP support extensions for your client. You'll need to work with the maintainers of your client to diagnose the problem.