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

Make it possible for sbt plugins to register server handlers for custom JSON-RPC methods #3890

Closed
olafurpg opened this issue Jan 16, 2018 · 3 comments
Assignees
Milestone

Comments

@olafurpg
Copy link
Member

olafurpg commented Jan 16, 2018

problem

I have integrated with sbt server in my language server and managed to trigger compile on file save scalameta/metals#170 I am very excited about the potential for using sbt server from an IDE to simplify the "Import project" step.

Would it be possible to give sbt plugins the ability to register handlers for custom JSON-RPC methods? Currently, sbt hardcodes a handful of LSP methods in

like initialize and textDocument/didSave. I would love to be able to write an sbt plugin that adds handler to respond to custom methods. In particular, I am interested in implementing methods from https://github.com/scalacenter/bsp/blob/master/docs/bsp.md to simplify project import when the user opens a directory with an sbt build.

expectation

Just brainstorming, maybe there could be a sbtServerMethods: SettingKey[List[JsonRpcMethodHandler]] where

case class JsonRpcMethod[A:Encoder, B:Decoder](method: String)
case class JsonRpcMethodHandler[A, B](endpoint: JsonRpcMethod[A, B], handler: A => B)

notes

sbt version: 1.1.0

@eed3si9n
Copy link
Member

I am on board with making sbt server more extensible, especially for experimenting with new feature proposals.

@dwijnand
Copy link
Member

SGTM too.

My only concern is I'd like to try and keep the compatibility promises to some reasonable minimum, so we have flexibility to change the internal details of the server without breaking any server-extending plugins that will have been published.

@olafurpg
Copy link
Member Author

I would be OK with no compatibility promises. Internal APIs are fine. Ideally, I'd like to see these methods handled in sbt server by default in the long term. I think a good first step towards that direction would be to allow quicker experimentation via sbt plugins.

@eed3si9n eed3si9n modified the milestones: 1.something, 1.2.0 Jan 22, 2018
eed3si9n added a commit to eed3si9n/sbt that referenced this issue Feb 28, 2018
Fixes sbt#3890

Here's an example:

```scala
    Global / serverHandlers += ServerHandler({ callback =>
      import callback._
      import sjsonnew.BasicJsonProtocol._
      import sbt.internal.protocol.JsonRpcRequestMessage
      ServerIntent(
        {
          case r: JsonRpcRequestMessage if r.method == "lunar/helo" =>
            jsonRpcNotify("lunar/oleh", "")
            ()
        },
        PartialFunction.empty
      )
```
eed3si9n added a commit to eed3si9n/sbt that referenced this issue Feb 28, 2018
Fixes sbt#3890

Here's an example:

```scala
    Global / serverHandlers += ServerHandler({ callback =>
      import callback._
      import sjsonnew.BasicJsonProtocol._
      import sbt.internal.protocol.JsonRpcRequestMessage
      ServerIntent(
        {
          case r: JsonRpcRequestMessage if r.method == "lunar/helo" =>
            jsonRpcNotify("lunar/oleh", "")
            ()
        },
        PartialFunction.empty
      )
```
@eed3si9n eed3si9n self-assigned this Feb 28, 2018
eed3si9n added a commit to eed3si9n/sbt that referenced this issue Mar 14, 2018
Fixes sbt#3890

Here's an example:

```scala
    Global / serverHandlers += ServerHandler({ callback =>
      import callback._
      import sjsonnew.BasicJsonProtocol._
      import sbt.internal.protocol.JsonRpcRequestMessage
      ServerIntent(
        {
          case r: JsonRpcRequestMessage if r.method == "lunar/helo" =>
            jsonRpcNotify("lunar/oleh", "")
            ()
        },
        PartialFunction.empty
      )
```
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants