From 04580383f5415f8379113ecef133e6f04ad8eeee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20Menkevi=C4=8Dius?= Date: Sun, 16 Jul 2017 18:46:36 +0300 Subject: [PATCH 1/2] omnisharp-utils.el: fix omnisharp-mkdirp-item for windows paths --- omnisharp-utils.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omnisharp-utils.el b/omnisharp-utils.el index 01357708..c8a6e9be 100644 --- a/omnisharp-utils.el +++ b/omnisharp-utils.el @@ -299,7 +299,7 @@ the developer's emacs unusable." "Makes a directory recursively, similarly to a 'mkdir -p'." (let* ((absolute-dir (expand-file-name dir)) (components (f-split absolute-dir))) - (omnisharp--mkdirp-item (f-join (apply #'concat (-take 2 components))) (-drop 2 components)) + (omnisharp--mkdirp-item (f-join (apply #'concat (-take 1 components))) (-drop 1 components)) absolute-dir)) (defun omnisharp--mkdirp-item (dir remaining) From f652f1fe0474676af746f0c8ac9dfd41cd784aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20Menkevi=C4=8Dius?= Date: Sun, 16 Jul 2017 18:47:14 +0300 Subject: [PATCH 2/2] omnisharp-install-server: implementation for windows note, that this requires powershell v5+ to be installed (windows 10+) --- omnisharp-server-installation.el | 60 +++++++++++++++++++++++++------- omnisharp.el | 7 +--- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/omnisharp-server-installation.el b/omnisharp-server-installation.el index ea05366e..168f2fd1 100644 --- a/omnisharp-server-installation.el +++ b/omnisharp-server-installation.el @@ -10,16 +10,21 @@ is built for. Also used to select version for automatic server installation." "Returns installation directory for automatic server installation." (f-join (expand-file-name "~") ".emacs.d" ".cache" "omnisharp" "server" (concat "v" omnisharp-expected-server-version))) +(defun omnisharp--server-installation-executable-name () + (if (eq system-type 'windows-nt) + "OmniSharp.exe" + "omnisharp")) + (defun omnisharp--server-installation-path (&rest ok-if-missing) "Returns path to installed omnisharp server binary, if any." - (let* ((executable-name "omnisharp") ;; TODO: platform dependant + (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 binary into given directory." + "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)) @@ -29,20 +34,50 @@ is built for. Also used to select version for automatic server installation." (message (format "omnisharp: downloading server binary from \"%s\"..." url)) (url-copy-file url filename t)) - (message (format "omnisharp: extracting into %s" (f-dirname filename))) - (call-process "tar" nil nil t "xf" filename "-C" (f-dirname filename))) + (let ((target-dir (f-dirname filename))) + (message (format "omnisharp: extracting \"%s\" into \"%s\"" + (f-filename filename) + target-dir)) -(defun omnisharp--server-installation-prepare-wrapper-script (filename server-dir) - (unless (f-exists-p filename) - (f-write (format "#!/usr/bin/env bash\nmono %s $@\n" (f-join server-dir "OmniSharp.exe")) - 'utf-8 - (f-join server-dir filename)) - (call-process "chmod" nil nil nil "0755" (f-join server-dir filename)))) + (if (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")))) + (progn + (call-process "tar" nil nil t "xf" filename "-C" target-dir) + + ;; setup wrapper script on unix platforms + (let ((server-exe (omnisharp--server-installation-executable-name))) + (unless (f-exists-p server-exe) + (f-write (format "#!/usr/bin/env bash\nmono %s $@\n" (f-join target-dir "OmniSharp.exe")) + 'utf-8 + (f-join target-dir server-exe)) + (set-file-modes (f-join target-dir server-exe) #o755))))))) + +(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" + (if (eq system-type 'windows-nt) + "omnisharp-win-x86-net46.zip" + "omnisharp-mono.tar.gz")) (defun omnisharp--install-server (reinstall) "Implementation for autoloaded omnisharp-install-server in omnisharp.el." (let* ((server-dir (omnisharp--server-installation-dir)) - (distro-tarball "omnisharp-mono.tar.gz") ;; TODO: platform specific + (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)) @@ -58,12 +93,11 @@ is built for. Also used to select version for automatic server installation." distro-url (f-join server-dir distro-tarball) reinstall) - (omnisharp--server-installation-prepare-wrapper-script "omnisharp" server-dir) (let ((executable-path (omnisharp--server-installation-path))) (if executable-path (message (format "omnisharp: server was installed to \"%s\"; you can now do M-x 'omnisharp-start-omnisharp-server' " executable-path)) - (message (concat "omnisharp: server could not be installed automatically." + (message (concat "omnisharp: server could not be installed automatically. " "Please check https://github.com/OmniSharp/omnisharp-emacs/blob/master/README.md#installation-of-the-omnisharp-roslyn-server-application for instructions.")))))) (message (format "omnisharp: server is already installed (%s)" expected-executable-path))))) diff --git a/omnisharp.el b/omnisharp.el index aa6dc57b..ba6184f5 100644 --- a/omnisharp.el +++ b/omnisharp.el @@ -117,12 +117,7 @@ finished loading the solution." (defun omnisharp-install-server (reinstall) "Installs OmniSharp server locally into ~/.emacs/cache/omnisharp/server/$(version)" (interactive "P") - (if (or (eq system-type 'darwin) - (eq system-type 'gnu/linux)) - (omnisharp--install-server reinstall) - (message (format (concat "omnisharp: sorry, omnisharp-install-server does not support %s yet," - " please see https://github.com/OmniSharp/omnisharp-emacs/blob/master/README.md#installation-of-the-omnisharp-roslyn-server-application") - system-type)))) + (omnisharp--install-server reinstall)) ;;;###autoload (defun company-omnisharp (command &optional arg &rest ignored)