Comments (7)
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.
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.
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.
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.
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:
- Will there be any foreseeable delay in this approach, for example in intellisense or hover?
- 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.
- 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.
- 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.
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)
- ConnectionLostException when invoking re-assigned Remote Targets HOT 3
- Docs: Dead link in joinableTaskFactory.md HOT 1
- Crash on Android 11 devices when throwing RemoteInvocationException HOT 9
- JsonRpc over HTTP fails HOT 1
- Add support for JsonPropertyNameAttribute from System.Text.Json HOT 10
- IDisposable interface ambiguity on receiver side when marshaling with RpcMarshalableAttribute HOT 1
- How to receive a JSON object as an rpc response? HOT 1
- Parse custom json rpc message responses HOT 1
- Event as Request from JSON Rpc Server HOT 1
- Allow `[RpcMarshalable]` interfaces to declare properties with serialized values HOT 4
- JSON Contract resolver needs to be reused HOT 1
- Support MessagePackFormatterAttribute applied to RPC methods
- User-supplied `TypelessObjectResolver` from MessagePack causes `IAsyncEnumerable<T>` to malfunction
- Support System.Text.Json compatible Json Converter for Request ID HOT 4
- Use camelCase for response objects HOT 4
- Connection with Java-based JSON-RPC server fails because Content-Length is required HOT 2
- package downgrade caused by v2.17.8 HOT 7
- JoinableTaskFactory bridge fails with multiple JsonRpc instances in a process without JTF HOT 4
- Deserialization of nested objects when using System.Text.Json HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vs-streamjsonrpc.