Skip to content

Commit

Permalink
fix(lsp-rust): Library path on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Mar 28, 2024
1 parent 4b1b24a commit 3a0144e
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 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"))
(_ "~/"))))
`(,(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,7 +1257,6 @@ 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
Expand Down Expand Up @@ -1289,7 +1298,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 +1314,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 +1468,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 +1494,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 +1513,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

0 comments on commit 3a0144e

Please sign in to comment.