Skip to content

Fix invalid cast issue in omnisharp-roslyn by fixing LspHandlerDescriptor ctor #488

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

Conversation

razzmatazz
Copy link
Contributor

@razzmatazz razzmatazz commented Dec 26, 2020

See:

The issue (apparently) is that LspHandlerDescriptor is constructed for DelegatingRequest that is registered in LanguageServerHost.cs (in omnisharp-roslyn) via r.OnRequest() here:

https://github.com/OmniSharp/omnisharp-roslyn/blob/b68f146a649bd6b0294894831e08bbd3b802110c/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs#L310

The constructor attempts to resolve RPC return type based on what generic type is set on IRequest<T> that is inherited by DelegatingRequest. However DelegatingRequest implements both IRequest and IRequest<TResponse> and LINQ code selects IRequest<MediatR.Unit> type as the return value -- while it should be IRequest<JToken> for LSP requests (apparently?).

The issue was fixed by ordering implemented IRequest<> interfaces by generic param type and taking the first that is not MediatR.Unit -- only then use the MediatR.Unit version.


I am not 100% sure this is the proper/correct fix for my issue (OmniSharp/omnisharp-roslyn#1995) but it seems to do the job.

I can try to write tests or change this you feel that is the wrong approach to fix the issue.

…ptor .ctor

The issue (apparently) is that LspHandlerDescriptor is constructed for
DelegatingRequest that is registered in LanguageServerHost.cs (in
omnisharp-roslyn) via .OnRequest().

The constructor attempts to resolve RPC return type based on what
generic type is set on IRequest<T> that inherits DelegatingRequest.
However DelegatingRequest implements both IRequest and
IRequest<TResponse> and .LINQ query selects IRequest<MediatR.Unit> type
as the return value -- while it should be IRequest<JToken>.

Fixed by ordering implemented IRequest<> interfaces by generic param
type and taking the first that is not MediatR.Unit -- only then use the
MediatR.Unit version.
@codecov
Copy link

codecov bot commented Dec 26, 2020

Codecov Report

Merging #488 (0763b5a) into master (81a38cc) will decrease coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #488      +/-   ##
==========================================
- Coverage   73.08%   73.07%   -0.01%     
==========================================
  Files         256      256              
  Lines       12246    12246              
  Branches      843      843              
==========================================
- Hits         8950     8949       -1     
- Misses       3296     3297       +1     
Impacted Files Coverage Δ
src/JsonRpc/OutputHandler.cs 96.72% <0.00%> (-1.64%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81a38cc...0763b5a. Read the comment docs.

@david-driscoll
Copy link
Member

@razzmatazz This change makes sense to me, we could probably just filter Unit out entirely, however this should have a similar effect.

I'm not too worried about tests as the other tests have all passed. I might look to see if I can add some more validation tests around the delegated request/responses however for the future.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mysterious We forgot to label this
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants