Skip to content

pylsp times out over TRAMP #3530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 3 tasks
connorfuhrman opened this issue May 19, 2022 · 1 comment · Fixed by #4204
Closed
2 of 3 tasks

pylsp times out over TRAMP #3530

connorfuhrman opened this issue May 19, 2022 · 1 comment · Fixed by #4204
Labels

Comments

@connorfuhrman
Copy link

Thank you for the bug report

  • I am using the latest version of lsp-mode related packages.
  • I checked FAQ and Troubleshooting sections
  • You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

Bug description

pylsp connects successfully but then has no functionality. Does not show current function in the top and cannot find definition. Consistently times out.

(also posted at https://emacs.stackexchange.com/questions/71806/pylsp-times-out-over-tramp)

Steps to reproduce

I am using pyenv but haven't gotten the Emacs integration working so to find the correct pylsp I added this script in $HOME/.local/bin/tramp_pylsp_wrapper:

#!/bin/sh

## Wrapper for connecting with TRAMP to source pyenv and
## start python language server
##
## This is a bandaid. Should find a better solution

set -e

PYENV_TO_USE=pylsp-test


# Set up pyenv
export PATH="$HOME/.pyenv/bin:$PATH"

eval "$(pyenv init - )"
eval "$(pyenv virtualenv-init -)"
export PYENV_VIRTUALENV_DISABLE_PROMPT=1

pyenv shell $PYENV_TO_USE

pylsp "$@"

My TRAMP configuration is below:

(use-package tramp
  :config
  (add-to-list 'tramp-remote-path "/home/connorfuhrman/.local/bin")
  (add-to-list 'tramp-remote-path 'tramp-own-remote-path) 
  (when (eq window-system 'w32)
    (setq tramp-default-method "plink")))

and my lsp-mode setup is below:

;; LSP setup
(use-package lsp-mode
  :ensure t
  :commands lsp lsp-deferred
  :hook (python-mode . lsp-deferred)
  :config
  (progn
    ;;(add-hook 'python-mode-hook #'lsp)
    (lsp-register-client
     (make-lsp-client :new-connection (lsp-tramp-connection "tramp_pylsp_wrapper")
                      :major-modes '(python-mode)
                      :remote? t
                      :server-id 'tramp_pylsp_wrapper-remote))))
(setq lsp-response-timeout 30)
(setq lsp-log-io t)
;; Dirty hack for TRAMP lsp issues
;; from https://github.com/emacs-lsp/lsp-mode/issues/1845#issuecomment-699169414
(defun lsp--make-message@override (params)
  "Create a LSP message from PARAMS, after encoding it to a JSON string."
  (let ((body (lsp--json-serialize params)))
    (concat "Content-Length: "
            (number-to-string (+ 2 (string-bytes body))) ;; dirty fix for pyls remote (https://github.com/emacs-lsp/lsp-mode/issues/1845#issuecomment-699169414)
            ;;(number-to-string (1+ (string-bytes body)))
            "\r\n\r\n"
            body
            "\n")))
(advice-add 'lsp--make-message :override #'lsp--make-message@override)

Expected behavior

Code navigation and lsp functionality over TRAMP

Which Language Server did you use?

python-lsp-server: https://emacs-lsp.github.io/lsp-mode/page/lsp-pylsp/

OS

Windows

Error callstack

-el
Debugger entered--Lisp error: (error "Timeout while waiting for response.  Method: textDocument/definition")
  error("Timeout while waiting for response.  Method: %s" "textDocument/definition")
  lsp-request("textDocument/definition" (:textDocument (:uri "file:////home/connorfuhrman/pylsp-testing/test.py") :position (:line 9 :character 7)))
  lsp-find-locations("textDocument/definition" nil :display-action nil)
  lsp-find-definition()
  funcall-interactively(lsp-find-definition)
  call-interactively(lsp-find-definition)
  #f(compiled-function () #<bytecode -0xb04039385fac28a>)()
  apply(#f(compiled-function () #<bytecode -0xb04039385fac28a>) nil)
  timer-event-handler([t 0 0 1000 nil #f(compiled-function () #<bytecode -0xb04039385fac28a>) nil idle 0 nil])

[Trace - 04:45:27 PM] Sending request 'initialize - (1)'.
Params: {
"processId": null,
"rootPath": "/home/connorfuhrman/pylsp-testing",
"clientInfo": {
"name": "emacs",
"version": "GNU Emacs 28.1 (build 2, x86_64-w64-mingw32)\n of 2022-04-21"
},
"rootUri": "file:////home/connorfuhrman/pylsp-testing",
"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,
"codeLens": {
"refreshSupport": true
},
"fileOperations": {
"didCreate": false,
"willCreate": false,
"didRename": true,
"willRename": true,
"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": true,
"documentationFormat": [
"markdown",
"plaintext"
],
"resolveAdditionalTextEditsSupport": true,
"insertReplaceSupport": true,
"deprecatedSupport": true,
"resolveSupport": {
"properties": [
"documentation",
"detail",
"additionalTextEdits",
"command"
]
},
"insertTextModeSupport": {
"valueSet": [
1,
2
]
}
},
"contextSupport": true
},
"signatureHelp": {
"signatureInformation": {
"parameterInformation": {
"labelOffsetSupport": true
}
}
},
"documentLink": {
"dynamicRegistration": true,
"tooltipSupport": true
},
"hover": {
"contentFormat": [
"markdown",
"plaintext"
]
},
"foldingRange": {
"dynamicRegistration": true
},
"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:45:32 PM] Received response 'initialize - (1)' in 984ms.
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:45:32 PM] Sending notification 'initialized'.
Params: {}

[Trace - 04:45:32 PM] Sending notification 'textDocument/didOpen'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py",
"languageId": "python",
"version": 0,
"text": "def func():\n print("Hello I'm a function!!")\n\n\ndef testme():\n func()\n\n\ndef main():\n testme()\n\n\n\nif name == 'main':\n main()\n"
}
}

[Trace - 04:45:32 PM] Sending request 'textDocument/codeLens - (2)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
}
}

[Trace - 04:45:33 PM] Sending request 'textDocument/documentSymbol - (3)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
}
}

[Trace - 04:45:33 PM] Sending request 'textDocument/codeAction - (4)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"context": {
"diagnostics": []
}
}

[Trace - 04:45:33 PM] Sending request 'textDocument/documentHighlight - (5)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"position": {
"line": 0,
"character": 0
}
}

