Kayla Skates - Home / Posts

Emacs – Eglot and Running pyright in Docker

Emacs eglot kept connecting and disconnecting from my language running in docker.[1]

TLDR, the following snippet works:

(setq eglot-withhold-process-id t)
(add-to-list 'eglot-server-programs `(python-mode . ("docker" "run" "--rm" "-i" "-v" "/private/tmp/python:/private/tmp/python" "debian-lsp" "pyright-langserver" "--stdio" :initializationOptions (:python (:pythonPath "python3")))))

The key part is setting eglot-withhold-process-id to t.

The Language Server spec specifies the process id is used to detect when the editor crashes, so the language server shutdown. ref: languageserver spec. By default, eglot was sending a process PID (like emacs pid). Since pyright ran in a container, it thought the editor terminated as the pid didn’t exist, and would shut down.

[jsonrpc] D[23:00:31.555] Running language server: docker run --rm -i -v /private/tmp/python:/private/tmp/python alpine-lsp pyright-langserver --stdio

[jsonrpc] e[23:00:31.556] --> initialize[1] {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"processId":5140,"clientInfo":{"name":"Eglot","version":"1.17.30"},"rootPath":"/private/tmp/python/","rootUri":"file:///private/tmp/python","initializationOptions":{"python":{"pythonPath":"python3"}},"capabilities":{"workspace":{"applyEdit":true,"executeCommand":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":false},"configuration":true,"workspaceFolders":true},"textDocument":{"synchronization":{"dynamicRegistration":false,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":false,"completionItem":{"snippetSupport":false,"deprecatedSupport":true,"resolveSupport":{"properties":["documentation","details","additionalTextEdits"]},"tagSupport":{"valueSet":[1]}},"contextSupport":true},"hover":{"dynamicRegistration":false,"contentFormat":["plaintext"]},"signatureHelp":{"dynamicRegistration":false,"signatureInformation":{"parameterInformation":{"labelOffsetSupport":true},"documentationFormat":["plaintext"],"activeParameterSupport":true}},"references":{"dynamicRegistration":false},"definition":{"dynamicRegistration":false,"linkSupport":true},"declaration":{"dynamicRegistration":false,"linkSupport":true},"implementation":{"dynamicRegistration":false,"linkSupport":true},"typeDefinition":{"dynamicRegistration":false,"linkSupport":true},"documentSymbol":{"dynamicRegistration":false,"hierarchicalDocumentSymbolSupport":true,"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":false},"codeAction":{"dynamicRegistration":false,"resolveSupport":{"properties":["edit","command"]},"dataSupport":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"isPreferredSupport":true},"formatting":{"dynamicRegistration":false},"rangeFormatting":{"dynamicRegistration":false},"rename":{"dynamicRegistration":false},"inlayHint":{"dynamicRegistration":false},"publishDiagnostics":{"relatedInformation":false,"codeDescriptionSupport":false,"tagSupport":{"valueSet":[1,2]}}},"window":{"showDocument":{"support":true},"workDoneProgress":true},"general":{"positionEncodings":["utf-32","utf-8","utf-16"]},"experimental":{}},"workspaceFolders":[{"uri":"file:///private/tmp/python","name":"/private/tmp/python/"}]}}

[jsonrpc] e[23:00:32.178] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Pyright language server 1.1.411 starting"}}

[jsonrpc] e[23:00:32.178] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Server root directory: file:///usr/local/lib/node_modules/pyright/dist"}}

[jsonrpc] e[23:00:32.185] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Starting service instance \"/private/tmp/python/\""}}

[jsonrpc] e[23:00:32.185] <-- initialize[1] {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"textDocumentSync":2,"definitionProvider":{"workDoneProgress":true},"declarationProvider":{"workDoneProgress":true},"typeDefinitionProvider":{"workDoneProgress":true},"referencesProvider":{"workDoneProgress":true},"documentSymbolProvider":{"workDoneProgress":true},"workspaceSymbolProvider":{"workDoneProgress":true},"hoverProvider":{"workDoneProgress":true},"documentHighlightProvider":{"workDoneProgress":true},"renameProvider":{"prepareProvider":true,"workDoneProgress":true},"completionProvider":{"triggerCharacters":[".","[","\"","'"],"resolveProvider":true,"workDoneProgress":true,"completionItem":{"labelDetailsSupport":true}},"signatureHelpProvider":{"triggerCharacters":["(",",",")"],"workDoneProgress":true},"codeActionProvider":{"codeActionKinds":["quickfix","source.organizeImports"],"workDoneProgress":true},"executeCommandProvider":{"commands":[],"workDoneProgress":true},"callHierarchyProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}}}}}

[jsonrpc] e[23:00:32.185] --> initialized {"jsonrpc":"2.0","method":"initialized","params":{}}

[jsonrpc] e[23:00:32.186] --> textDocument/didOpen {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///private/tmp/python/what.py","version":0,"languageId":"python","text":"def hello_world():\n    print(\"123\")\n\nhello_world()\n"}}}

[jsonrpc] e[23:00:32.348] --> workspace/didChangeConfiguration {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{}}}

[jsonrpc] e[23:00:32.457] <-- client/registerCapability[0] {"jsonrpc":"2.0","id":0,"method":"client/registerCapability","params":{"registrations":[{"id":"1ac226a7-2452-41bc-b705-2db23bcefe46","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/pyrightconfig.json","kind":7},{"globPattern":"**","kind":7}]}}]}}

