OmniSharp / omnisharp-emacs

Troll coworkers - use Emacs at work for csharp!
GNU General Public License v3.0
514 stars 90 forks source link

OmniSharp-Roslyn features #178

Open nosami opened 9 years ago

nosami commented 9 years ago

OmniSharp-Roslyn has some features that aren't in the old server that emacs doesn't support yet. I'll list them here and will add to this issue as new stuff is added.

The first big change is the notion of TextChanges. The server can return these whenever change(s) need to be made to one or more documents. A TextChange is a range of text as well as the new text that should go in that range. It could be to delete some text, add some new text or change some text at a specified location.

So the idea is that instead of returning a complete document with all the changes, you can specify that you want only the changes to a document. We currently support this for code refactorings and format document. It is far more efficient to work in this way and you don't get the jarring effect when a document is replaced. It also has the effect of moving the cursor to the correct new location - so if you added a using statement, the cursor would automatically drop down a line. In Atom and Sublime we also use these changes to format a block on keystroke ( '}', ';' ) etc. so that code is automatically indented as you type. You can see how we apply these in Atom here - https://github.com/OmniSharp/omnisharp-atom/blob/2950bbca17af9a434fbdd7be8b45675a7a6516df/lib/omnisharp-atom/features/lib/apply-changes.ts I would suggest trying out omnisharp-atom just so that you can see how this works in practice - it's very smooth. If you do decide to add this to emacs, you'll need to make it conditional as the old server doesn't support TextChanges (and never will)

The next big change is using stdin/stdout to communicate with the server. The server now supports stdio in addition to the web interface.
It works similarly to the http request/response pattern. The format of the requests and responses doesn't change - only the transport changes and we add some extra information to the packets.

The main reason that we did this was so that the server can push information to the editor without the editor requesting any data. For DNX apps, the server loads projects asynchronously and sends events to the editor as each project is added. Another benefit of this is that you don't need to worry about finding free ports etc when working with multiple solutions simultaneously. We use the V8 debugger protocol for sending the data. Each request gets a sequence ID and the corresponding response for t)at request will have a matching ID so that you can pair them up. In the future, we may be able to use this protocol to support debugging too (run until breakpoint etc). We will also probably also send errors and warnings as events that occur in the background.

To start the server in stdio mode, just add --stdio to the command line. Again, take a look at Atom as Atom is using this transport protocol. You will also see that Atom can load multiple solutions completely transparently.

Having said all that, we won't break compatibility with the way emacs does things now, so you should be able to make these changes in your own time (if you want to!)

mikavilpas commented 9 years ago

We already discussed this in a private conversation, but I'll restate this here: there is now a branch that's dedicated to adding support for the new omnisharp-roslyn features here.

That branch so far has the build ported for omnisharp-roslyn integration testing, and it has implemented text changes for renames. I've started working on stdio support so I can drop the dependency to curl for good. This should get rid of weird errors like this and this.

mikavilpas commented 9 years ago

I'm so glad sublime and atom have picked up such tremendous momentum. It seems emacs is now the underdog :)

However, we have awesome people chiming in every week with new fixes, and a great spirit! If someone feels like they want to contribute something, we could use

The development environment is starting to be quite pleasant with all the integration tests and the travis build. If you're trying to figure out how to install, develop, debug, run tests or something similar, I/we can help you, don't be afraid to ask.

bsuh commented 8 years ago

Can we get an update on where omnisharp-roslyn emacs support is? The branch seems to have not had commits in a few months. Is it useable as an alpha?

mikavilpas commented 8 years ago

It just so happens I commented on omnisharp-emacs on reddit here: https://www.reddit.com/r/emacs/comments/3w7gtj/omnisharp_extension_to_emacs/

But more specifically: is it ready for use:

Long version:

I'll be more than happy to answer any questions you may have, but for the time being I'm not actively developing the project. I talk more about this in my reddit post.

2015-12-10 17:25 GMT+02:00 Brian Suh notifications@github.com:

Can we get an update on where omnisharp-roslyn emacs support is? The branch seems to have not had commits in a few months. Is it useable as an alpha?

