Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No sln file selection anymore #476

Merged
merged 3 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions omnisharp-server-actions.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
49 changes: 20 additions & 29 deletions omnisharp-server-management.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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: "
Expand Down
2 changes: 1 addition & 1 deletion omnisharp-settings.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.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
Expand Down
25 changes: 1 addition & 24 deletions omnisharp-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/buttercup-tests/navigation/go-to-definition-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"))))