[gnome-builder] lsp: add lazy binding alternative for IdeLspService



commit 8cb57aa5dde3e1262c8c5e4df8000b10947fb99c
Author: Christian Hergert <chergert redhat com>
Date:   Tue Dec 21 17:41:05 2021 -0800

    lsp: add lazy binding alternative for IdeLspService

 src/libide/lsp/ide-lsp-service.c | 49 +++++++++++++++++++++++++++++++---------
 src/libide/lsp/ide-lsp-service.h | 27 ++++++++++++----------
 2 files changed, 53 insertions(+), 23 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-service.c b/src/libide/lsp/ide-lsp-service.c
index 8d1f9b3c1..1bbbe130b 100644
--- a/src/libide/lsp/ide-lsp-service.c
+++ b/src/libide/lsp/ide-lsp-service.c
@@ -644,17 +644,10 @@ on_notify_pipeline_cb (IdeLspService   *self,
   IDE_EXIT;
 }
 
-/**
- * ide_lsp_service_class_bind_client:
- * @klass: a [class@LspService] class structure
- * @provider: an [class@Object]
- *
- * Binds the "client" property of @property to its context's instance of @klass. If the language
- * server is not running yet, it will be started.
- */
-void
-ide_lsp_service_class_bind_client (IdeLspServiceClass *klass,
-                                   IdeObject          *provider)
+static void
+ide_lsp_service_class_bind_client_internal (IdeLspServiceClass *klass,
+                                            IdeObject          *provider,
+                                            gboolean            autostart)
 {
   IdeContext *context;
   GParamSpec *pspec;
@@ -677,6 +670,7 @@ ide_lsp_service_class_bind_client (IdeLspServiceClass *klass,
    */
   if (ide_context_has_project (context))
     {
+      IdeLspServicePrivate *priv;
       IdeBuildManager *build_manager = ide_build_manager_from_context (context);
       g_autoptr(IdeLspService) service = NULL;
       gboolean do_notify = FALSE;
@@ -692,6 +686,9 @@ ide_lsp_service_class_bind_client (IdeLspServiceClass *klass,
           do_notify = TRUE;
         }
 
+      priv = ide_lsp_service_get_instance_private (service);
+      do_notify |= (autostart && !priv->has_started);
+
       if (do_notify)
         on_notify_pipeline_cb (service, NULL, build_manager);
 
@@ -701,6 +698,36 @@ ide_lsp_service_class_bind_client (IdeLspServiceClass *klass,
   IDE_EXIT;
 }
 
+/**
+ * ide_lsp_service_class_bind_client:
+ * @klass: a [class@LspService] class structure
+ * @provider: an [class@Object]
+ *
+ * Binds the "client" property of @property to its context's instance of
+ * @klass. If the language server is not running yet, it will be started.
+ */
+void
+ide_lsp_service_class_bind_client (IdeLspServiceClass *klass,
+                                   IdeObject          *provider)
+{
+  ide_lsp_service_class_bind_client_internal (klass, provider, TRUE);
+}
+
+/**
+ * ide_lsp_service_class_bind_client_lazy:
+ * @klass: a [class@LspService] class structure
+ * @provider: an [class@Object]
+ *
+ * Like ide_lsp_service_bind_client() but will not immediately spawn
+ * the language server.
+ */
+void
+ide_lsp_service_class_bind_client_lazy (IdeLspServiceClass *klass,
+                                        IdeObject          *provider)
+{
+  ide_lsp_service_class_bind_client_internal (klass, provider, FALSE);
+}
+
 const char *
 ide_lsp_service_get_program (IdeLspService *self)
 {
diff --git a/src/libide/lsp/ide-lsp-service.h b/src/libide/lsp/ide-lsp-service.h
index ff1fc8808..54349ce39 100644
--- a/src/libide/lsp/ide-lsp-service.h
+++ b/src/libide/lsp/ide-lsp-service.h
@@ -53,24 +53,27 @@ struct _IdeLspServiceClass
 };
 
 IDE_AVAILABLE_IN_42
-void                ide_lsp_service_class_bind_client  (IdeLspServiceClass *klass,
-                                                        IdeObject          *provider);
+void                ide_lsp_service_class_bind_client      (IdeLspServiceClass *klass,
+                                                            IdeObject          *provider);
 IDE_AVAILABLE_IN_42
-void                ide_lsp_service_set_inherit_stderr (IdeLspService      *self,
-                                                        gboolean            inherit_stderr);
+void                ide_lsp_service_class_bind_client_lazy (IdeLspServiceClass *klass,
+                                                            IdeObject          *provider);
 IDE_AVAILABLE_IN_42
-gboolean            ide_lsp_service_get_inherit_stderr (IdeLspService      *self);
+void                ide_lsp_service_set_inherit_stderr     (IdeLspService      *self,
+                                                            gboolean            inherit_stderr);
 IDE_AVAILABLE_IN_42
-void                ide_lsp_service_restart            (IdeLspService      *self);
+gboolean            ide_lsp_service_get_inherit_stderr     (IdeLspService      *self);
 IDE_AVAILABLE_IN_42
-const char         *ide_lsp_service_get_program        (IdeLspService      *self);
+void                ide_lsp_service_restart                (IdeLspService      *self);
 IDE_AVAILABLE_IN_42
-void                ide_lsp_service_set_program        (IdeLspService      *self,
-                                                        const char         *program);
+const char         *ide_lsp_service_get_program            (IdeLspService      *self);
 IDE_AVAILABLE_IN_42
-const char * const *ide_lsp_service_get_search_path    (IdeLspService      *self);
+void                ide_lsp_service_set_program            (IdeLspService      *self,
+                                                            const char         *program);
 IDE_AVAILABLE_IN_42
-void                ide_lsp_service_set_search_path    (IdeLspService      *self,
-                                                        const char * const *search_path);
+const char * const *ide_lsp_service_get_search_path        (IdeLspService      *self);
+IDE_AVAILABLE_IN_42
+void                ide_lsp_service_set_search_path        (IdeLspService      *self,
+                                                            const char * const *search_path);
 
 G_END_DECLS


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