Skip to content

Commit 387e0e1

Browse files
committed
Add lsp-gunzip function to decompress gzipped files
Also add zip? and gzip? keys to lsp-download-install so that dependencies can decompress themselves.
1 parent dbe83b6 commit 387e0e1

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

lsp-mode.el

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7192,19 +7192,32 @@ nil."
71927192

71937193

71947194
;; 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)))
7195+
(cl-defun lsp-download-install (callback error-callback &key url store-path gzip? zip? &allow-other-keys)
7196+
(let* ((url (lsp-resolve-value url))
7197+
(gzip? (lsp-resolve-value gzip?))
7198+
(store-path (lsp-resolve-value store-path))
7199+
(download-path
7200+
(cond
7201+
(gzip? (concat store-path ".gz"))
7202+
(zip? (concat store-path ".zip"))
7203+
(t store-path))))
71987204
(make-thread
71997205
(lambda ()
72007206
(condition-case err
72017207
(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)
7208+
(when (f-exists? download-path)
7209+
(f-delete download-path))
7210+
(lsp--info "Starting to download %s to %s..." url download-path)
7211+
(mkdir (f-parent download-path) t)
7212+
(url-copy-file url download-path)
7213+
(lsp--info "Finished downloading %s..." download-path)
7214+
(when (or gzip? zip?)
7215+
(lsp--info "Decompressing %s..." download-path)
7216+
(when gzip?
7217+
(lsp-gunzip download-path))
7218+
(when zip?
7219+
(lsp-unzip download-path store-path))
7220+
(lsp--info "Decompressed %s..." store-path))
72087221
(funcall callback))
72097222
(error (funcall error-callback err)))))))
72107223

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

7272+
(defun lsp-gunzip (gz-file)
7273+
"Decompress file in place."
7274+
(unless lsp-gunzip-script
7275+
(error "Unable to find `gzip' on the path, please customize `lsp-gunzip-script'"))
7276+
(shell-command (format lsp-gunzip-script gz-file)))
72477277

72487278
;; VSCode marketplace
72497279

0 commit comments

Comments
 (0)