package io.typefox.lsapi.services.json;

import io.typefox.lsapi.Message;
import io.typefox.lsapi.NotificationMessage;
import io.typefox.lsapi.RequestMessage;
import io.typefox.lsapi.ResponseMessage;
import io.typefox.lsapi.services.LanguageServer;
import io.typefox.lsapi.services.json.LanguageServerProtocol;
import io.typefox.lsapi.services.json.LanguageServerToJsonAdapter;
import java.io.PrintWriter;
import org.eclipse.xtend.lib.annotations.AccessorType;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure2;

@SuppressWarnings("all")
public class LoggingJsonAdapter extends LanguageServerToJsonAdapter {
  @Accessors(AccessorType.PUBLIC_SETTER)
  private PrintWriter errorLog;
  
  @Accessors(AccessorType.PUBLIC_SETTER)
  private PrintWriter messageLog;
  
  public LoggingJsonAdapter(final LanguageServer server) {
    super(server);
    LanguageServerProtocol _protocol = this.getProtocol();
    final Procedure2<String, Throwable> _function = (String message, Throwable throwable) -> {
      if ((this.errorLog != null)) {
        if ((throwable != null)) {
          throwable.printStackTrace(this.errorLog);
        } else {
          if ((message != null)) {
            this.errorLog.println(message);
          }
        }
        this.errorLog.flush();
      }
    };
    _protocol.addErrorListener(_function);
    LanguageServerProtocol _protocol_1 = this.getProtocol();
    final Procedure2<Message, String> _function_1 = (Message message, String json) -> {
      if ((this.messageLog != null)) {
        boolean _matched = false;
        if (message instanceof RequestMessage) {
          _matched=true;
          this.messageLog.println(("Client Request:\n\t" + json));
        }
        if (!_matched) {
          if (message instanceof NotificationMessage) {
            _matched=true;
            this.messageLog.println(("Client Notification:\n\t" + json));
          }
        }
        this.messageLog.flush();
      }
    };
    _protocol_1.addIncomingMessageListener(_function_1);
    LanguageServerProtocol _protocol_2 = this.getProtocol();
    final Procedure2<Message, String> _function_2 = (Message message, String json) -> {
      if ((this.messageLog != null)) {
        boolean _matched = false;
        if (message instanceof ResponseMessage) {
          _matched=true;
          this.messageLog.println(("Server Response:\n\t" + json));
        }
        if (!_matched) {
          if (message instanceof NotificationMessage) {
            _matched=true;
            this.messageLog.println(("Server Notification:\n\t" + json));
          }
        }
        this.messageLog.flush();
      }
    };
    _protocol_2.addOutgoingMessageListener(_function_2);
  }
  
  public void setErrorLog(final PrintWriter errorLog) {
    this.errorLog = errorLog;
  }
  
  public void setMessageLog(final PrintWriter messageLog) {
    this.messageLog = messageLog;
  }
}

@@ -45,159 +45,279 @@
 ort 
-io.typefox.lsapi.Message;%0Aimport io.typefox.lsapi.NotificationMessage;%0Aimport io.typefox.lsapi.RequestMessage;%0Aimport io.typefox.lsapi.ResponseMessage;
+java.io.PrintWriter;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0A%0Aimport org.eclipse.xtend.lib.annotations.AccessorType;%0Aimport org.eclipse.xtend.lib.annotations.Accessors;%0Aimport org.eclipse.xtext.xbase.lib.Procedures.Procedure2;%0A
 %0Aimp
@@ -341,31 +341,15 @@
 api.
-services.LanguageServer
+Message
 ;%0Aim
@@ -374,304 +374,157 @@
 api.
-services.json.LanguageServerProtocol;%0Aimport io.typefox.lsapi.services.json.LanguageServerToJsonAdapter;%0Aimport java.io.PrintWriter;%0Aimport org.eclipse.xtend.lib.annotations.AccessorType;%0Aimport org.eclipse.xtend.lib.annotations.Accessors;%0Aimport org.eclipse.xtext.xbase.lib.Procedures.Procedure2
+NotificationMessage;%0Aimport io.typefox.lsapi.RequestMessage;%0Aimport io.typefox.lsapi.ResponseMessage;%0Aimport io.typefox.lsapi.services.LanguageServer
 ;%0A%0A@
@@ -690,18 +690,16 @@
 rorLog;%0A
-  
 %0A  @Acce
@@ -766,18 +766,16 @@
 ageLog;%0A
-  
 %0A  publi
@@ -842,16 +842,240 @@
 r(server
+, new MessageJsonHandler(), Executors.newCachedThreadPool());%0A  %7D%0A%0A  public LoggingJsonAdapter(final LanguageServer server, final ExecutorService executorService) %7B%0A    super(server, new MessageJsonHandler(), executorService
 );%0A    L
@@ -1181,16 +1181,22 @@
 tion = (
+final 
 String m
@@ -1202,16 +1202,22 @@
 message,
+ final
  Throwab
@@ -1676,24 +1676,30 @@
 nction_1 = (
+final 
 Message mess
@@ -1694,32 +1694,38 @@
 Message message,
+ final
  String json) -%3E
@@ -2374,16 +2374,22 @@
 on_2 = (
+final 
 Message 
@@ -2392,24 +2392,30 @@
 age message,
+ final
  String json
@@ -2956,26 +2956,24 @@
 ion_2);%0A  %7D%0A
-  
 %0A  public vo
@@ -3051,18 +3051,16 @@
 og;%0A  %7D%0A
-  
 %0A  publi

Add ExecutorService parameter to LoggingJsonAdapter