Skip to content

Commit 261b8bc

Browse files
lukel97nbfalcon
andauthored
Add lsp-gunzip function to decompress gzipped files (#2400)
* 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 * Use keyword symbol for decompress argument * Fix whitespace and error message Co-authored-by: Nikita Bloshchanevich <[email protected]> * Adjust whitespace Co-authored-by: Nikita Bloshchanevich <[email protected]> * Alter lsp-gunzip error message Co-authored-by: Nikita Bloshchanevich <[email protected]>
1 parent dbe83b6 commit 261b8bc

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

lsp-mode.el

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
(require 'ht)
4141
(require 'imenu)
4242
(require 'inline)
43+
(require 'jka-compr)
4344
(require 'json)
4445
(require 'lv)
4546
(require 'markdown-mode)
@@ -7192,19 +7193,33 @@ nil."
71927193

71937194

71947195
;; Download URL handling
7195-
(cl-defun lsp-download-install (callback error-callback &key url store-path &allow-other-keys)
7196-
(let ((url (lsp-resolve-value url))
7197-
(store-path (lsp-resolve-value store-path)))
7196+
(cl-defun lsp-download-install (callback error-callback &key url store-path decompress &allow-other-keys)
7197+
(let* ((url (lsp-resolve-value url))
7198+
(store-path (lsp-resolve-value store-path))
7199+
;; (decompress (lsp-resolve-value decompress))
7200+
(download-path
7201+
(pcase decompress
7202+
(:gzip (concat store-path ".gz"))
7203+
(:zip (concat store-path ".zip"))
7204+
(`nil store-path)
7205+
(_ (error ":decompress must be `:gzip', `:zip' or `nil'")))))
71987206
(make-thread
71997207
(lambda ()
72007208
(condition-case err
72017209
(progn
7202-
(when (f-exists? store-path)
7203-
(f-delete store-path))
7204-
(lsp--info "Starting to download %s to %s..." url store-path)
7205-
(mkdir (f-parent store-path) t)
7206-
(url-copy-file url store-path)
7207-
(lsp--info "Finished downloading %s..." store-path)
7210+
(when (f-exists? download-path)
7211+
(f-delete download-path))
7212+
(lsp--info "Starting to download %s to %s..." url download-path)
7213+
(mkdir (f-parent download-path) t)
7214+
(url-copy-file url download-path)
7215+
(lsp--info "Finished downloading %s..." download-path)
7216+
(when decompress
7217+
(lsp--info "Decompressing %s..." download-path)
7218+
(pcase decompress
7219+
(:gzip
7220+
(lsp-gunzip download-path))
7221+
(:zip (lsp-unzip download-path store-path)))
7222+
(lsp--info "Decompressed %s..." store-path))
72087223
(funcall callback))
72097224
(error (funcall error-callback err)))))))
72107225

@@ -7243,7 +7258,24 @@ STORE-PATH to make it executable."
72437258
(unless lsp-unzip-script
72447259
(error "Unable to find `unzip' or `powershell' on the path, please customize `lsp-unzip-script'"))
72457260
(shell-command (format lsp-unzip-script zip-file dest)))
7261+
7262+
;; gunzip
7263+
7264+
(defconst lsp-ext-gunzip-script "gzip -d %1$s"
7265+
"Script to decompress a gzippped file with gzip.")
7266+
7267+
(defcustom lsp-gunzip-script (cond ((executable-find "gzip") lsp-ext-gunzip-script)
7268+
(t nil))
7269+
"The script to decompress a gzipped file. Should be a format string with one argument for the file to be decompressed in place."
7270+
:group 'lsp-mode
7271+
:type 'string
7272+
:package-version '(lsp-mode . "7.1"))
72467273

7274+
(defun lsp-gunzip (gz-file)
7275+
"Decompress file in place."
7276+
(unless lsp-gunzip-script
7277+
(error "Unable to find `gzip' on the path, please either customize `lsp-gunzip-script' or manually decompress %s" gz-file))
7278+
(shell-command (format lsp-gunzip-script gz-file)))
72477279

72487280
;; VSCode marketplace
72497281

0 commit comments

Comments
 (0)