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

style(lsp-rust): Mnior clean up #4398

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Changes from 2 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
77 changes: 45 additions & 32 deletions clients/lsp-rust.el
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@
:group 'lsp-rust-rls
:package-version '(lsp-mode . "6.1"))

(defcustom lsp-rust-library-directories '("~/.cargo/registry/src" "~/.rustup/toolchains")
(defcustom lsp-rust-library-directories
(let ((home-dir (pcase system-type
('windows-nt (getenv "USERPROFILE"))
Copy link
Member

Choose a reason for hiding this comment

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

The ~ should expand to %USERPROFILE% under windows, why do we need this change? Just to expand the path?

Copy link
Member Author

@jcs090218 jcs090218 Mar 28, 2024

Choose a reason for hiding this comment

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

You are right. Sorry for the noisy. 😓

I've reverted!

(_ "~/"))))
`(,(expand-file-name ".cargo/registry/src" home-dir)
,(expand-file-name ".rustup/toolchains" home-dir)))
"List of directories which will be considered to be libraries."
:risky t
:type '(repeat string)
Expand Down Expand Up @@ -350,7 +355,12 @@ PARAMS progress report notification data."
:group 'lsp-rust-analyzer
:package-version '(lsp-mode . "6.2"))

(defcustom lsp-rust-analyzer-library-directories '("~/.cargo/registry/src" "~/.rustup/toolchains")
(defcustom lsp-rust-analyzer-library-directories
(let ((home-dir (pcase system-type
('windows-nt (getenv "USERPROFILE"))
(_ "~/"))))
`(,(expand-file-name ".cargo/registry/src" home-dir)
,(expand-file-name ".rustup/toolchains" home-dir)))
"List of directories which will be considered to be libraries."
:risky t
:type '(repeat string)
Expand Down Expand Up @@ -1247,35 +1257,33 @@ other commands within the workspace. Useful for setting RUSTFLAGS."

;; ---------------------------------------------------------------------


(defun lsp-rust-analyzer--semantic-modifiers ()
"Mapping between rust-analyzer keywords and fonts to apply.
The keywords are sent in the initialize response, in the semantic
tokens legend."
`(
("documentation" . ,lsp-rust-analyzer-documentation-modifier)
("declaration" . ,lsp-rust-analyzer-declaration-modifier)
("definition" . ,lsp-rust-analyzer-definition-modifier)
("static" . ,lsp-rust-analyzer-static-modifier)
("abstract" . ,lsp-rust-analyzer-abstract-modifier)
("deprecated" . ,lsp-rust-analyzer-deprecated-modifier)
("readonly" . ,lsp-rust-analyzer-readonly-modifier)
`(("documentation" . ,lsp-rust-analyzer-documentation-modifier)
("declaration" . ,lsp-rust-analyzer-declaration-modifier)
("definition" . ,lsp-rust-analyzer-definition-modifier)
("static" . ,lsp-rust-analyzer-static-modifier)
("abstract" . ,lsp-rust-analyzer-abstract-modifier)
("deprecated" . ,lsp-rust-analyzer-deprecated-modifier)
("readonly" . ,lsp-rust-analyzer-readonly-modifier)
("default_library" . ,lsp-rust-analyzer-default-library-modifier)
("async" . ,lsp-rust-analyzer-async-modifier)
("attribute" . ,lsp-rust-analyzer-attribute-modifier)
("callable" . ,lsp-rust-analyzer-callable-modifier)
("constant" . ,lsp-rust-analyzer-constant-modifier)
("consuming" . ,lsp-rust-analyzer-consuming-modifier)
("control_flow" . ,lsp-rust-analyzer-control-flow-modifier)
("crate_root" . ,lsp-rust-analyzer-crate-root-modifier)
("injected" . ,lsp-rust-analyzer-injected-modifier)
("intra_doc_link" . ,lsp-rust-analyzer-intra-doc-link-modifier)
("library" . ,lsp-rust-analyzer-library-modifier)
("mutable" . ,lsp-rust-analyzer-mutable-modifier)
("public" . ,lsp-rust-analyzer-public-modifier)
("reference" . ,lsp-rust-analyzer-reference-modifier)
("trait" . ,lsp-rust-analyzer-trait-modifier)
("unsafe" . ,lsp-rust-analyzer-unsafe-modifier)))
("async" . ,lsp-rust-analyzer-async-modifier)
("attribute" . ,lsp-rust-analyzer-attribute-modifier)
("callable" . ,lsp-rust-analyzer-callable-modifier)
("constant" . ,lsp-rust-analyzer-constant-modifier)
("consuming" . ,lsp-rust-analyzer-consuming-modifier)
("control_flow" . ,lsp-rust-analyzer-control-flow-modifier)
("crate_root" . ,lsp-rust-analyzer-crate-root-modifier)
("injected" . ,lsp-rust-analyzer-injected-modifier)
("intra_doc_link" . ,lsp-rust-analyzer-intra-doc-link-modifier)
("library" . ,lsp-rust-analyzer-library-modifier)
("mutable" . ,lsp-rust-analyzer-mutable-modifier)
("public" . ,lsp-rust-analyzer-public-modifier)
("reference" . ,lsp-rust-analyzer-reference-modifier)
("trait" . ,lsp-rust-analyzer-trait-modifier)
("unsafe" . ,lsp-rust-analyzer-unsafe-modifier)))

(defun lsp-rust-switch-server (&optional lsp-server)
"Switch priorities of lsp servers, unless LSP-SERVER is already active."
Expand All @@ -1289,7 +1297,8 @@ tokens legend."
(* (lsp--client-priority (gethash server lsp-clients)) -1)))
(message (format "Switched to server %s." server)))))))

