Skip to content

Commit 4f42baa

Browse files
VladimirMakaevVladimir Makayevtestforstephen
authored
Add extensibility points to DebugAdapter and ProtocolServer (#509)
Co-authored-by: Vladimir Makayev <[email protected]> Co-authored-by: Jinbo Wang <[email protected]>
1 parent 8905c4a commit 4f42baa

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/DebugAdapter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public CompletableFuture<Messages.Response> dispatchRequest(Messages.Request req
102102
}
103103
}
104104

105-
private void initialize() {
105+
protected void initialize() {
106106
// Register request handlers.
107107
// When there are multiple handlers registered for the same request, follow the rule "first register, first execute".
108108
registerHandler(new InitializeRequestHandler());
@@ -141,15 +141,15 @@ private void initialize() {
141141
registerHandlerForNoDebug(new ProcessIdHandler());
142142
}
143143

144-
private void registerHandlerForDebug(IDebugRequestHandler handler) {
144+
protected void registerHandlerForDebug(IDebugRequestHandler handler) {
145145
registerHandler(requestHandlersForDebug, handler);
146146
}
147147

148-
private void registerHandlerForNoDebug(IDebugRequestHandler handler) {
148+
protected void registerHandlerForNoDebug(IDebugRequestHandler handler) {
149149
registerHandler(requestHandlersForNoDebug, handler);
150150
}
151151

152-
private void registerHandler(IDebugRequestHandler handler) {
152+
protected void registerHandler(IDebugRequestHandler handler) {
153153
registerHandler(requestHandlersForDebug, handler);
154154
registerHandler(requestHandlersForNoDebug, handler);
155155
}
@@ -165,4 +165,5 @@ private void registerHandler(Map<Command, List<IDebugRequestHandler>> requestHan
165165
handlerList.add(handler);
166166
}
167167
}
168+
168169
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Microsoft Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Microsoft Corporation - initial API and implementation
10+
*******************************************************************************/
11+
12+
package com.microsoft.java.debug.core.adapter;
13+
14+
import com.microsoft.java.debug.core.protocol.IProtocolServer;
15+
16+
@FunctionalInterface
17+
public interface IDebugAdapterFactory {
18+
public IDebugAdapter create(IProtocolServer server);
19+
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/ProtocolServer.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ public ProtocolServer(InputStream input, OutputStream output, IProviderContext c
5252
debugAdapter = new DebugAdapter(this, context);
5353
}
5454

55+
/**
56+
* Constructs a protocol server instance based on the given input stream and output stream.
57+
* @param input
58+
* the input stream
59+
* @param output
60+
* the output stream
61+
* @param debugAdapterFactory
62+
* factory to create debug adapter that implements DAP communication
63+
*/
64+
public ProtocolServer(InputStream input, OutputStream output, IDebugAdapterFactory debugAdapterFactory) {
65+
super(input, output);
66+
debugAdapter = debugAdapterFactory.create(this);
67+
}
68+
5569
/**
5670
* A while-loop to parse input data and send output data constantly.
5771
*/

0 commit comments

Comments
 (0)