— Reply to this email directly or view it on GitHub https://github.com/OmniSharp/omnisharp-emacs/issues/178#issuecomment-163657783 .

abourget commented 8 years ago

Ping here ? any other solutions to happily code CSharp in Emacs elsewhere ?

juergenhoetzel commented 8 years ago

For me the Roslyn branch is quite useful. Because the old Omnisharp server is deprecated, I would call for making this the default branch.

kirill-gerasimenko commented 8 years ago

Hi, @juergenhoetzel, which version of omnisharp-roslyn server works for you (for the feature-omnisharp-roslyn-support branch)?

juergenhoetzel commented 8 years ago

@kirill-gerasimenko

I use the a master checkout of omnisharp-roslyn and set the omnisharp-server-executable-path to the net451 target executable: /src/OmniSharp/bin/Release/net451/centos.7-x64/OmniSharp.exe

The stdio transport is not affected by this issue: System.DllNotFoundException: System.Native #600

kirill-gerasimenko commented 8 years ago

@juergenhoetzel thanks! I was using dev branch and emacs was hanging for me, I'll try master with settings you mentioned.

juergenhoetzel commented 8 years ago

@kirill-gerasimenko

sry that was a typo, indeed I'm using the dev branch:

juergen@centos:~/csharp/omnisharp-roslyn → git branch
* dev

You checked the output of the *omnisharp-debug* and OmniServer buffer?

kirill-gerasimenko commented 8 years ago

@juergenhoetzel I will check these, I'm very new to emacs, still figuring out things. Thanks for update!

mikavilpas commented 8 years ago

Great to hear it's working for you.

With regards to the master branch, feature-omnisharp-roslyn could be merged to it, but I'm worried that people that may be using the current master will update their packages, and find omnisharp not working for them any longer. So the migration path isn't clear for me. Any thoughts?

k-ode commented 8 years ago

How do you currently run the roslyn branch? I just tried it and my Emacs just crashes if I try to run omnisharp-start-omnisharp-server.

If I start it manually, I get errors like these:

Blocking call to accept-process-output with quit inhibited!! [2 times]
REQUEST [error] Error from parser json-read: (json-end-of-file)
Error from http://localhost:2000/http://localhost:2000/typelookup : (json-end-of-file)

The url is obviously wrong, but even if I hack around that I still get errors:

Blocking call to accept-process-output with quit inhibited!! [4 times]
Error from http://localhost:2000/typelookup : (error http 500)
Error from  http://localhost:2000/typelookup.

The output from the server looks like this:

      An unhandled exception has occurred: Must be able aggregate the response to spread them out across all plugins for /typelookup
System.NotSupportedException: Must be able aggregate the response to spread them out across all plugins for /typelookup
   vid OmniSharp.Middleware.Endpoint.EndpointHandler`2.<HandleAllRequest>d__19.MoveNext() i C:\home\bin\omnisharp-roslyn\src\OmniSharp.Host\Middleware\Endpoint\EndpointHandler.cs:rad 202
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
   vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   vid OmniSharp.Middleware.Endpoint.EndpointHandler`2.<Process>d__16.MoveNext() i C:\home\bin\omnisharp-roslyn\src\OmniSharp.Host\Middleware\Endpoint\EndpointHandler.cs:rad 130
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
   vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   vid OmniSharp.Middleware.EndpointMiddleware.<Invoke>d__7.MoveNext() i C:\home\bin\omnisharp-roslyn\src\OmniSharp.Host\Middleware\EndpointMiddleware.cs:rad 91
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
   vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   vid Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()
bsuh commented 8 years ago

Wasted hours this previous weekend trying to get omnisharp-roslyn working on OSX without much success 😞

First ran into the problem of using netcoreapp1.0 version of omnisharp-roslyn can't handle loading projects using .NET 4 https://github.com/OmniSharp/omnisharp-roslyn/issues/586

Running the net451 version standalone omnisharp-roslyn server doesn't work https://github.com/OmniSharp/omnisharp-roslyn/issues/600

Using the omnisharp-emac's HTTP client instead of stdio results in incorrect requests like http://localhost:2000/http://localhost:2000/typelookup

