-
Notifications
You must be signed in to change notification settings - Fork 90
/
omnisharp-server-installation.el
128 lines (109 loc) · 6.08 KB
/
omnisharp-server-installation.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
;; -*- lexical-binding: t -*-
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(require 'gnutls)
(require 'dash)
(defun omnisharp--server-installation-dir ()
"Returns installation directory for automatic server installation."
(f-join omnisharp-cache-directory "server" (concat "v" omnisharp-expected-server-version)))
(defun omnisharp--server-installation-executable-name ()
(if (eq system-type 'windows-nt)
"OmniSharp.exe"
"run"))
(defun omnisharp--server-installation-path (&rest ok-if-missing)
"Returns path to installed omnisharp server binary, if any."
(let* ((executable-name (omnisharp--server-installation-executable-name))
(executable-path (f-join (omnisharp--server-installation-dir) executable-name)))
(if (or (f-exists-p executable-path) ok-if-missing)
executable-path
nil)))
(defun omnisharp--server-installation-download-and-extract (url filename reinstall)
"Downloads and extracts a tgz/zip into it's parent directory."
;; remove the file if reinstall is set
(if (and reinstall (f-exists-p filename))
(f-delete filename))
(unless (f-exists-p filename)
(message (format "omnisharp: downloading server binary from \"%s\"..." url))
(let ((gnutls-algorithm-priority
(if (and (not gnutls-algorithm-priority)
(boundp 'libgnutls-version)
(>= libgnutls-version 30603)
(version<= emacs-version "26.2"))
"NORMAL:-VERS-TLS1.3"
gnutls-algorithm-priority)))
(url-copy-file url filename t)))
(let ((target-dir (f-dirname filename)))
(message (format "omnisharp: extracting \"%s\" into \"%s\""
(f-filename filename)
target-dir))
(cond
((eq system-type 'windows-nt)
;; on windows, we attempt to use powershell v5+, available on Windows 10+
(let ((powershell-version (substring
(shell-command-to-string "powershell -command \"(Get-Host).Version.Major\"")
0 -1)))
(if (>= (string-to-number powershell-version) 5)
(call-process "powershell"
nil
nil
nil
"-command"
(concat "add-type -assembly system.io.compression.filesystem;"
"[io.compression.zipfile]::ExtractToDirectory(\"" filename "\", \"" target-dir "\")"))
(message (concat "omnisharp: for the 'M-x omnisharp-install-server' "
" command to work on Windows you need to have powershell v5+ installed")))))
((or (eq system-type 'gnu/linux)
(eq system-type 'darwin))
(call-process "tar" nil nil t "xf" filename "-C" target-dir))
(t (signal "omnisharp-install-server does not support platform %s (yet)" system-type)))))
(defun omnisharp--server-installation-tarball-name ()
"Resolves a tarball or zip file to use for this installation.
Note that due to a bug in emacs on Windows we currently use the x86/32bit version.
See https://github.com/OmniSharp/omnisharp-emacs/issues/315"
(cond ((eq system-type 'windows-nt) "omnisharp-win-x86.zip")
((eq system-type 'darwin) "omnisharp-osx.tar.gz")
((and (eq system-type 'gnu/linux)
(or (eq (string-match "^x86_64" system-configuration) 0)
(eq (string-match "^i[3-6]86" system-configuration) 0))) "omnisharp-linux-x64.tar.gz")
(t "omnisharp-mono.tar.gz")))
(defun omnisharp--install-server (reinstall &rest silent-installation)
"Implementation for autoloaded omnisharp-install-server in omnisharp.el.
REINSTALL can be set 't to force reinstallation.
SILENT-INSTALLATION value of 't means user is not involved."
(let* ((server-dir (omnisharp--server-installation-dir))
(distro-tarball (omnisharp--server-installation-tarball-name))
(distro-url (concat "https://github.com/OmniSharp/omnisharp-roslyn/releases/download"
"/v" omnisharp-expected-server-version
"/" distro-tarball))
(expected-executable-path (omnisharp--server-installation-path t)))
(if (or reinstall (not (f-exists-p expected-executable-path)))
(if (or silent-installation
(y-or-n-p (format "omnisharp: this will download and extract ~20-30 MB from \"%s\"; do you want to continue?"
distro-url)))
(progn
(message (format "omnisharp: attempting to download and install OmniSharp server into %s"
server-dir))
(omnisharp--mkdirp server-dir)
(omnisharp--server-installation-download-and-extract
distro-url
(f-join server-dir distro-tarball)
reinstall)
(let ((executable-path (omnisharp--server-installation-path)))
(if executable-path
(if (not silent-installation)
(message (format "omnisharp: server was installed as \"%s\"; you can now do M-x 'omnisharp-start-omnisharp-server' "
executable-path)))
(message (concat "omnisharp: server could not be installed automatically. "
"Please check https://github.com/OmniSharp/omnisharp-emacs/blob/master/doc/server-installation.md for instructions."))))))
(if (not silent-installation)
(message (format "omnisharp: server is already installed (%s)"
expected-executable-path))))))
(provide 'omnisharp-server-installation)