;; inlay hints
;;
;;; Inlay hints

(defcustom lsp-rust-analyzer-debug-lens-extra-dap-args
'(:MIMode "gdb" :miDebuggerPath "gdb" :stopAtEntry t :externalConsole :json-false)
Expand All @@ -1304,7 +1313,8 @@ meaning."
:group 'lsp-rust-analyzer
:package-version '(lsp-mode . "8.0.0"))

;; lenses
;;
;;; Lenses

(defgroup lsp-rust-analyzer-lens nil
"LSP lens support for Rust when using rust-analyzer.
Expand Down Expand Up @@ -1457,17 +1467,22 @@ such as imports and dyn traits."
(special-mode)))
(pop-to-buffer buf)))

;; runnables
(defvar lsp-rust-analyzer--last-runnable nil)
;;
;;; Runnables

(defvar lsp-rust-analyzer--last-runnable nil
"Record the last runnable.")

(defun lsp-rust-analyzer--runnables ()
"Return list of runnables."
(lsp-send-request (lsp-make-request
"experimental/runnables"
(lsp-make-rust-analyzer-runnables-params
:text-document (lsp--text-document-identifier)
:position? (lsp--cur-position)))))

(defun lsp-rust-analyzer--select-runnable ()
"Select runnable."
(lsp--completing-read
"Select runnable:"
(if lsp-rust-analyzer--last-runnable
Expand All @@ -1478,7 +1493,6 @@ such as imports and dyn traits."
(lsp-rust-analyzer--runnables))
(-lambda ((&rust-analyzer:Runnable :label)) label)))


(defun lsp-rust-analyzer--common-runner (runnable)
"Execute a given RUNNABLE.

Expand All @@ -1498,7 +1512,6 @@ and run a compilation"
(if (functionp 'cargo-process-mode) 'cargo-process-mode nil)
(lambda (_) (concat "*" label "*"))))))


(defun lsp-rust-analyzer-run (runnable)
"Select and run a RUNNABLE action."
(interactive (list (lsp-rust-analyzer--select-runnable)))
Expand Down
Loading