From 85b7b6151b99aba90350b9c1bd13b7349f83b015 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 30 Jul 2024 00:48:42 -0400 Subject: [PATCH] fix(lsp): force lsp-zig-download-url-format to change Can't change the variable after lsp-zig loads because its used when it's loaded. Can't set it before lsp-zig loads because it's a constant (resetting its value). Thank god it uses a (non-inlined) function to build that URL, so we have an easy target to advise. Fix: #7970 Amend: 93dfb0acfbde Amend: bc5a8ec3fa67 Amend: 7bb5df4cd4ae --- modules/tools/lsp/+lsp.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/tools/lsp/+lsp.el b/modules/tools/lsp/+lsp.el index 3fbcebc6d..95abfd247 100644 --- a/modules/tools/lsp/+lsp.el +++ b/modules/tools/lsp/+lsp.el @@ -43,9 +43,20 @@ Can be a list of backends; accepts any value `company-backends' accepts.") (when (modulep! :config default +bindings) (setq lsp-keymap-prefix nil)) - ;; REVIEW: Remove when zigtools/zls#1879 is resolved. (unless (featurep :system 'windows) - (setq lsp-zig-download-url-format "https://github.com/zigtools/zls/releases/latest/download/zls-%s-%s.tar.xz")) + ;; HACK: Frustratingly enough, the value of `lsp-zig-download-url-format' is + ;; used immediately while the lsp-zig package is loading, so changing it + ;; *after* lsp-zig makes no difference. What's worse, the variable is a + ;; constant, so we can't change it *before* the package is loaded either! + ;; Thank god a (non-inlined) function is used to build the URL, so we have + ;; something to advise. + ;; REVIEW: Remove when zigtools/zls#1879 is resolved. + (defadvice! +lsp--use-correct-zls-download-url-a (fn &rest _) + "See zigtools/zls#1879." + :around #'lsp-zig--zls-url + (let ((lsp-zig-download-url-format + "https://github.com/zigtools/zls/releases/latest/download/zls-%s-%s.tar.xz")) + (apply fn args)))) :config (add-to-list 'doom-debug-variables 'lsp-log-io)