OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.79k stars 420 forks source link

Provide documentation/example of communication #606

Open mickaelistria opened 8 years ago

mickaelistria commented 8 years ago

I didn't manage to find any documentation or example of how requests/answers between OmniSharp-roslyn server and whethever client should look like. I've seem some clients doing that (for Vim, VSCode or Atom) and I tried to mimic what I thought would be necessary, without much success.

I also tried the example request shown on omnisharp-sever, but this one fail too.

Usually, the error I get with my (erroneous?) requests is

      An unhandled exception has occurred: Must be able aggregate the response to spread them out across all plugins for /autocomplete
System.NotSupportedException: Must be able aggregate the response to spread them out across all plugins for /autocomplete
   at OmniSharp.Middleware.Endpoint.EndpointHandler`2.<HandleAllRequest>d__19.MoveNext() in /home/travis/build/OmniSharp/omnisharp-roslyn/src/OmniSharp.Host/Middleware/Endpoint/EndpointHandler.cs:line 202
jtbm37 commented 8 years ago

@mickaelistria

Start the server

OmniSharp -v -s /path/to/my/project/

-v is important so you can see what the response looks like.

Omnisharp starts a webserver listening at localhost:2000 by default.

Query the server

See all the http endpoints available here.

You can then use curl to experiment.

Find the usage of each enum values and see which Request class is associated so you can know what parameters each endpoint expect.

Let's take an example.

GotoDefinition

The endpoint enumeration is GoToDefinition therefore the url will be http://localhost:2000/gotodefinition. After searching for its usages we can see it's used in the class GotoDefinitionRequest which inherits from Request. Each properties on those classes represent the http request parameters. Here are all the properties:

Line
Column
Buffer
Changes
FileName
Timeout
WantMetadata

From my experience I know that when you need to go to the definition of a symbol you need to at least send to the server the line, column and file name values (the rest are optional, ie. it won't blow up).

With this we can craft this query: curl -H "Content-Type: application/json" -X POST -d '{"Line":"31","Column":"26", "FileName":"/absolute/path/to/filename.cs"}' http://localhost:2000/gotodefinition

We should get the response back: {"FileName":"/absolute/path/to/method/file.cs","Line":34,"Column":46,"MetadataSource":null}

Hope that helps.

mickaelistria commented 8 years ago

@jtbm37 Thanks, that's very helpful, and I made progress thanks to your help. Is there a way to set the workspace "remotely", using some HTTP request to load it instead of using the -s /path/to/project CLI parameter?

danwalmsley commented 8 years ago

@mickaelistria did you get things running in the end? I'm doing the same thing you did back in July, m first request works then the second fails, did you come against a similar problem?

mickaelistria commented 8 years ago

As I'm working on a client for a Java application (Eclipse, https://github.com/eclipselabs/eclipse-language-service ) and moved using the https://github.com/OmniSharp/omnisharp-node-client wrapper around OmniSharp, which implements https://github.com/Microsoft/language-server-protocol, I could use a nice Java client API ( https://github.com/TypeFox/ls-api ). The node client can understand JSon-RPC requests via stdin/stdout.

danwalmsley commented 8 years ago

@mickaelistria thanks, fyi it turned out verbose mode was breaking it. I opened issue #629 regarding that.

Thanks anyway

willl commented 8 years ago

A request from @thinca in the omnisharp-vim repo along the same lines as this request for (more) documentation:

I want:

  • API reference, which describes all endpoints, and its input and output.
  • Command line reference of OmniSharp command.
  • About stdio mode.

I understand manpower is not enough. However, it is difficult for non core member of omnisharp-roslyn to follow the latest version without documentation.

JulCesWhat commented 6 years ago

So, is there a way to do what @mickaelistria wanted to do on https://github.com/OmniSharp/omnisharp-roslyn/issues/606#issuecomment-231793946 ? Or should I open a new issue for this?

NxSoftware commented 2 years ago

@jtbm37

Start the server

OmniSharp -v -s /path/to/my/project/

Unfortunately I failed at the first step on macOS, see #2440.

+1 for creating some documentation around how to get started