From 4c2af711481b47784ed95380ff9cfd856f32fa2f Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 11 Dec 2020 09:12:05 +0000 Subject: [PATCH 1/5] Add lsp-gunzip function to decompress gzipped files Also add decompress key to lsp-download-install so that dependencies can decompress themselves with lsp-unzip/lsp-gunzip --- lsp-mode.el | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/lsp-mode.el b/lsp-mode.el index 2ee2201a5b9..c635e475f3f 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -7192,19 +7192,32 @@ nil." ;; Download URL handling -(cl-defun lsp-download-install (callback error-callback &key url store-path &allow-other-keys) - (let ((url (lsp-resolve-value url)) - (store-path (lsp-resolve-value store-path))) +(cl-defun lsp-download-install (callback error-callback &key url store-path decompress &allow-other-keys) + (let* ((url (lsp-resolve-value url)) + (store-path (lsp-resolve-value store-path)) + ;; (decompress (lsp-resolve-value decompress)) + (download-path + (pcase decompress + (`gzip (concat store-path ".gz")) + (`zip (concat store-path ".zip")) + (`nil store-path) + (_ (error ":decompress must be `gzip', `zip' or `nil'"))))) (make-thread (lambda () (condition-case err (progn - (when (f-exists? store-path) - (f-delete store-path)) - (lsp--info "Starting to download %s to %s..." url store-path) - (mkdir (f-parent store-path) t) - (url-copy-file url store-path) - (lsp--info "Finished downloading %s..." store-path) + (when (f-exists? download-path) + (f-delete download-path)) + (lsp--info "Starting to download %s to %s..." url download-path) + (mkdir (f-parent download-path) t) + (url-copy-file url download-path) + (lsp--info "Finished downloading %s..." download-path) + (when decompress + (lsp--info "Decompressing %s..." download-path) + (pcase decompress + (`gzip (lsp-gunzip download-path)) + (`zip (lsp-unzip download-path store-path))) + (lsp--info "Decompressed %s..." store-path)) (funcall callback)) (error (funcall error-callback err))))))) @@ -7243,7 +7256,24 @@ STORE-PATH to make it executable." (unless lsp-unzip-script (error "Unable to find `unzip' or `powershell' on the path, please customize `lsp-unzip-script'")) (shell-command (format lsp-unzip-script zip-file dest))) + +;; gunzip + +(defconst lsp-ext-gunzip-script "gzip -d %1$s" + "Script to decompress a gzippped file with gzip.") + +(defcustom lsp-gunzip-script (cond ((executable-find "gzip") lsp-ext-gunzip-script) + (t nil)) + "The script to decompress a gzipped file. Should be a format string with one argument for the file to be decompressed in place." + :group 'lsp-mode + :type 'string + :package-version '(lsp-mode . "7.1")) +(defun lsp-gunzip (gz-file) + "Decompress file in place." + (unless lsp-gunzip-script + (error "Unable to find `gzip' on the path, please customize `lsp-gunzip-script'")) + (shell-command (format lsp-gunzip-script gz-file))) ;; VSCode marketplace From ac339507ada2bc029fd0f1b1d955124e2e8c9df9 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 11 Dec 2020 14:18:00 +0000 Subject: [PATCH 2/5] Use keyword symbol for decompress argument --- lsp-mode.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lsp-mode.el b/lsp-mode.el index c635e475f3f..9f06b0f8e67 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -7198,8 +7198,8 @@ nil." ;; (decompress (lsp-resolve-value decompress)) (download-path (pcase decompress - (`gzip (concat store-path ".gz")) - (`zip (concat store-path ".zip")) + (:gzip (concat store-path ".gz")) + (:zip (concat store-path ".zip")) (`nil store-path) (_ (error ":decompress must be `gzip', `zip' or `nil'"))))) (make-thread @@ -7215,8 +7215,8 @@ nil." (when decompress (lsp--info "Decompressing %s..." download-path) (pcase decompress - (`gzip (lsp-gunzip download-path)) - (`zip (lsp-unzip download-path store-path))) + (:gzip (lsp-gunzip download-path)) + (:zip (lsp-unzip download-path store-path))) (lsp--info "Decompressed %s..." store-path)) (funcall callback)) (error (funcall error-callback err))))))) From ad21b1dd217203f29ae397c4eebeae130111c435 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 11 Dec 2020 14:28:49 +0000 Subject: [PATCH 3/5] Fix whitespace and error message Co-authored-by: Nikita Bloshchanevich --- lsp-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lsp-mode.el b/lsp-mode.el index 9f06b0f8e67..b5626c8221e 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -7201,7 +7201,7 @@ nil." (:gzip (concat store-path ".gz")) (:zip (concat store-path ".zip")) (`nil store-path) - (_ (error ":decompress must be `gzip', `zip' or `nil'"))))) + (_ (error ":decompress must be `:gzip', `:zip' or `nil'"))))) (make-thread (lambda () (condition-case err From 1212611b2ede1a06897878e5590b68267db2478b Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 11 Dec 2020 14:30:52 +0000 Subject: [PATCH 4/5] Adjust whitespace Co-authored-by: Nikita Bloshchanevich --- lsp-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lsp-mode.el b/lsp-mode.el index b5626c8221e..6fc66a9fca9 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -7201,7 +7201,7 @@ nil." (:gzip (concat store-path ".gz")) (:zip (concat store-path ".zip")) (`nil store-path) - (_ (error ":decompress must be `:gzip', `:zip' or `nil'"))))) + (_ (error ":decompress must be `:gzip', `:zip' or `nil'"))))) (make-thread (lambda () (condition-case err From 7a9aad297bb566d33fbeae2ddb5232d5b01d3a65 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 11 Dec 2020 17:06:06 +0000 Subject: [PATCH 5/5] Alter lsp-gunzip error message --- lsp-mode.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lsp-mode.el b/lsp-mode.el index 6fc66a9fca9..253742b4c99 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -40,6 +40,7 @@ (require 'ht) (require 'imenu) (require 'inline) +(require 'jka-compr) (require 'json) (require 'lv) (require 'markdown-mode) @@ -7215,7 +7216,8 @@ nil." (when decompress (lsp--info "Decompressing %s..." download-path) (pcase decompress - (:gzip (lsp-gunzip download-path)) + (:gzip + (lsp-gunzip download-path)) (:zip (lsp-unzip download-path store-path))) (lsp--info "Decompressed %s..." store-path)) (funcall callback)) @@ -7272,7 +7274,7 @@ STORE-PATH to make it executable." (defun lsp-gunzip (gz-file) "Decompress file in place." (unless lsp-gunzip-script - (error "Unable to find `gzip' on the path, please customize `lsp-gunzip-script'")) + (error "Unable to find `gzip' on the path, please either customize `lsp-gunzip-script' or manually decompress %s" gz-file)) (shell-command (format lsp-gunzip-script gz-file))) ;; VSCode marketplace