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

Drop support for specifying solution file manually #474

Closed
wants to merge 8 commits into from
Closed
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
13 changes: 6 additions & 7 deletions Dockerfile.testing
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
FROM microsoft/dotnet:1.1.2-sdk
FROM mono:5.18

WORKDIR /usr/src

# Install dependencies
RUN apt-get update \
&& apt-get install -y git emacs24-nox wget curl make \
&& apt-get install -y git emacs24-nox curl make python \
&& rm -rf /var/lib/apt/lists/*

# Install sample project's dependencies
COPY test/MinimalProject test/MinimalProject
RUN (cd ./test/MinimalProject && nuget restore MinimalProject.csproj && msbuild MinimalProject.csproj)

# Install Cask
RUN curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python
ENV PATH /root/.cask/bin:$PATH

# Install sample project's dependencies
COPY test/MinimalProject test/MinimalProject
RUN (cd ./test/MinimalProject && dotnet restore)

# Install omnisharp and it's dependency packages via Cask
COPY Cask Cask
COPY omnisharp*.el ./
Expand Down
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
50 changes: 21 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,14 @@ 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"
(if omnisharp-debug "--verbose" ""))))
(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 +101,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 +356,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.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
Expand Down
30 changes: 6 additions & 24 deletions omnisharp-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ the OmniSharp server understands."

(defun omnisharp--log (single-or-multiline-log-string)
"Writes message to the log."
(when omnisharp-debug
(message (concat "*omnisharp-log*: "
(format-time-string "[%H:%M:%S] ")
single-or-multiline-log-string)))

(let ((log-buffer (get-buffer-create "*omnisharp-log*")))
(save-window-excursion
(with-current-buffer log-buffer
Expand Down Expand Up @@ -336,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
14 changes: 0 additions & 14 deletions test-stuff/run-integration-tests.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
#!/bin/bash

echo "'dotnet --version' reports:" $(dotnet --version)

if [[ $(dotnet --version) != "1.1"* ]]; then
echo "Must install the .NET CLI 1.1.* http://dotnet.github.io/"
exit 1
fi

if [[ ! -r test/MinimalProject/project.lock.json ]]; then
echo "Restoring MinimalProject packages"
pushd test/MinimalProject
dotnet restore
popd
fi

TERM=dumb SHELL=sh cask exec emacs \
-Q \
-batch \
Expand Down
7 changes: 1 addition & 6 deletions test/MinimalProject/MinimalProject.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<AssemblyName>MinimalProject</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>MinimalProject</PackageId>
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
9 changes: 8 additions & 1 deletion test/MinimalProject/MyClass.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
using System;

namespace minimal
{
public class MyClass {}
public class MyClass
{
public static void Main(string[] args)
{
Console.WriteLine("hello, world");
}
}
}
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:MinimalProject:System.Runtime:System.String*")
(ot--i-should-be-in-buffer-name "*omnisharp-metadata:MiscellaneousFiles.csproj:mscorlib:System.String*")
(ot--point-should-be-on-a-line-containing "public sealed class String"))))
4 changes: 4 additions & 0 deletions test/buttercup-tests/setup.el
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ request id."
(beginning-of-buffer)
(search-forward "$")
(delete-backward-char 1)
(message (concat "ot--buffer-contents-and-point-at-$: (thing-at-point 'word) is: "
(thing-at-point 'word)))
(message (concat "ot--buffer-contents-and-point-at-$: (thing-at-point 'line) is: "
(thing-at-point 'line)))
;; will block
(omnisharp--update-buffer)
(when (fboundp 'evil-insert)
Expand Down
17 changes: 11 additions & 6 deletions test/buttercup-tests/solution/code-actions/fix-code-issue-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
;; each one in a sensible manner.
(describe "Fix code issue"
(before-each (ot--open-the-minimal-project-source-file "MyClass.cs"))
(it "can act on a simple part of the buffer (using System;)"
(it "can act on a simple part of the buffer (using System.Net;)"
(ot--buffer-contents-and-point-at-$
"public class Class1"
"namespace MyNamespace"
"{"
" public void Whatever()"
" public class MyClass"
" {"
" Gu$id.NewGuid();"
" public void Whatever()"
" {"
" IPAddress.Par$se(\"1.2.3.4\");"
" }"
" }"
"}")
(ot--answer-omnisharp--completing-read-with (lambda (choices) "using System;"))
(ot--answer-omnisharp--completing-read-with (lambda (choices)
(message (concat "the choices are: " (json-encode choices)))
"using System.Net;"))
(omnisharp--wait-until-request-completed (omnisharp-run-code-action-refactoring))
(ot--buffer-should-contain "using System;"))
(ot--buffer-should-contain "using System.Net;"))

(it "can operate on the current region (Extract method)"
(ot--buffer-contents-and-region
Expand Down
1 change: 0 additions & 1 deletion test/buttercup-tests/solution/solution-errors-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

(ot--switch-to-the-window-in-the-buffer "*omnisharp-solution-errors*")

(ot--buffer-should-contain "MyClass.cs(1,1): warning CS8019: Unnecessary using directive.")
(ot--buffer-should-contain "MyClass.cs(6,14): error CS1519: Invalid token '-' in class, struct, or interface member declaration")
(ot--buffer-should-contain "MyClass.cs(7,5): error CS1519: Invalid token '}' in class, struct, or interface member declaration")
(ot--buffer-should-contain "omnisharp-solution-errors: finished")))