From c6155602b62f3a516eea3db6f652f466390b4e93 Mon Sep 17 00:00:00 2001 From: Jan Horvath Date: Thu, 9 Jan 2025 10:43:52 +0100 Subject: [PATCH] Fixing the build output appearence in vscode --- .../ui/AbstractLspInputOutputProvider.java | 36 ++++++++++++++----- java/java.lsp.server/vscode/src/extension.ts | 11 ++++-- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/AbstractLspInputOutputProvider.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/AbstractLspInputOutputProvider.java index aa778d9e3926..c31252fb67e8 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/AbstractLspInputOutputProvider.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/AbstractLspInputOutputProvider.java @@ -85,7 +85,7 @@ public final Lookup getIOLookup(LspIO io) { @Override public final void resetIO(LspIO io) { - NbCodeLanguageClient client = LspServerUtils.findLspClient(Lookup.getDefault()); + NbCodeLanguageClient client = io.getClient(); if (client != null) { client.resetOutput(io.name); } @@ -93,7 +93,7 @@ public final void resetIO(LspIO io) { @Override public final void showIO(LspIO io, Set operations) { - NbCodeLanguageClient client = LspServerUtils.findLspClient(Lookup.getDefault()); + NbCodeLanguageClient client = io.getClient(); if (client != null) { client.showOutput(io.name); } @@ -101,7 +101,7 @@ public final void showIO(LspIO io, Set operations) { @Override public final void closeIO(LspIO io) { - NbCodeLanguageClient client = LspServerUtils.findLspClient(Lookup.getDefault()); + NbCodeLanguageClient client = io.getClient(); if (client != null) { client.closeOutput(io.name); } @@ -180,9 +180,14 @@ public void close() { }; } this.in = in; - client = LspServerUtils.findLspClient(Lookup.getDefault()); - if (client != null) { - client.resetOutput(name); + // In case of Run, Debug and Test use IOContext for output. IOContext will end up in the Debug Console + if (!(name.startsWith("Run") || name.startsWith("Debug") || name.startsWith("Test"))) { //NOI18N + client = LspServerUtils.findLspClient(Lookup.getDefault()); + if (client != null) { + client.resetOutput(name); + } + } else { + client = null; } } @@ -201,8 +206,16 @@ private final class LspWriter extends Writer { @Override public void write(char[] cbuf, int off, int len) throws IOException { String chunk = new String(cbuf, off, len); - if (len > 0) { - client.writeOutput(new OutputMessage(name, chunk, stdIO)); + if (client != null) { + if (len > 0) { + client.writeOutput(new OutputMessage(name, chunk, stdIO)); + } + } else { + if (stdIO) { + ctx.stdOut(chunk); + } else { + ctx.stdErr(chunk); + } } } @@ -215,6 +228,13 @@ public void close() throws IOException { closed = true; } } + + protected NbCodeLanguageClient getClient() { + return client; + } } +// private static boolean namedOutput(String name) { +// return !(name.startsWith("Run") || name.startsWith("Debug")); +// } } diff --git a/java/java.lsp.server/vscode/src/extension.ts b/java/java.lsp.server/vscode/src/extension.ts index d43b8dcd16c0..5592188f7a2a 100644 --- a/java/java.lsp.server/vscode/src/extension.ts +++ b/java/java.lsp.server/vscode/src/extension.ts @@ -458,11 +458,18 @@ class LineBufferingPseudoterminal implements vscode.Pseudoterminal { name: this.name, pty: this, }); + + // Listen for terminal close events + vscode.window.onDidCloseTerminal((closedTerminal) => { + if (closedTerminal === this.terminal) { + this.terminal = undefined; // Clear the terminal reference + } + }); } // Prevent 'stealing' of the focus when running tests in parallel - if (!testAdapter?.testInParallelProfileExist()) { +// if (!testAdapter?.testInParallelProfileExist()) { this.terminal.show(true); - } +// } } /**