Skip to content

Commit

Permalink
Enable console for vscode-js-debug
Browse files Browse the repository at this point in the history
* Fix some bugs in case DAP process doesn't exist
* Buffer streams by default so they're not discarded when received
before console shows
  • Loading branch information
mickaelistria committed Oct 2, 2023
1 parent cb8f917 commit 1b66a28
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.lsp4e.debug/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Debug Adapter client for Eclipse IDE (Incubation)
Bundle-SymbolicName: org.eclipse.lsp4e.debug;singleton:=true
Bundle-Version: 0.15.4.qualifier
Bundle-Version: 0.15.5.qualifier
Bundle-Activator: org.eclipse.lsp4e.debug.DSPPlugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public DSPProcess(DSPDebugTarget dspDebugTarget, ProcessEventArguments args) {
this.target = dspDebugTarget;
this.proxy = new DSPStreamsProxy(target.getDebugProtocolServer());
this.processArgs = args;
handle = ProcessHandle.of(args.getSystemProcessId());
handle = args != null && args.getSystemProcessId() != null ? ProcessHandle.of(args.getSystemProcessId()) : Optional.empty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DSPStreamMonitor implements IFlushableStreamMonitor {

private final ListenerList<IStreamListener> listeners = new ListenerList<>();
private final StringBuilder stream = new StringBuilder();
private boolean buffer;
private boolean buffer = true; // buffer by default as first output can happen before listeners are in place

@Override
public String getContents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,11 @@ public DSPThread[] getThreads() {
}
}
try {
CompletableFuture<ThreadsResponse> threads2 = getDebugProtocolServer().threads();
var server = getDebugProtocolServer();
if (server == null) {
return new DSPThread[0];
}
CompletableFuture<ThreadsResponse> threads2 = server.threads();
CompletableFuture<DSPThread[]> future = threads2.thenApplyAsync(threadsResponse -> {
synchronized (threads) {
final var lastThreads = new TreeMap<Integer, DSPThread>(threads);
Expand Down Expand Up @@ -628,18 +632,20 @@ public void thread(ThreadEventArguments args) {
@Override
public void output(OutputEventArguments args) {
boolean outputted = false;
if (process != null) {
DSPStreamsProxy dspStreamsProxy = process.getStreamsProxy();
String output = args.getOutput();
if (args.getCategory() == null || OutputEventArgumentsCategory.CONSOLE.equals(args.getCategory())
|| OutputEventArgumentsCategory.STDOUT.equals(args.getCategory())) {
// TODO put this data in a different region with a different colour
dspStreamsProxy.getOutputStreamMonitor().append(output);
outputted = true;
} else if (OutputEventArgumentsCategory.STDERR.equals(args.getCategory())) {
dspStreamsProxy.getErrorStreamMonitor().append(output);
outputted = true;
}
DSPStreamsProxy dspStreamsProxy;
if (process == null) {
process(null); // create dummy process to have a console
}
dspStreamsProxy = process.getStreamsProxy();
String output = args.getOutput();
if (args.getCategory() == null || OutputEventArgumentsCategory.CONSOLE.equals(args.getCategory())
|| OutputEventArgumentsCategory.STDOUT.equals(args.getCategory())) {
// TODO put this data in a different region with a different colour
dspStreamsProxy.getOutputStreamMonitor().append(output);
outputted = true;
} else if (OutputEventArgumentsCategory.STDERR.equals(args.getCategory())) {
dspStreamsProxy.getErrorStreamMonitor().append(output);
outputted = true;
}
if (!outputted && DSPPlugin.DEBUG) {
System.out.println("output: " + args);
Expand Down

0 comments on commit 1b66a28

Please sign in to comment.