[Trace - 04:45:33 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 2
}

[Trace - 04:45:33 PM] Sending request 'textDocument/codeLens - (6)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
}
}

[Trace - 04:45:33 PM] Sending request 'textDocument/documentSymbol - (7)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
}
}

[Trace - 04:45:33 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 4
}

[Trace - 04:45:33 PM] Sending request 'textDocument/codeAction - (8)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"context": {
"diagnostics": []
}
}

[Trace - 04:45:33 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 5
}

[Trace - 04:45:33 PM] Sending request 'textDocument/documentHighlight - (9)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"position": {
"line": 0,
"character": 0
}
}

[Trace - 04:45:35 PM] Sending request 'textDocument/documentSymbol - (10)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
}
}

[Trace - 04:45:35 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 8
}

[Trace - 04:45:35 PM] Sending request 'textDocument/codeAction - (11)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"range": {
"start": {
"line": 15,
"character": 0
},
"end": {
"line": 15,
"character": 0
}
},
"context": {
"diagnostics": []
}
}

[Trace - 04:45:35 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 9
}

[Trace - 04:45:35 PM] Sending request 'textDocument/documentHighlight - (12)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"position": {
"line": 15,
"character": 0
}
}

[Trace - 04:45:35 PM] Sending request 'textDocument/hover - (13)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"position": {
"line": 15,
"character": 0
}
}

[Trace - 04:45:37 PM] Sending request 'textDocument/documentSymbol - (14)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
}
}

[Trace - 04:45:37 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 11
}

[Trace - 04:45:37 PM] Sending request 'textDocument/codeAction - (15)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"range": {
"start": {
"line": 13,
"character": 19
},
"end": {
"line": 13,
"character": 19
}
},
"context": {
"diagnostics": []
}
}

[Trace - 04:45:37 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 12
}

[Trace - 04:45:37 PM] Sending request 'textDocument/documentHighlight - (16)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"position": {
"line": 13,
"character": 19
}
}

[Trace - 04:45:38 PM] Sending request 'textDocument/documentSymbol - (17)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
}
}

[Trace - 04:45:38 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 15
}

[Trace - 04:45:38 PM] Sending request 'textDocument/codeAction - (18)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"range": {
"start": {
"line": 9,
"character": 4
},
"end": {
"line": 9,
"character": 10
}
},
"context": {
"diagnostics": []
}
}

[Trace - 04:45:38 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 16
}

[Trace - 04:45:38 PM] Sending request 'textDocument/documentHighlight - (19)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"position": {
"line": 9,
"character": 10
}
}

[Trace - 04:45:38 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 13
}

[Trace - 04:45:38 PM] Sending request 'textDocument/hover - (20)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"position": {
"line": 9,
"character": 10
}
}

[Trace - 04:45:40 PM] Sending request 'textDocument/documentSymbol - (21)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
}
}

[Trace - 04:45:40 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 18
}

[Trace - 04:45:40 PM] Sending request 'textDocument/codeAction - (22)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"range": {
"start": {
"line": 8,
"character": 11
},
"end": {
"line": 8,
"character": 11
}
},
"context": {
"diagnostics": []
}
}

[Trace - 04:45:42 PM] Sending request 'textDocument/documentSymbol - (23)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
}
}

[Trace - 04:45:42 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 22
}

[Trace - 04:45:42 PM] Sending request 'textDocument/codeAction - (24)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"range": {
"start": {
"line": 8,
"character": 11
},
"end": {
"line": 8,
"character": 11
}
},
"context": {
"diagnostics": []
}
}

[Trace - 04:45:44 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 24
}

[Trace - 04:52:37 PM] Sending request 'textDocument/documentSymbol - (25)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
}
}

[Trace - 04:52:37 PM] Sending request 'textDocument/codeAction - (26)'.
Params: {
"textDocument": {
"uri": "file:////home/connorfuhrman/pylsp-testing/test.py"
},
"range": {
"start": {
"line": 8,
"character": 11
},
"end": {
"line": 8,
"character": 11
}
},
"context": {
"diagnostics": []
}
}

[Trace - 04:52:37 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 26
}

Anything else?

Connecting from Windows 10 to Ubuntu

@connorfuhrman
Copy link
Author

The IO log did not paste well. It's on pastebin at https://pastebin.com/UQYJpvd6

yyoncho added a commit to yyoncho/lsp-mode that referenced this issue Oct 27, 2023
- This fixes the implementation of `lsp-mode` tramp support. After this PR the
remote clients will be automatically registered and in most of the cases it will
work out of the box. The remote connection is managed to a way similar to what
eglot does.

Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#3841
Fixes emacs-lsp#3642
Fixes emacs-lsp#3579
Fixes emacs-lsp#3530
Fixes emacs-lsp#3491
Fixes emacs-lsp#3490
Fixes emacs-lsp#3391
Fixes emacs-lsp#3369
Fixes emacs-lsp#3364
Fixes emacs-lsp#3020
Fixes emacs-lsp#3018
Fixes emacs-lsp#3020
yyoncho added a commit to yyoncho/lsp-mode that referenced this issue Oct 30, 2023
- This fixes the implementation of `lsp-mode` tramp support. After this PR the
remote clients will be automatically registered and in most of the cases it will
work out of the box. The remote connection is managed to a way similar to what
eglot does.

Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#3841
Fixes emacs-lsp#3642
Fixes emacs-lsp#3579
Fixes emacs-lsp#3530
Fixes emacs-lsp#3491
Fixes emacs-lsp#3490
Fixes emacs-lsp#3391
Fixes emacs-lsp#3369
Fixes emacs-lsp#3364
Fixes emacs-lsp#3020
Fixes emacs-lsp#3018
Fixes emacs-lsp#3020
@yyoncho yyoncho closed this as completed in d45aca0 Nov 1, 2023
yyoncho added a commit to yyoncho/lsp-mode that referenced this issue Nov 2, 2023
* Fix lsp-mode's tramp support

- This fixes the implementation of `lsp-mode` tramp support. After this PR the
remote clients will be automatically registered and in most of the cases it will
work out of the box. The remote connection is managed to a way similar to what
eglot does.

Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#3841
Fixes emacs-lsp#3642
Fixes emacs-lsp#3579
Fixes emacs-lsp#3530
Fixes emacs-lsp#3491
Fixes emacs-lsp#3490
Fixes emacs-lsp#3391
Fixes emacs-lsp#3369
Fixes emacs-lsp#3364
Fixes emacs-lsp#3020
Fixes emacs-lsp#3018
Fixes emacs-lsp#3020

* Use executable-find with remote = t everywhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant