Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions rustic-lsp.el
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ in, e.g. your home directory."
:type 'boolean
:group 'rustic)

(defcustom rustic-lsp-check-command "check"
"Command for computing diagnostics on save."
:type 'string
:group 'rustic)

;;; Common

(defun rustic-setup-lsp ()
Expand All @@ -74,6 +79,7 @@ in, e.g. your home directory."

(defvar lsp-rust-analyzer-macro-expansion-method)
(defvar lsp-rust-analyzer-server-command)
(defvar lsp-rust-analyzer-cargo-watch-command)
(defvar lsp-rust-server)
(declare-function lsp "lsp-mode" (&optional arg))
(declare-function lsp-rust-switch-server "lsp-rust" (lsp-server))
Expand All @@ -89,6 +95,7 @@ with `lsp-rust-switch-server'."
;; (lsp-workspace-folders-add (rustic-buffer-workspace))
(setq lsp-rust-server rustic-lsp-server)
(setq lsp-rust-analyzer-server-command rustic-analyzer-command)
(setq lsp-rust-analyzer-cargo-watch-command rustic-lsp-check-command)
(lsp-rust-switch-server rustic-lsp-server))

(defun rustic-install-lsp-client-p (lsp-client)
Expand Down Expand Up @@ -129,14 +136,19 @@ with `lsp-rust-switch-server'."
(defclass eglot-rust-analyzer (eglot-lsp-server) ()
:documentation "Rust-analyzer LSP server.")

(cl-defmethod eglot-initialization-options ((server eglot-rust-analyzer))
"Pass `detachedFiles' when `rustic-enable-detached-file-support' is non-`nil'."
(if (or (null rustic-enable-detached-file-support)
(null buffer-file-name)
(rustic-buffer-crate t))
eglot--{}
(list :detachedFiles
(vector (file-local-name (file-truename buffer-file-name))))))
(cl-defmethod eglot-initialization-options ((_server eglot-rust-analyzer))
"Pass `detachedFiles' when `rustic-enable-detached-file-support' is non-`nil'.

Also pass the value `rustic-lsp-check-command' as the check.command
option."
(append
(and rustic-enable-detached-file-support
buffer-file-name
(null (rustic-buffer-crate t))
(list :detachedFiles
(vector (file-local-name (file-truename buffer-file-name)))))
(list :check
(list :command rustic-lsp-check-command))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not use eglot. What the purpose of this change? in the previous code, if the conditions don't match we will just return the empty object. However in the revised version we will always return the :check object. Is that intended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is intentional. The :check field specifies the checker command to use. I've made the defcustom's default be the same as rust-analyzers so users shouldn't see any behavior change with this


(rustic-setup-eglot))

Expand Down
Loading