Skip to content

Commit

Permalink
Create new output channel for every LspIO
Browse files Browse the repository at this point in the history
  • Loading branch information
jhorvath committed Dec 5, 2024
1 parent 5767a5f commit 73902be
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,25 @@ public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) {
public CompletableFuture<Boolean> requestDocumentSave(SaveDocumentRequestParams documentUris) {
return remote.requestDocumentSave(documentUris);
}

@Override
public CompletableFuture<Void> writeOutput(OutputMessage lm) {
return remote.writeOutput(lm);
}

@Override
public CompletableFuture<Void> showOutput(String outputName) {
return remote.showOutput(outputName);
}

@Override
public CompletableFuture<Void> closeOutput(String outputName) {
return remote.closeOutput(outputName);
}

@Override
public CompletableFuture<Void> resetOutput(String outputName) {
return remote.resetOutput(outputName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,16 @@ public default boolean isRequestDispatcherThread() {
@JsonRequest("window/documentSave")
public CompletableFuture<Boolean> requestDocumentSave(@NonNull SaveDocumentRequestParams documentUri);

@JsonRequest("output/write")
public CompletableFuture<Void> writeOutput(OutputMessage message);

@JsonRequest("output/show")
public CompletableFuture<Void> showOutput(String outputName);

@JsonRequest("output/close")
public CompletableFuture<Void> closeOutput(String outputName);

@JsonRequest("output/reset")
public CompletableFuture<Void> resetOutput(String outputName);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.java.lsp.server.protocol;

/**
*
* @author Jan Horvath
*/
public final class OutputMessage {

String outputName;
String message;
boolean stdIO;

public OutputMessage(String outputName, String message, boolean stdIO) {
this.outputName = outputName;
this.message = message;
this.stdIO = stdIO;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,27 @@ public CompletableFuture<Boolean> requestDocumentSave(SaveDocumentRequestParams
logWarning(Arrays.asList(documentUris));
return CompletableFuture.completedFuture(false);
}

@Override
public CompletableFuture<Void> writeOutput(OutputMessage lm) {
logWarning(lm.message);
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Void> showOutput(String outputName) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Void> closeOutput(String outputName) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Void> resetOutput(String outputName) {
return CompletableFuture.completedFuture(null);
}
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.netbeans.modules.java.lsp.server.ui;

import org.netbeans.modules.java.lsp.server.protocol.OutputMessage;
import java.io.CharArrayReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -29,6 +30,8 @@
import org.netbeans.api.io.Hyperlink;
import org.netbeans.api.io.OutputColor;
import org.netbeans.api.io.ShowOperation;
import org.netbeans.modules.java.lsp.server.LspServerUtils;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
import org.netbeans.modules.java.lsp.server.ui.AbstractLspInputOutputProvider.LspIO;
import org.netbeans.spi.io.InputOutputProvider;
import org.openide.util.Lookup;
Expand Down Expand Up @@ -82,14 +85,26 @@ public final Lookup getIOLookup(LspIO io) {

@Override
public final void resetIO(LspIO io) {
NbCodeLanguageClient client = LspServerUtils.findLspClient(Lookup.getDefault());
if (client != null) {
client.resetOutput(io.name);
}
}

@Override
public final void showIO(LspIO io, Set<ShowOperation> operations) {
NbCodeLanguageClient client = LspServerUtils.findLspClient(Lookup.getDefault());
if (client != null) {
client.showOutput(io.name);
}
}

@Override
public final void closeIO(LspIO io) {
NbCodeLanguageClient client = LspServerUtils.findLspClient(Lookup.getDefault());
if (client != null) {
client.closeOutput(io.name);
}
}

@Override
Expand Down Expand Up @@ -131,6 +146,7 @@ public final void setIODescription(LspIO io, String description) {
public static final class LspIO {
private final String name;
private final IOContext ctx;
private final NbCodeLanguageClient client;
final Lookup lookup;
final Reader in;
final LspWriter out;
Expand Down Expand Up @@ -164,12 +180,16 @@ public void close() {
};
}
this.in = in;
client = LspServerUtils.findLspClient(Lookup.getDefault());
if (client != null) {
client.resetOutput(name);
}
}

boolean isClosed() {
return out.closed && err.closed;
}

private final class LspWriter extends Writer {
private final boolean stdIO;
volatile boolean closed;
Expand All @@ -181,10 +201,8 @@ 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 (stdIO) {
ctx.stdOut(chunk);
} else {
ctx.stdErr(chunk);
if (len > 0) {
client.writeOutput(new OutputMessage(name, chunk, stdIO));
}
}

Expand All @@ -198,5 +216,5 @@ public void close() throws IOException {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.java.lsp.server.protocol.OutputMessage;
import org.netbeans.modules.java.lsp.server.protocol.SaveDocumentRequestParams;
import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams;
import org.netbeans.modules.java.lsp.server.protocol.TestProgressParams;
Expand Down Expand Up @@ -160,4 +161,25 @@ public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) {
public CompletableFuture<Boolean> requestDocumentSave(SaveDocumentRequestParams documentUris) {
return CompletableFuture.completedFuture(false);
}

@Override
public CompletableFuture<Void> writeOutput(OutputMessage message) {
System.out.println(message);
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Void> showOutput(String outputName) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Void> closeOutput(String outputName) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Void> resetOutput(String outputName) {
return CompletableFuture.completedFuture(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.java.lsp.server.protocol.OutputMessage;
import org.netbeans.modules.java.lsp.server.protocol.SaveDocumentRequestParams;
import org.netbeans.modules.java.lsp.server.protocol.SetTextEditorDecorationParams;
import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams;
Expand Down Expand Up @@ -285,6 +286,26 @@ public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) {
public CompletableFuture<Boolean> requestDocumentSave(SaveDocumentRequestParams documentUris) {
return CompletableFuture.completedFuture(false);
}

@Override
public CompletableFuture<Void> writeOutput(OutputMessage message) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Void> showOutput(String outputName) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Void> closeOutput(String outputName) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Void> resetOutput(String outputName) {
return CompletableFuture.completedFuture(null);
}
}

private static Launcher<NbLanguageServer> createLauncher(NbCodeLanguageClient client, InputStream in, OutputStream out,
Expand Down
Loading

0 comments on commit 73902be

Please sign in to comment.