emacs-lsp / lsp-metals

lsp-mode :heart: metals
https://emacs-lsp.github.io/lsp-metals
GNU General Public License v3.0
58 stars 33 forks source link

TRAMP support #30

Open MagicRB opened 4 years ago

MagicRB commented 4 years ago

Describe the bug lsp-metals doesn't work with projects over TRAMP

To Reproduce open a .scala file over TRAMP and eval this lisp code

(lsp-register-client
   (make-lsp-client :new-connection (lsp-stdio-connection 'lsp-metals--server-command)
            :major-modes '(scala-mode)
            :priority -1
            :initialization-options '((decorationProvider . t)
                          (didFocusProvider . t)
                          (executeClientCommandProvider . t)
                          (doctorProvider . "html")
                          (statusBarProvider . "on")
                          (debuggingProvider . t)
                          (treeViewProvider . t))
            :notification-handlers (ht ("metals/executeClientCommand" #'lsp-metals--execute-client-command)
                           ("metals/publishDecorations" #'lsp-metals--publish-decorations)
                           ("metals/treeViewDidChange" #'lsp-metals-treeview--did-change)
                           ("metals-model-refresh" #'lsp-metals--model-refresh)
                           ("metals/status" #'lsp-metals--status-string))
            :action-handlers (ht ("metals-debug-session-start" (-partial #'lsp-metals--debug-start :json-false))
                     ("metals-run-session-start" (-partial #'lsp-metals--debug-start t)))
            :server-id 'metals
            :remote? ;; This is what i added
            :initialized-fn (lambda (workspace)
                      (lsp-metals--add-focus-hooks)
                      (with-lsp-workspace workspace
                    (lsp--set-configuration
                     (lsp-configuration-section "metals"))))
            :after-open-fn (lambda ()
                     (add-hook 'lsp-on-idle-hook #'lsp-metals--did-focus nil t))
            :completion-in-comments? t))

Expected behavior lsp-metals should work as if it was running on a local buffer.

Logs

Tramp: Opening connection for main@fractal.in.redalder.org using ssh...
Tramp: Sending command ‘exec ssh -l main  -o ControlMaster=auto -o ControlPath='tramp.%C' -o ControlPersist=no -e none example.org’
Tramp: Waiting for prompts from remote shell...
Tramp: Sending password
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on 'example.rog’
Tramp: Opening connection for main@example.org using ssh...done
Tramp: Inserting ‘/ssh:main@example.org:/home/main/.../AppEntry.scala’...
Tramp: Encoding remote file ‘/ssh:main@example.org:/home/main/.../AppEntry.scala’ with ‘(env GZIP= gzip <%s | base64)’...done
Tramp: Decoding local file ‘/tmp/tramp.ANFeAZ.scala’ with ‘(lambda (beg end) (base64-decode-region beg end) (let ((coding-system-for-write 'binary) (coding-system-for-read 'binary)) (apply #'tramp-call-process-region '(tramp-file-name ssh main nil example.org nil /home/main/.../AppEntry.scala nil) (point-min) (point-max) (car (split-string env GZIP= gzip -d)) t t nil (cdr (split-string env GZIP= gzip -d)))))’...done
Tramp: Inserting ‘/ssh:main@example.org:/home/main/.../AppEntry.scala’...done
File mode specification error: (wrong-type-argument hash-table-p nil)

Tramp: Checking ‘vc-registered’ for /ssh:main@example.org:/home/main/.../AppEntry.scala...done
File mode specification error: (wrong-type-argument hash-table-p nil)

This log was captured after a initial tramp connection was already established, but after resetting i got just more of the same

Note I'm sure lsp-metals worked on the remote computer as i just transformed it into a headless workstation

MagicRB commented 4 years ago

I now understand lisp better and with this bit of lisp, TRAMP is fully functional if a bit slow


(lsp-register-client
   (make-lsp-client :new-connection (lsp-tramp-connection 'lsp-metals--server-command)
            :major-modes '(scala-mode)
            :priority -1
            :initialization-options '((decorationProvider . t)
                          (didFocusProvider . t)
                          (executeClientCommandProvider . t)
                          (doctorProvider . "html")
                          (statusBarProvider . "on")
                          (debuggingProvider . t)
                          (treeViewProvider . t))
            :notification-handlers (ht ("metals/executeClientCommand" #'lsp-metals--execute-client-command)
                           ("metals/publishDecorations" #'lsp-metals--publish-decorations)
                           ("metals/treeViewDidChange" #'lsp-metals-treeview--did-change)
                           ("metals-model-refresh" #'lsp-metals--model-refresh)
                           ("metals/status" #'lsp-metals--status-string))
            :action-handlers (ht ("metals-debug-session-start" (-partial #'lsp-metals--debug-start :json-false))
                     ("metals-run-session-start" (-partial #'lsp-metals--debug-start t)))
            :server-id 'metals
            :remote? t
            :initialized-fn (lambda (workspace)
                      (lsp-metals--add-focus-hooks)
                      (with-lsp-workspace workspace
                    (lsp--set-configuration
                     (lsp-configuration-section "metals"))))
            :after-open-fn (lambda ()
                     (add-hook 'lsp-on-idle-hook #'lsp-metals--did-focus nil t))
            :completion-in-comments? t))```