Skip to content
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

LSP doesn't start over Tramp #217

Closed
Patryk27 opened this issue Jan 20, 2021 · 13 comments · Fixed by #218
Closed

LSP doesn't start over Tramp #217

Patryk27 opened this issue Jan 20, 2021 · 13 comments · Fixed by #218

Comments

@Patryk27
Copy link
Contributor

Patryk27 commented Jan 20, 2021

Hi,

rustic-mode works perfectly fine locally, but when started over a Tramp session (via standard C-x C-f /ssh:something), errors out with:

LSP :: There are no language servers supporting current mode `rustic-mode' registered with `lsp-mode'.
This issue might be caused by:
1. The language you are trying to use does not have built-in support in `lsp-mode'. You must install the required support manually. Examples of this are `lsp-java' or `lsp-metals'.
2. The language server that you expect to run is not configured to run for major mode `rustic-mode'. You may check that by checking the `:major-modes' that are passed to `lsp-register-client'.
3. `lsp-mode' doesn't have any integration for the language behind `rustic-mode'. Refer to https://emacs-lsp.github.io/lsp-mode/page/languages and https://langserver.org/ .

Syntax highlighting works, but LSP doesn't start at all.

For reference, I'm using standard Doom Emacs with no fancy plugins & no fancy configuration.

@brotzeit
Copy link
Owner

Is your LSP server installed on the remote system ?

@Patryk27
Copy link
Contributor Author

Patryk27 commented Jan 20, 2021

Yes - I'm using NixOS, so my local & remote configuration are almost identical; additionally, LSP via ssh emacs -nw works as usual.

lsp-doctor via Tramp says:

Checking for Native JSON support: OK
Using company-capf: OK
Check emacs supports `read-process-output-max': OK
Check `read-process-output-max' default has been changed from 4k: OK
Byte compiled against Native JSON (recompile lsp-mode if failing when Native JSON available): OK
`gc-cons-threshold' increased?: OK
Using gccemacs with emacs lisp native compilation (https://akrl.sdf.org/gccemacs.html): NOT AVAILABLE (OPTIONAL)

@brotzeit
Copy link
Owner

brotzeit commented Jan 20, 2021

I guess you are using rust-analyzer. Can you run it manually on the remote host ?

@Patryk27
Copy link
Contributor Author

Yes, I'm using rust-analyzer - it works on the remote machine:

❯ rust-analyzer --version
rust-analyzer 2021-01-04

@brotzeit
Copy link
Owner

I haven't used lsp-mode on remote hosts, but I just noticed https://emacs-lsp.github.io/lsp-mode/page/remote/. Have you tried it ?

@Patryk27
Copy link
Contributor Author

I've tried adding:

(with-eval-after-load "lsp-rust"
    (lsp-register-client
     (make-lsp-client
      :new-connection (lsp-tramp-connection
                       (executable-find (car lsp-rust-analyzer-server-command)))
      :major-modes '(rust-mode rustic-mode)
      :priority (if (eq lsp-rust-server 'rust-analyzer) 1 -1)
      :remote? t
      :initialization-options 'lsp-rust-analyzer--make-init-options
      :notification-handlers (ht<-alist lsp-rust-notification-handlers)
      :action-handlers (ht<-alist lsp-rust-action-handlers)
      :library-folders-fn (lambda (_workspace) lsp-rust-library-directories)
      :ignore-messages nil
      :server-id 'rust-analyzer-remote)))

(and similar ones)
... and they all made Emacs bail out with:

Debugger entered--Lisp error: (wrong-number-of-arguments (3 . 3) 7)
  start-file-process-shell-command("rust-analyzer-remote" "*rust-analyzer-remote*" "stty" "raw" ";" "/etc/profiles/per-user/ppp/bin/rust-analyzer" "2>/tmp/rust-analyzer-remote-3-stderr")
  apply(start-file-process-shell-command "rust-analyzer-remote" "*rust-analyzer-remote*" ("stty" "raw" ";" "/etc/profiles/per-user/ppp/bin/rust-analyzer" "2>/tmp/rust-analyzer-remote-3-stderr"))
  lsp--start-workspace(...)
  lsp--start-connection(...)
  mapcar(...)
  lsp--ensure-lsp-servers(...)
  lsp--try-project-root-workspaces(nil nil)
  lsp()
  rustic-setup-lsp()
  rustic-mode()

@Patryk27
Copy link
Contributor Author

Patryk27 commented Jan 20, 2021

Actually, this new error might be emacs-lsp/lsp-mode#2514 - I'll check when I get home later.

@Patryk27
Copy link
Contributor Author

Yeah, adding emacs-lsp/lsp-mode#2514 (comment) and #217 (comment) made LSP work 😄

Thanks for helping!

@brotzeit brotzeit reopened this Jan 20, 2021
@brotzeit
Copy link
Owner

What did you do exactly so we can add it to the readme ?

@Patryk27
Copy link
Contributor Author

Patryk27 commented Jan 21, 2021

I added those lines to my config.el:

;; fix for Emacs 28 (https://github.com/emacs-lsp/lsp-mode/issues/2514#issuecomment-759452037)
(defun start-file-process-shell-command@around (start-file-process-shell-command name buffer &rest args)
    "Start a program in a subprocess.  Return the process object for it. Similar to `start-process-shell-command', but calls `start-file-process'."
    (let ((command (mapconcat 'identity args " ")))
        (funcall start-file-process-shell-command name buffer command)))

(advice-add 'start-file-process-shell-command :around #'start-file-process-shell-command@around)

;; remote rust-analyzer
(with-eval-after-load "lsp-rust"
    (lsp-register-client
     (make-lsp-client
      :new-connection (lsp-tramp-connection
                       (executable-find (car lsp-rust-analyzer-server-command)))
      :major-modes '(rust-mode rustic-mode)
      :priority (if (eq lsp-rust-server 'rust-analyzer) 1 -1)
      :remote? t
      :initialization-options 'lsp-rust-analyzer--make-init-options
      :notification-handlers (ht<-alist lsp-rust-notification-handlers)
      :action-handlers (ht<-alist lsp-rust-action-handlers)
      :library-folders-fn (lambda (_workspace) lsp-rust-library-directories)
      :ignore-messages nil
      :server-id 'rust-analyzer-remote)))

@brotzeit
Copy link
Owner

Do you want to add a section to the readme ? I haven't set it up myself, so maybe you can add some hints why this is needed.

@Patryk27
Copy link
Contributor Author

Sure, I'll prepare a merge request tomorrow :-)

@brotzeit
Copy link
Owner

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants