Code Monkey home page Code Monkey logo

Comments (7)

davidwengier avatar davidwengier commented on June 3, 2024 1

If I'm reading the code correctly, I don't think the initialize request is interceptable in the middle layer

initialize is dispatched here but the middle layer only comes into play a few lines later in that method, here (links go to closed source code.. sorry!)

I think the solution here might be to create a language server that gets all of the requests, and then in turn delegates them to the underlying server you don't own.

from vs-streamjsonrpc.

AArnott avatar AArnott commented on June 3, 2024

This seems more like an LSP-specific request. StreamJsonRpc doesn't provide for adding any middleware layer to modify an outbound requests. I'll see if any of the LSP folks can jump in here or recommend an alternate forum for your question.

from vs-streamjsonrpc.

matteo-prosperi avatar matteo-prosperi commented on June 3, 2024

Implementing the ILanguageClientMiddleLayer interface should allow you to intercept the initialize message and modify it in a way that is acceptable to the server.

from vs-streamjsonrpc.

matteo-prosperi avatar matteo-prosperi commented on June 3, 2024

However, I noticed that even after implementing the ILanguageClientMiddleLayer and assigning it to MiddleLayer property of my client, it doesn't intercept the Initialize request.

Are you getting calls to the ILanguageClientMiddleLayer.CanHandle method? Are you returning true from it for the messages you want to modify?
How early are you assigning the middle layer to the ILanguageClientCustomMessage2.MiddleLayer property? I would suggest doing it at construction time.

from vs-streamjsonrpc.

Rishabh-V avatar Rishabh-V commented on June 3, 2024

Thanks @AArnott, @matteo-prosperi, @davidwengier for pitching in and helping.

@matteo-prosperi - I am returning true from CanHandle method but CanHandle is fired for textdocument/didOpen at the start when the file is opened but not for the InitializeRequest and so unable to intercept this request. OnServerInitializeFailedAsync is called directly.

@davidwengier - This was my assessment as well while debugging the source. The RemoteLanguageClientInstance has a method named SendInitializeRequestAsync which is responsible for sending the InitializeRequest. I modified the InitializeParams to remove the PublishDiagnostics value while debugging and post that all the requests were intercepted by the middle layer.

Couple of questions on the suggestion approach:

  1. Will there be any foreseeable delay in this approach, for example in intellisense or hover?
  2. Is there a sample or reference code I can refer to get this right the first time?

Many thanks to all of you!

from vs-streamjsonrpc.

davidwengier avatar davidwengier commented on June 3, 2024
  1. There will be delays, though whether they impact the user is questionable. Doing things this way means two different duplex streams, and therefore any serialization/deserialization overhead is doubled, as your delegating server necessarily has to deserialize everything, only to reserialize it again. I will say though that we use this system in VS for the Razor editor, and the Html editor when its LSP mode is turned on. In fact, in the Razor editor we often delegate to the Html server, which in turn delegates to the CSS or TypeScript server, so we're already doing this, and doing it in a more convoluted way than you will.
  2. Not sure there is a great example of this, but the code for the Razor server is OSS. It's a bit convoluted as it uses a library provided by Roslyn for its server, and it doesn't delegate directly to any other servers, but rather goes back through VS buffers to do it, which is probably overkill for your needs. If you want to start digging in though, our ILanguageClient implementation is here: https://github.com/dotnet/razor/blob/main/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs

from vs-streamjsonrpc.

Rishabh-V avatar Rishabh-V commented on June 3, 2024

Thanks @davidwengier for sharing the details. Appreciate your help. I will give it a try.

I do hope though that given such issues, there should be a way to change the Client Capabilities in the client somewhere.

Thanks again everyone and I am happy to close this issue.

from vs-streamjsonrpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.