From 2c5ddff5a434d0ac059708024f84514dc5a7faa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20Menkevi=C4=8Dius?= Date: Sun, 7 Apr 2019 11:26:17 +0300 Subject: [PATCH 1/3] omnisharp: drop support for specifying sln when starting the server Newer omnisharp-roslyn server versions ignore the sln paramater and start to parse project files at cwd. This makes for a more seamless experience and hopefully does not break too many things. --- omnisharp-server-actions.el | 20 ++++++-------- omnisharp-server-management.el | 49 ++++++++++++++-------------------- omnisharp-utils.el | 25 +---------------- 3 files changed, 29 insertions(+), 65 deletions(-) diff --git a/omnisharp-server-actions.el b/omnisharp-server-actions.el index 574ad324..e19c08ed 100644 --- a/omnisharp-server-actions.el +++ b/omnisharp-server-actions.el @@ -19,20 +19,16 @@ Will query user for a path to project/solution file to start the server with." (let ((server-executable-path (omnisharp--resolve-omnisharp-server-executable-path)) - (project-file-candidates (omnisharp--resolve-sln-candidates))) + (project-root (omnisharp--project-root))) (if server-executable-path (if (and (not no-autodetect) - project-file-candidates) - (omnisharp--do-server-start (completing-read "Omnisharp - Start Server" - project-file-candidates - nil - t)) - (let ((path-to-project (read-file-name - "Start OmniSharp for project folder or solution file: "))) - (if (file-exists-p path-to-project) - (omnisharp--do-server-start path-to-project) - (error (format "Path does not lead to a valid project directory or solution file path: %s" - path-to-project)))))))) + project-root + (file-directory-p project-root)) + (omnisharp--do-server-start project-root) + (let ((project-root (read-directory-name "Project root to use with OmniSharp: "))) + (if (file-directory-p project-root) + (omnisharp--do-server-start project-root) + (error (format "Path does not lead to a directory: %s" project-root)))))))) (defun omnisharp--stop-server () "Actual implementation for autoloaded omnisharp-stop-server" diff --git a/omnisharp-server-management.el b/omnisharp-server-management.el index 299a67f2..9a7d08a3 100644 --- a/omnisharp-server-management.el +++ b/omnisharp-server-management.el @@ -63,20 +63,18 @@ to use server installed via `omnisharp-install-server`. " as detailed in https://github.com/OmniSharp/omnisharp-emacs/blob/master/doc/server-installation.md")) nil))))) -(defun omnisharp--do-server-start (path-to-project) +(defun omnisharp--do-server-start (project-root) (let ((server-executable-path (omnisharp--resolve-omnisharp-server-executable-path))) - (message (format "omnisharp: starting server using project folder/solution file: \"%s\"" - path-to-project)) + (message (format "omnisharp: starting server on project root: \"%s\"" project-root)) (omnisharp--log-reset) - (omnisharp--log (format "starting server using project folder/solution path \"%s\"" - path-to-project)) + (omnisharp--log (format "starting server on project root \"%s\"" project-root)) (omnisharp--log (format "Using server binary on %s" server-executable-path)) ;; Save all csharp buffers to ensure the server is in sync" (save-some-buffers t (lambda () (string-equal (file-name-extension (buffer-file-name)) "cs"))) - (setq omnisharp--last-project-path path-to-project) + (setq omnisharp--last-project-path project-root) ;; this can be set by omnisharp-reload-solution to t (setq omnisharp--restart-server-on-stop nil) @@ -85,12 +83,13 @@ to use server installed via `omnisharp-install-server`. (make-omnisharp--server-info ;; use a pipe for the connection instead of a pty (let* ((process-connection-type nil) + (default-directory (omnisharp--path-to-server (expand-file-name project-root))) (omnisharp-process (start-process - "OmniServer" ; process name - "OmniServer" ; buffer name - server-executable-path - "--encoding" "utf-8" - "--stdio" "-s" (omnisharp--path-to-server (expand-file-name path-to-project))))) + "OmniServer" ; process name + "OmniServer" ; buffer name + server-executable-path + "--encoding" "utf-8" + "--stdio"))) (buffer-disable-undo (process-buffer omnisharp-process)) (set-process-filter omnisharp-process 'omnisharp--handle-server-message) (set-process-sentinel omnisharp-process @@ -101,7 +100,7 @@ to use server installed via `omnisharp-install-server`. (if omnisharp--restart-server-on-stop (omnisharp--do-server-start omnisharp--last-project-path))))) omnisharp-process) - path-to-project)))) + project-root)))) (defun omnisharp--clear-response-handlers () "For development time cleaning up impossible states of response @@ -356,26 +355,18 @@ and attempts to start it if it is not." (unless (or (omnisharp--buffer-contains-metadata) (not (buffer-file-name))) - (let* ((filename (buffer-file-name)) + (let* ((project-root (omnisharp--project-root)) (server-project-root (if omnisharp--server-info (cdr (assoc :project-root omnisharp--server-info)) nil)) + (filename (buffer-file-name)) (filename-in-scope (and server-project-root (f-same-p (f-common-parent (list filename server-project-root)) - server-project-root))) - (project-path-candidates (omnisharp--resolve-sln-candidates)) - (project-path-candidates-sln (-filter (lambda (filename) (string= (f-ext filename) "sln")) - project-path-candidates)) - (project-path (cond ((= (length project-path-candidates) 1) (car project-path-candidates)) - ((= (length project-path-candidates-sln) 1) (car project-path-candidates-sln))))) - (cond ((and (not server-project-root) project-path) - (omnisharp--do-server-start project-path)) - - ((and (not server-project-root) (not (= (length project-path-candidates) 1))) - (message (concat "omnisharp: no unambigious project path could be found" - " to start OmniSharp server for this buffer automatically")) - (unless (= (length project-path-candidates) 0) - (message (concat "omnisharp: project path candidates are: " - (s-join ", " project-path-candidates))) - (message "omnisharp: start the server manually with M-x omnisharp-start-omnisharp-server"))) + server-project-root)))) + (cond ((and (not server-project-root) project-root) + (omnisharp--do-server-start project-root)) + + ((and (not server-project-root) (not project-root)) + (message (concat "omnisharp: no project root could be found to start omnisharp server for this buffer automatically")) + (message "omnisharp: start the server manually with M-x omnisharp-start-omnisharp-server or make sure project root is discoverable by projectile")) ((and server-project-root (not filename-in-scope)) (message (format (concat "omnisharp: buffer will not be managed by omnisharp: " diff --git a/omnisharp-utils.el b/omnisharp-utils.el index ffeec03a..490f84e4 100644 --- a/omnisharp-utils.el +++ b/omnisharp-utils.el @@ -341,32 +341,9 @@ was found. Uses projectile for the job." ;; use project root as a candidate (if we have projectile available) (if (require 'projectile nil 'noerror) (condition-case nil - (let ((project-root (projectile-project-root))) - (if (not (string= project-root default-directory)) - project-root)) + (projectile-project-root) (error nil)))) -(defun omnisharp--resolve-sln-candidates () - "Resolves a list of .sln file candidates and directories to be used -for starting a server based on the current buffer." - (let ((dir (file-name-directory (or buffer-file-name ""))) - (candidates nil) - (project-root (omnisharp--project-root))) - (while (and dir (not (f-root-p dir))) - (if (not (file-remote-p dir)) - (setq candidates (append candidates - (f-files dir (lambda (filename) - (string-match-p "\\.sln$" filename)))))) - (setq dir (f-parent dir))) - - (setq candidates (reverse candidates)) - - ;; use project root as a candidate (if we have projectile available) - (if project-root - (setq candidates (append candidates (list project-root)))) - - candidates)) - (defun omnisharp--buffer-contains-metadata() "Returns t if buffer is omnisharp metadata buffer." (or (boundp 'omnisharp--metadata-source) From 32c2378b04afffb8c9d366e5da47fefa4b13eb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20Menkevi=C4=8Dius?= Date: Wed, 27 Mar 2019 10:54:05 +0200 Subject: [PATCH 2/3] omnisharp-settings.el: upgrade expected server version to 1.32.13 --- omnisharp-settings.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omnisharp-settings.el b/omnisharp-settings.el index 0ca978dd..1ddb3063 100644 --- a/omnisharp-settings.el +++ b/omnisharp-settings.el @@ -91,7 +91,7 @@ Otherwise omnisharp request the user to do M-x `omnisharp-install-server` and th executable will be used instead." :type '(choice (const :tag "Not Set" nil) string)) -(defcustom omnisharp-expected-server-version "1.32.6" +(defcustom omnisharp-expected-server-version "1.32.13" "Version of the omnisharp-roslyn server that this omnisharp-emacs package is built for. Also used to select version for automatic server installation." :group 'omnisharp From 71ac0591083105063ebbdb4bd03291e9a9a34d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20Menkevi=C4=8Dius?= Date: Mon, 22 Apr 2019 10:29:06 +0300 Subject: [PATCH 3/3] omnisharp-settings.el: update omnisharp-expected-server-version to 1.32.18 --- omnisharp-settings.el | 2 +- test/buttercup-tests/navigation/go-to-definition-test.el | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/omnisharp-settings.el b/omnisharp-settings.el index 1ddb3063..41ef0148 100644 --- a/omnisharp-settings.el +++ b/omnisharp-settings.el @@ -91,7 +91,7 @@ Otherwise omnisharp request the user to do M-x `omnisharp-install-server` and th executable will be used instead." :type '(choice (const :tag "Not Set" nil) string)) -(defcustom omnisharp-expected-server-version "1.32.13" +(defcustom omnisharp-expected-server-version "1.32.18" "Version of the omnisharp-roslyn server that this omnisharp-emacs package is built for. Also used to select version for automatic server installation." :group 'omnisharp diff --git a/test/buttercup-tests/navigation/go-to-definition-test.el b/test/buttercup-tests/navigation/go-to-definition-test.el index 03af291b..9269d719 100644 --- a/test/buttercup-tests/navigation/go-to-definition-test.el +++ b/test/buttercup-tests/navigation/go-to-definition-test.el @@ -79,5 +79,5 @@ ;; TODO: for some reason I need to set current buffer from window list ;; with with-current-buffer.. (with-current-buffer (car (mapcar #'window-buffer (window-list))) - (ot--i-should-be-in-buffer-name "*omnisharp-metadata:MiscellaneousFiles.csproj:mscorlib:System.String*") + (ot--i-should-be-in-buffer-name "*omnisharp-metadata:MinimalProject:netstandard:System.String*") (ot--point-should-be-on-a-line-containing "public sealed class String"))))