Skip to content

Commit 4adb231

Browse files
committed
Move MessageDispatcher creation outside of ProtocolEndpoint
This change moves the creation of a MessageDispatcher instance outside of the ProtocolEndpoint class so that it can be created at a higher level in the startup code. The new MessageDispatcher parameter will be used in an upcoming refactoring.
1 parent 311f02e commit 4adb231

File tree

7 files changed

+27
-15
lines changed

7 files changed

+27
-15
lines changed

src/PowerShellEditorServices.Protocol/Client/DebugAdapterClientBase.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Client
1313
public class DebugAdapterClient : ProtocolEndpoint
1414
{
1515
public DebugAdapterClient(ChannelBase clientChannel)
16-
: base(clientChannel, MessageProtocolType.DebugAdapter)
16+
: base(
17+
clientChannel,
18+
new MessageDispatcher(),
19+
MessageProtocolType.DebugAdapter)
1720
{
1821
}
1922

src/PowerShellEditorServices.Protocol/Client/LanguageClientBase.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public abstract class LanguageClientBase : ProtocolEndpoint
2121
/// </summary>
2222
/// <param name="clientChannel">The channel to use for communication with the server.</param>
2323
public LanguageClientBase(ChannelBase clientChannel)
24-
: base(clientChannel, MessageProtocolType.LanguageServer)
24+
: base(
25+
clientChannel,
26+
new MessageDispatcher(),
27+
MessageProtocolType.LanguageServer)
2528
{
2629
}
2730

src/PowerShellEditorServices.Protocol/MessageProtocol/ProtocolEndpoint.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private bool InMessageLoopThread
5757
/// handlers for requests, responses, and events that are
5858
/// transmitted through the channel.
5959
/// </summary>
60-
protected MessageDispatcher MessageDispatcher { get; set; }
60+
private MessageDispatcher MessageDispatcher { get; set; }
6161

6262
/// <summary>
6363
/// Initializes an instance of the protocol server using the
@@ -71,9 +71,11 @@ private bool InMessageLoopThread
7171
/// </param>
7272
public ProtocolEndpoint(
7373
ChannelBase protocolChannel,
74+
MessageDispatcher messageDispatcher,
7475
MessageProtocolType messageProtocolType)
7576
{
7677
this.protocolChannel = protocolChannel;
78+
this.MessageDispatcher = messageDispatcher;
7779
this.messageProtocolType = messageProtocolType;
7880
this.originalSynchronizationContext = SynchronizationContext.Current;
7981
}
@@ -89,12 +91,6 @@ public async Task Start()
8991
// Start the provided protocol channel
9092
this.protocolChannel.Start(this.messageProtocolType);
9193

92-
// Start the message dispatcher
93-
this.MessageDispatcher = new MessageDispatcher(this.protocolChannel);
94-
95-
// Set the handler for any message responses that come back
96-
this.MessageDispatcher.SetResponseHandler(this.HandleResponse);
97-
9894
// Listen for unhandled exceptions from the message loop
9995
this.UnhandledException += MessageDispatcher_UnhandledException;
10096

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public DebugAdapter(
4141
EditorSession editorSession,
4242
ChannelBase serverChannel,
4343
bool ownsEditorSession)
44-
: base(serverChannel)
44+
: base(serverChannel, new MessageDispatcher())
4545
{
4646
this.editorSession = editorSession;
4747
this.ownsEditorSession = ownsEditorSession;

src/PowerShellEditorServices.Protocol/Server/DebugAdapterBase.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
1212
{
1313
public abstract class DebugAdapterBase : ProtocolEndpoint
1414
{
15-
public DebugAdapterBase(ChannelBase serverChannel)
16-
: base (serverChannel, MessageProtocolType.DebugAdapter)
15+
public DebugAdapterBase(
16+
ChannelBase serverChannel,
17+
MessageDispatcher messageDispatcher)
18+
: base(
19+
serverChannel,
20+
messageDispatcher,
21+
MessageProtocolType.DebugAdapter)
1722
{
1823
}
1924

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public IEditorOperations EditorOperations
5151
public LanguageServer(
5252
EditorSession editorSession,
5353
ChannelBase serverChannel)
54-
: base(serverChannel)
54+
: base(serverChannel, new MessageDispatcher())
5555
{
5656
this.editorSession = editorSession;
5757
this.editorSession.PowerShellContext.RunspaceChanged += PowerShellContext_RunspaceChanged;

src/PowerShellEditorServices.Protocol/Server/LanguageServerBase.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ public abstract class LanguageServerBase : ProtocolEndpoint
1414
{
1515
private ChannelBase serverChannel;
1616

17-
public LanguageServerBase(ChannelBase serverChannel) :
18-
base(serverChannel, MessageProtocolType.LanguageServer)
17+
public LanguageServerBase(
18+
ChannelBase serverChannel,
19+
MessageDispatcher messageDispatcher)
20+
: base(
21+
serverChannel,
22+
messageDispatcher,
23+
MessageProtocolType.LanguageServer)
1924
{
2025
this.serverChannel = serverChannel;
2126
}

0 commit comments

Comments
 (0)