From 3a0144e2f53a0238caa957db841834eb9eac259c Mon Sep 17 00:00:00 2001 From: JenChieh Date: Thu, 28 Mar 2024 00:15:24 -0700 Subject: [PATCH 1/3] fix(lsp-rust): Library path on Windows --- clients/lsp-rust.el | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/clients/lsp-rust.el b/clients/lsp-rust.el index 7ee3de9178..ba3b0ed8d6 100644 --- a/clients/lsp-rust.el +++ b/clients/lsp-rust.el @@ -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) @@ -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) @@ -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 @@ -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) @@ -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. @@ -1457,10 +1468,14 @@ 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 @@ -1468,6 +1483,7 @@ such as imports and dyn traits." :position? (lsp--cur-position))))) (defun lsp-rust-analyzer--select-runnable () + "Select runnable." (lsp--completing-read "Select runnable:" (if lsp-rust-analyzer--last-runnable @@ -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. @@ -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))) From 9e85b75204ab00fff64717fb58f2a4dea39cd4e8 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Thu, 28 Mar 2024 00:16:53 -0700 Subject: [PATCH 2/3] align alist --- clients/lsp-rust.el | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/clients/lsp-rust.el b/clients/lsp-rust.el index ba3b0ed8d6..15fcf5e5c5 100644 --- a/clients/lsp-rust.el +++ b/clients/lsp-rust.el @@ -1261,30 +1261,29 @@ other commands within the workspace. Useful for setting RUSTFLAGS." "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." From 11b3aa649c5deadcf65998bba43bd9e0a2fc6db4 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Thu, 28 Mar 2024 10:56:12 -0700 Subject: [PATCH 3/3] Revert fix --- clients/lsp-rust.el | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/clients/lsp-rust.el b/clients/lsp-rust.el index 15fcf5e5c5..5f4c19bf46 100644 --- a/clients/lsp-rust.el +++ b/clients/lsp-rust.el @@ -69,11 +69,7 @@ :package-version '(lsp-mode . "6.1")) (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))) + '("~/.cargo/registry/src" "~/.rustup/toolchains") "List of directories which will be considered to be libraries." :risky t :type '(repeat string) @@ -356,11 +352,7 @@ PARAMS progress report notification data." :package-version '(lsp-mode . "6.2")) (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))) + '("~/.cargo/registry/src" "~/.rustup/toolchains") "List of directories which will be considered to be libraries." :risky t :type '(repeat string)