[gnome-builder] lsp: add support for LSP "trace" setting during initialization



commit 56573ed4f3d73cb73cd6cebdaca6b39749d487ba
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 22 10:55:30 2019 -0800

    lsp: add support for LSP "trace" setting during initialization

 src/libide/lsp/ide-lsp-client.c | 66 +++++++++++++++++++++++++++++++++++++++++
 src/libide/lsp/ide-lsp-client.h | 12 ++++++++
 src/libide/lsp/libide-lsp.h     |  1 +
 src/libide/lsp/meson.build      | 18 ++++++++++-
 4 files changed, 96 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/lsp/ide-lsp-client.c b/src/libide/lsp/ide-lsp-client.c
index 8a04f9800..6a698e7cd 100644
--- a/src/libide/lsp/ide-lsp-client.c
+++ b/src/libide/lsp/ide-lsp-client.c
@@ -33,6 +33,7 @@
 #include <unistd.h>
 
 #include "ide-lsp-client.h"
+#include "ide-lsp-enums.h"
 
 typedef struct
 {
@@ -42,6 +43,7 @@ typedef struct
   GIOStream      *io_stream;
   GHashTable     *diagnostics_by_file;
   GPtrArray      *languages;
+  IdeLspTrace     trace;
 } IdeLspClientPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (IdeLspClient, ide_lsp_client, IDE_TYPE_OBJECT)
