-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathDebugAdapterClientBase.cs
97 lines (82 loc) · 3.76 KB
/
DebugAdapterClientBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel;
using Microsoft.PowerShell.EditorServices.Utility;
using System.Threading.Tasks;
using System;
namespace Microsoft.PowerShell.EditorServices.Protocol.Client
{
public class DebugAdapterClient : IMessageSender, IMessageHandlers
{
private ILogger logger;
private ProtocolEndpoint protocolEndpoint;
private MessageDispatcher messageDispatcher;
public DebugAdapterClient(ChannelBase clientChannel, ILogger logger)
{
this.logger = logger;
this.messageDispatcher = new MessageDispatcher(logger);
this.protocolEndpoint = new ProtocolEndpoint(
clientChannel,
messageDispatcher,
logger);
}
public async Task StartAsync()
{
this.protocolEndpoint.Start();
// Initialize the debug adapter
await this.SendRequestAsync(
InitializeRequest.Type,
new InitializeRequestArguments
{
LinesStartAt1 = true,
ColumnsStartAt1 = true
},
true);
}
public void Stop()
{
this.protocolEndpoint.Stop();
}
public async Task LaunchScriptAsync(string scriptFilePath)
{
await this.SendRequestAsync(
LaunchRequest.Type,
new LaunchRequestArguments {
Script = scriptFilePath
},
true);
await this.SendRequestAsync(
ConfigurationDoneRequest.Type,
null,
true);
}
public Task SendEventAsync<TParams, TRegistrationOptions>(NotificationType<TParams, TRegistrationOptions> eventType, TParams eventParams)
{
return ((IMessageSender)protocolEndpoint).SendEventAsync(eventType, eventParams);
}
public Task<TResult> SendRequestAsync<TParams, TResult, TError, TRegistrationOptions>(RequestType<TParams, TResult, TError, TRegistrationOptions> requestType, TParams requestParams, bool waitForResponse)
{
return ((IMessageSender)protocolEndpoint).SendRequestAsync(requestType, requestParams, waitForResponse);
}
public Task<TResult> SendRequestAsync<TResult, TError, TRegistrationOptions>(RequestType0<TResult, TError, TRegistrationOptions> requestType0)
{
return ((IMessageSender)protocolEndpoint).SendRequestAsync(requestType0);
}
public void SetRequestHandler<TParams, TResult, TError, TRegistrationOptions>(RequestType<TParams, TResult, TError, TRegistrationOptions> requestType, Func<TParams, RequestContext<TResult>, Task> requestHandler)
{
((IMessageHandlers)messageDispatcher).SetRequestHandler(requestType, requestHandler);
}
public void SetRequestHandler<TResult, TError, TRegistrationOptions>(RequestType0<TResult, TError, TRegistrationOptions> requestType0, Func<RequestContext<TResult>, Task> requestHandler)
{
((IMessageHandlers)messageDispatcher).SetRequestHandler(requestType0, requestHandler);
}
public void SetEventHandler<TParams, TRegistrationOptions>(NotificationType<TParams, TRegistrationOptions> eventType, Func<TParams, EventContext, Task> eventHandler)
{
((IMessageHandlers)messageDispatcher).SetEventHandler(eventType, eventHandler);
}
}
}