[jsonrpc] e[23:00:32.479] --> client/registerCapability[0] {"jsonrpc":"2.0","id":0,"result":null}

[jsonrpc] e[23:00:32.479] <-- workspace/configuration[1] {"jsonrpc":"2.0","id":1,"method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///private/tmp/python","section":"python"}]}}

[jsonrpc] e[23:00:32.479] --> workspace/configuration[1] {"jsonrpc":"2.0","id":1,"result":[null]}

[jsonrpc] e[23:00:32.479] <-- workspace/configuration[2] {"jsonrpc":"2.0","id":2,"method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///private/tmp/python","section":"python"}]}}

[jsonrpc] e[23:00:32.480] --> workspace/configuration[2] {"jsonrpc":"2.0","id":2,"result":[null]}

[jsonrpc] e[23:00:32.488] <-- workspace/configuration[3] {"jsonrpc":"2.0","id":3,"method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///private/tmp/python","section":"pyright"}]}}

[jsonrpc] e[23:00:32.488] --> workspace/configuration[3] {"jsonrpc":"2.0","id":3,"result":[null]}

[jsonrpc] e[23:00:32.488] <-- workspace/configuration[4] {"jsonrpc":"2.0","id":4,"method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///private/tmp/python","section":"pyright"}]}}

[jsonrpc] e[23:00:32.489] --> workspace/configuration[4] {"jsonrpc":"2.0","id":4,"result":[null]}

[jsonrpc] e[23:00:32.724] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"No include entries specified; assuming /private/tmp/python"}}

[jsonrpc] e[23:00:32.724] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Auto-excluding **/node_modules"}}

[jsonrpc] e[23:00:32.724] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Auto-excluding **/__pycache__"}}

[jsonrpc] e[23:00:32.724] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Auto-excluding **/.*"}}

[jsonrpc] e[23:00:32.724] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Assuming Python version 3.14.5.final.0"}}

[jsonrpc] e[23:00:32.724] <-- client/registerCapability[5] {"jsonrpc":"2.0","id":5,"method":"client/registerCapability","params":{"registrations":[{"id":"bcf8b7bf-1730-4659-9d15-6379a8fd3a45","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/pyrightconfig.json","kind":7},{"globPattern":"**","kind":7}]}}]}}

[jsonrpc] e[23:00:32.747] --> client/registerCapability[5] {"jsonrpc":"2.0","id":5,"result":null}

[jsonrpc] e[23:00:32.757] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"No include entries specified; assuming /private/tmp/python"}}

[jsonrpc] e[23:00:32.757] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Auto-excluding **/node_modules"}}

[jsonrpc] e[23:00:32.757] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Auto-excluding **/__pycache__"}}

[jsonrpc] e[23:00:32.757] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Auto-excluding **/.*"}}

[jsonrpc] e[23:00:32.757] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Assuming Python version 3.14.5.final.0"}}

[jsonrpc] e[23:00:32.757] <-- client/registerCapability[6] {"jsonrpc":"2.0","id":6,"method":"client/registerCapability","params":{"registrations":[{"id":"66637763-f2fa-4d60-8385-2736e5c59da3","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/pyrightconfig.json","kind":7},{"globPattern":"**","kind":7}]}}]}}

[jsonrpc] e[23:00:32.778] --> client/registerCapability[6] {"jsonrpc":"2.0","id":6,"result":null}

[jsonrpc] e[23:00:33.072] <-- window/logMessage {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Found 2 source files"}}

[jsonrpc] e[23:00:33.072] <-- textDocument/publishDiagnostics {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///private/tmp/python/what.py","version":0,"diagnostics":[]}}

[jsonrpc] e[23:00:33.080] <-- client/unregisterCapability[7] {"jsonrpc":"2.0","id":7,"method":"client/unregisterCapability","params":{"unregisterations":[{"id":"1ac226a7-2452-41bc-b705-2db23bcefe46","method":"workspace/didChangeWatchedFiles"}]}}

[jsonrpc] e[23:00:33.080] --> client/unregisterCapability[7] {"jsonrpc":"2.0","id":7,"result":null}

[jsonrpc] e[23:00:33.080] <-- client/unregisterCapability[8] {"jsonrpc":"2.0","id":8,"method":"client/unregisterCapability","params":{"unregisterations":[{"id":"bcf8b7bf-1730-4659-9d15-6379a8fd3a45","method":"workspace/didChangeWatchedFiles"}]}}

[jsonrpc] e[23:00:33.080] --> client/unregisterCapability[8] {"jsonrpc":"2.0","id":8,"result":null}

[jsonrpc] D[23:00:35.336] Connection state change: `exited abnormally with code 1

'

  

----------b---y---e---b---y---e----------

[stderr]  

[stderr]  

[stderr]  nil

[stderr]  nil

[stderr]  Process EGLOT (python/(python-mode)) stderr finished

  1. The Eglot Error Mesage for reference↩︎

Leave a Reply

Your email address will not be published. Required fields are marked *