Skip to content

Commit

Permalink
Perform LSP tracing server-side.
Browse files Browse the repository at this point in the history
  • Loading branch information
sdedic committed Sep 9, 2024
1 parent 4c81ffe commit 27ac704
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
*/
public final class Server {
private static final Logger LOG = Logger.getLogger(Server.class.getName());
/**
* Special logger that logs LSP in/out messages.
*/
private static final Logger LSP_LOG = Logger.getLogger("org.netbeans.modules.java.lsp.server.lsptrace"); // NOI18N
private static final LspServerTelemetryManager LSP_SERVER_TELEMETRY = new LspServerTelemetryManager();
private static final ErrorsNotifier ERR_NOTIFIER = new ErrorsNotifier();

Expand Down Expand Up @@ -266,7 +270,17 @@ public MessageConsumer attachLookup(MessageConsumer delegate) {
// PENDING: allow for message consumer wrappers to be registered to add pre/post processing for
// the request plus build the request's default Lookup contents.
if (!(delegate instanceof Endpoint)) {
return delegate;
return new MessageConsumer() {
@Override
public void consume(Message msg) throws MessageIssueException, JsonRpcException {
if (LSP_LOG.isLoggable(Level.FINEST)) {
LSP_LOG.log(Level.FINEST, "OUT: {0}",
msg.toString().replace("\n", "\n\t"));
}
delegate.consume(msg);
}

};
}
return new MessageConsumer() {
@Override
Expand All @@ -275,6 +289,10 @@ public void consume(Message msg) throws MessageIssueException, JsonRpcException
ProxyLookup ll = new ProxyLookup(new AbstractLookup(ic), sessionLookup);
final OperationContext ctx;

if (LSP_LOG.isLoggable(Level.FINEST)) {
LSP_LOG.log(Level.FINEST, "IN : {0}",
msg.toString().replace("\n", "\n\t"));
}
// Intercept client REQUESTS; take the progress token from them, if it is
// attached.
Runnable r;
Expand Down
6 changes: 5 additions & 1 deletion java/java.lsp.server/vscode/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ The default userdir location is inside the **global** vscode settings location:
When the environment variable `nbcode_userdir` (to e.g. `/tmp/foo`) is set when starting vscode or nbcode (npm run nbcode), the userdir will point to `/tmp/foo/userdir`.

### Debug output
_Standalone NBLS_ can be instructed to print messages (stderr, out) to the console: add `-J-Dnetbeans.logger.console=true` to the npm commandline. This has the same effect as `netbeans.verbose = true` settings in the vscode. Messages from the LSP protocol can be displayed in vscode by setting `java.trace.server = verbose` setting in vscode JSON settings.
_Standalone NBLS_ can be instructed to print messages (stderr, out) to the console: add `-J-Dnetbeans.logger.console=true` to the npm commandline. This has the same effect as `netbeans.verbose = true` settings in the vscode.

### LSP protocol tracing
Messages from the LSP protocol can be displayed in vscode by setting `java.trace.server = verbose` setting in vscode JSON settings. Sometimes it may be needed to record LSP requests and responses in the debug output log stream from the Apache NetBeans language server so that requests are properly ordered with logs from executed actions. This can be enabled on language server startup by adding `-J-Dorg.netbeans.modules.java.lsp.server.lsptrace.level=FINEST`
to the NBLS commandline.

### Debugging separately from global NBLS
By default the extension uses **global** userdir of the **global** vscode instance and uses NBLS data in there. In case this is not desired, the `launch.json` must be changed:
Expand Down

0 comments on commit 27ac704

Please sign in to comment.