@@ -62,6 +64,7 @@ enum {
 enum {
   PROP_0,
   PROP_IO_STREAM,
+  PROP_TRACE,
   N_PROPS
 };
 
@@ -728,6 +731,10 @@ ide_lsp_client_get_property (GObject    *object,
       g_value_set_object (value, priv->io_stream);
       break;
 
+    case PROP_TRACE:
+      g_value_set_enum (value, ide_lsp_client_get_trace (self));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -748,6 +755,10 @@ ide_lsp_client_set_property (GObject      *object,
       priv->io_stream = g_value_dup_object (value);
       break;
 
+    case PROP_TRACE:
+      ide_lsp_client_set_trace (self, g_value_get_enum (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -772,6 +783,14 @@ ide_lsp_client_class_init (IdeLspClientClass *klass)
                          G_TYPE_IO_STREAM,
                          (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_TRACE] =
+    g_param_spec_enum ("trace",
+                       "Trace",
+                       "If tracing should be enabled on the peer.",
+                       IDE_TYPE_LSP_TRACE,
+                       IDE_LSP_TRACE_OFF,
+                       (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, N_PROPS, properties);
 
   signals [NOTIFICATION] =
@@ -816,6 +835,7 @@ ide_lsp_client_init (IdeLspClient *self)
 
   g_assert (IDE_IS_MAIN_THREAD ());
 
+  priv->trace = IDE_LSP_TRACE_OFF;
   priv->languages = g_ptr_array_new_with_free_func (g_free);
 
   priv->diagnostics_by_file = g_hash_table_new_full ((GHashFunc)g_file_hash,
@@ -957,6 +977,7 @@ ide_lsp_client_start (IdeLspClient *self)
   g_autoptr(GVariant) params = NULL;
   g_autofree gchar *root_path = NULL;
   g_autofree gchar *root_uri = NULL;
+  const gchar *trace_string;
   IdeContext *context;
   GFile *workdir;
 
@@ -981,6 +1002,22 @@ ide_lsp_client_start (IdeLspClient *self)
   root_path = g_file_get_path (workdir);
   root_uri = g_file_get_uri (workdir);
 
+  switch (priv->trace)
+    {
+    case IDE_LSP_TRACE_VERBOSE:
+      trace_string = "verbose";
+      break;
+
+    case IDE_LSP_TRACE_MESSAGES:
+      trace_string = "messages";
+      break;
+
+    case IDE_LSP_TRACE_OFF:
+    default:
+      trace_string = "off";
+      break;
+    }
+
   /*
    * The first thing we need to do is initialize the client with information
    * about our project. So that we will perform asynchronously here. It will
@@ -991,6 +1028,7 @@ ide_lsp_client_start (IdeLspClient *self)
     "processId", JSONRPC_MESSAGE_PUT_INT64 (getpid ()),
     "rootUri", JSONRPC_MESSAGE_PUT_STRING (root_uri),
     "rootPath", JSONRPC_MESSAGE_PUT_STRING (root_path),
+    "trace", JSONRPC_MESSAGE_PUT_STRING (trace_string),
     "capabilities", "{", "}"
   );
 
@@ -1360,3 +1398,31 @@ ide_lsp_client_add_language (IdeLspClient *self,
 
   g_ptr_array_add (priv->languages, g_strdup (language_id));
 }
+
+IdeLspTrace
+ide_lsp_client_get_trace (IdeLspClient *self)
+{
+  IdeLspClientPrivate *priv = ide_lsp_client_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_LSP_CLIENT (self), IDE_LSP_TRACE_OFF);
+
+  return priv->trace;
+}
+
+void
+ide_lsp_client_set_trace (IdeLspClient *self,
+                          IdeLspTrace   trace)
+{
+  IdeLspClientPrivate *priv = ide_lsp_client_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_LSP_CLIENT (self));
+  g_return_if_fail (trace == IDE_LSP_TRACE_OFF ||
+                    trace == IDE_LSP_TRACE_MESSAGES ||
+                    trace == IDE_LSP_TRACE_VERBOSE);
+
+  if (trace != priv->trace)
+    {
+      priv->trace = trace;
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TRACE]);
+    }
+}
diff --git a/src/libide/lsp/ide-lsp-client.h b/src/libide/lsp/ide-lsp-client.h
index 2a453f600..e8e047ff2 100644
--- a/src/libide/lsp/ide-lsp-client.h
+++ b/src/libide/lsp/ide-lsp-client.h
@@ -33,6 +33,13 @@ G_BEGIN_DECLS
 IDE_AVAILABLE_IN_3_32
 G_DECLARE_DERIVABLE_TYPE (IdeLspClient, ide_lsp_client, IDE, LSP_CLIENT, IdeObject)
 
+typedef enum
+{
+  IDE_LSP_TRACE_OFF,
+  IDE_LSP_TRACE_MESSAGES,
+  IDE_LSP_TRACE_VERBOSE,
+} IdeLspTrace;
+
 struct _IdeLspClientClass
 {
   IdeObjectClass parent_class;
@@ -52,6 +59,11 @@ struct _IdeLspClientClass
 
 IDE_AVAILABLE_IN_3_32
 IdeLspClient *ide_lsp_client_new                      (GIOStream            *io_stream);
+IDE_AVAILABLE_IN_3_36
+IdeLspTrace   ide_lsp_client_get_trace                (IdeLspClient         *self);
+IDE_AVAILABLE_IN_3_36
+void          ide_lsp_client_set_trace                (IdeLspClient         *self,
+                                                       IdeLspTrace           trace);
 IDE_AVAILABLE_IN_3_32
 void          ide_lsp_client_add_language             (IdeLspClient         *self,
                                                        const gchar          *language_id);
diff --git a/src/libide/lsp/libide-lsp.h b/src/libide/lsp/libide-lsp.h
index a91bcedb4..7f7c713a4 100644
--- a/src/libide/lsp/libide-lsp.h
+++ b/src/libide/lsp/libide-lsp.h
@@ -31,6 +31,7 @@
 #include "ide-lsp-completion-provider.h"
 #include "ide-lsp-completion-results.h"
 #include "ide-lsp-diagnostic-provider.h"
+#include "ide-lsp-enums.h"
 #include "ide-lsp-formatter.h"
 #include "ide-lsp-highlighter.h"
 #include "ide-lsp-hover-provider.h"
diff --git a/src/libide/lsp/meson.build b/src/libide/lsp/meson.build
index c8140ca03..af63abff0 100644
--- a/src/libide/lsp/meson.build
+++ b/src/libide/lsp/meson.build
@@ -1,3 +1,4 @@
+libide_lsp_header_dir = join_paths(libide_header_dir, 'lsp')
 libide_lsp_header_subdir = join_paths(libide_header_subdir, 'lsp')
 libide_include_directories += include_directories('.')
 
@@ -53,7 +54,22 @@ libide_lsp_private_sources = [
   'ide-lsp-util.c',
 ]
 
-libide_lsp_sources = libide_lsp_public_sources + libide_lsp_private_sources
+libide_lsp_enum_headers = [
+  'ide-lsp-client.h',
+]
+
+libide_lsp_enums = gnome.mkenums_simple('ide-lsp-enums',
+     body_prefix: '#include "config.h"',
+   header_prefix: '#include <libide-core.h>',
+       decorator: '_IDE_EXTERN',
+         sources: libide_lsp_enum_headers,
+  install_header: true,
+     install_dir: libide_lsp_header_dir,
+)
+libide_lsp_generated_sources = [libide_lsp_enums[0]]
+libide_lsp_generated_headers = [libide_lsp_enums[1]]
+
+libide_lsp_sources = libide_lsp_public_sources + libide_lsp_private_sources + libide_lsp_generated_sources
 
 #
 # Dependencies


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]