Running the net451 version stdio doesn't work unless you patch omnisharp-emacs to start the process with "mono" before omnisharp-server-executable-path

Even then none of the API seem to return any meaningful results. Can't go to definition. Linting returns no errors. Code completion doesn't return any results.

razzmatazz commented 8 years ago

@bsuh – i might be able to help you as I managed to get both the Roslyn server and emacs client to work pretty well for me using the latest Omni sharp-Roslyn binaries (from source).

A) Yes there is a problem that OS X (and Linux I think) needs mono to invoke the actual .net .exe. I have one-liner sh script for this, patching Elise code is another option. My idea is that omnisharp-Roslyn would eventually provided this wrapper when installed.( PR wanted?)

B) I am using it with msbuild/.sln+.csproj solution. Do you have something else (.net core .project)?

C) have your tried enabling omnsharp-debug variable to have debug output from the server? That would help diagnose why Roslyn server does not provide intellisense for you. Me I had to patch Roslyn sever to make it work (that PR is merged already)

razzmatazz commented 8 years ago

D) I am using stdio transport btw

k-ode commented 8 years ago

Just running (start-process "foo" "*foo*" "OmniSharp") crashes Emacs on Windows 8.1 (with OmniSharp.exe on path).

kirill-gerasimenko commented 8 years ago

I've got the same issue on windows 10. I've read in emacs documentation that on windows there is limitation that if the process writes directly to CON: device emacs will fail or not work(I don't know if this is the reason of the issue though). I've tried to use netstandard version of the server - it didn't crash emacs, but in debug buffer there were errors. Sorry for poor details - it was some time ago.

On 21 Sep 2016, 00:14 +0200, Kim Grönqvist notifications@github.com, wrote:

Just running (start-process "foo" "foo" "OmniSharp") crashes Emacs on Windows 8.1 (with OmniSharp.exe on path).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub (https://github.com/OmniSharp/omnisharp-emacs/issues/178#issuecomment-248451182), or mute the thread (https://github.com/notifications/unsubscribe-auth/AC5UqsQrHQdVF_PfRMMZtxm8hgm-kbGFks5qsFq-gaJpZM4E_2D3).

mikavilpas commented 8 years ago

Strange and unfortunate behaviour for sure. If anyone would like to experiment with it that would be great - personally I have no time, sorry.

kirill-gerasimenko commented 8 years ago

Hi, @razzmatazz, is this your working configuration:

razzmatazz commented 8 years ago

@kirill-gerasimenko – Right. Server may be a couple of weeks old but yes. On emacs 25 / os x 10.11

Kirill Gerasimenko notifications@github.com schrieb am Do. 22. Sep. 2016 um 12:53:

Hi, @razzmatazz https://github.com/razzmatazz, is this your working configuration:

  • OmniSharp server from latest dev branch?
  • omnisharp-emacs from feature-omnisharp-roslyn-support?
  • running omnisharp-emacs with stdio?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/OmniSharp/omnisharp-emacs/issues/178#issuecomment-248858162, or mute the thread https://github.com/notifications/unsubscribe-auth/AAiZZIyBWVN_y_7THehF6qzPilJ71nJbks5qslAZgaJpZM4E_2D3 .

juergenhoetzel commented 8 years ago

I've got the same issue on windows 10. I've read in emacs documentation that on windows there is limitation that if the process writes directly to CON: device emacs will fail or not work(I don't know if this is the reason of the issue though). I've tried to use netstandard version of the server - it didn't crash emacs, but in debug buffer there were errors. Sorry for poor details - it was some time ago.

I can confirm the net451 version crashes Emacs. But the netcoreapp1.0 version works fine for me:

omnisharp-roslyn/src/OmniSharp/bin/Release/netcoreapp1.0/win7-x64/Omnisharp.exe

My Environment:

razzmatazz commented 7 years ago

This is kind of late, but I found the problem with emacs crash, in particular x64 .net exes make emacs crash in start-process.

kirill-gerasimenko commented 7 years ago

Many thanks! Great job you've done discovering the issue!

PS: new "install omnisharp server" command works like a charm!