1
1
using System . Collections . Generic ;
2
+ using Microsoft . Extensions . Logging ;
2
3
using Newtonsoft . Json . Linq ;
3
4
using OmniSharp . Extensions . JsonRpc ;
4
- using OmniSharp . Extensions . JsonRpc . Client ;
5
5
using OmniSharp . Extensions . JsonRpc . Server ;
6
- using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
6
+ using OmniSharp . Extensions . LanguageServer . Protocol ;
7
7
using OmniSharp . Extensions . LanguageServer . Protocol . Shared ;
8
8
using OmniSharp . Extensions . LanguageServer . Protocol . Window ;
9
9
10
10
namespace OmniSharp . Extensions . LanguageServer . Client
11
11
{
12
12
public class LspClientReceiver : Receiver , ILspClientReceiver
13
13
{
14
- private readonly ILspHandlerTypeDescriptorProvider _handlerTypeDescriptorProvider ;
15
- private bool _initialized ;
14
+ private readonly ILogger < LspClientReceiver > _logger ;
16
15
17
- public LspClientReceiver ( ILspHandlerTypeDescriptorProvider handlerTypeDescriptorProvider )
16
+ public LspClientReceiver ( ILogger < LspClientReceiver > logger )
18
17
{
19
- _handlerTypeDescriptorProvider = handlerTypeDescriptorProvider ;
18
+ _logger = logger ;
20
19
}
21
20
22
21
public override ( IEnumerable < Renor > results , bool hasResponse ) GetRequests ( JToken container )
@@ -29,36 +28,33 @@ public override (IEnumerable<Renor> results, bool hasResponse) GetRequests(JToke
29
28
var ( results , hasResponse ) = base . GetRequests ( container ) ;
30
29
foreach ( var item in results )
31
30
{
32
- if ( item . IsRequest && _handlerTypeDescriptorProvider . IsMethodName ( item . Request ! . Method , typeof ( IShowMessageRequestHandler ) ) )
31
+ switch ( item )
33
32
{
34
- newResults . Add ( item ) ;
35
- }
36
- else if ( item . IsResponse )
37
- {
38
- newResults . Add ( item ) ;
39
- }
40
- else if ( item . IsNotification &&
41
- _handlerTypeDescriptorProvider . IsMethodName (
42
- item . Notification ! . Method ,
43
- typeof ( IShowMessageHandler ) ,
44
- typeof ( ILogMessageHandler ) ,
45
- typeof ( ITelemetryEventHandler )
46
- )
47
- )
48
- {
49
- newResults . Add ( item ) ;
33
+ case { IsResponse : true } :
34
+ case { IsRequest : true , Request : { Method : WindowNames . ShowMessageRequest } } :
35
+ case { IsNotification : true , Notification : { Method : WindowNames . ShowMessage } } :
36
+ case { IsNotification : true , Notification : { Method : WindowNames . LogMessage } } :
37
+ case { IsNotification : true , Notification : { Method : WindowNames . TelemetryEvent } } :
38
+ case { IsNotification : true , Notification : { Method : WindowNames . WorkDoneProgressCancel } } :
39
+ case { IsNotification : true , Notification : { Method : WindowNames . WorkDoneProgressCreate } } :
40
+ newResults . Add ( item ) ;
41
+ break ;
42
+ case { IsRequest : true , Request : { } } :
43
+ _logger . LogWarning ( "Unexpected request {Method} {@Request}" , item . Request . Method , item . Request ) ;
44
+ break ;
45
+ case { IsNotification : true , Notification : { } } :
46
+ _logger . LogWarning ( "Unexpected notification {Method} {@Request}" , item . Notification . Method , item . Notification ) ;
47
+ break ;
48
+ case { IsError : true , Error : { } } :
49
+ _logger . LogWarning ( "Unexpected error {Method} {@Request}" , item . Error . Method , item . Error ) ;
50
+ break ;
51
+ default :
52
+ _logger . LogError ( "Unexpected Renor {@Renor}" , item ) ;
53
+ break ;
50
54
}
51
55
}
52
56
53
57
return ( newResults , hasResponse ) ;
54
58
}
55
-
56
- public void Initialized ( ) => _initialized = true ;
57
-
58
- public override bool ShouldFilterOutput ( object value )
59
- {
60
- if ( _initialized ) return true ;
61
- return value is OutgoingResponse || value is OutgoingRequest v && v . Params is InitializeParams ;
62
- }
63
59
}
64
60
}
0 commit comments