[gnome-builder] libide/lsp: allow LSP services to use run contexts



commit 413350345d33c86cd88e6f390124e89da48902b7
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 5 18:01:31 2022 -0700

    libide/lsp: allow LSP services to use run contexts
    
    This will allow things to be much easier to configure going forward since
    the launcher can get into weird states by time configure_launcher is
    called.

 src/libide/lsp/ide-lsp-service.c | 38 +++++++++++++++++++++++++++++++++-----
 src/libide/lsp/ide-lsp-service.h |  3 +++
 2 files changed, 36 insertions(+), 5 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-service.c b/src/libide/lsp/ide-lsp-service.c
index e10409a62..9bc44b9b5 100644
--- a/src/libide/lsp/ide-lsp-service.c
+++ b/src/libide/lsp/ide-lsp-service.c
@@ -217,6 +217,8 @@ ide_lsp_service_real_create_launcher (IdeLspService    *self,
       ide_run_context_append_argv (run_context, priv->program);
       ide_run_context_set_cwd (run_context, srcdir);
 
+      IDE_LSP_SERVICE_GET_CLASS (self)->prepare_run_context (self, pipeline, run_context);
+
       if ((launcher = ide_run_context_end (run_context, NULL)))
         {
           ide_subprocess_launcher_set_flags (launcher, flags);
@@ -239,6 +241,8 @@ ide_lsp_service_real_create_launcher (IdeLspService    *self,
           ide_run_context_append_argv (run_context, priv->program);
           ide_run_context_set_cwd (run_context, srcdir);
 
+          IDE_LSP_SERVICE_GET_CLASS (self)->prepare_run_context (self, pipeline, run_context);
+
           if ((launcher = ide_run_context_end (run_context, NULL)))
             {
               ide_subprocess_launcher_set_flags (launcher, flags);
@@ -264,6 +268,8 @@ ide_lsp_service_real_create_launcher (IdeLspService    *self,
                   ide_run_context_append_argv (run_context, path);
                   ide_run_context_set_cwd (run_context, srcdir);
 
+                  IDE_LSP_SERVICE_GET_CLASS (self)->prepare_run_context (self, pipeline, run_context);
+
                   if ((launcher = ide_run_context_end (run_context, NULL)))
                     {
                       ide_subprocess_launcher_set_flags (launcher, flags);
@@ -281,11 +287,18 @@ ide_lsp_service_real_create_launcher (IdeLspService    *self,
 
       if ((path = g_find_program_in_path (priv->program)))
         {
-          launcher = ide_subprocess_launcher_new (flags);
-          ide_subprocess_launcher_push_argv (launcher, path);
-          ide_subprocess_launcher_set_cwd (launcher, srcdir);
-          ide_subprocess_launcher_set_clear_env (launcher, FALSE);
-          IDE_RETURN (g_steal_pointer (&launcher));
+          g_autoptr(IdeRunContext) run_context = ide_run_context_new ();
+
+          ide_run_context_append_argv (run_context, path);
+          ide_run_context_set_cwd (run_context, srcdir);
+
+          IDE_LSP_SERVICE_GET_CLASS (self)->prepare_run_context (self, pipeline, run_context);
+
+          if ((launcher = ide_run_context_end (run_context, NULL)))
+            {
+              ide_subprocess_launcher_set_flags (launcher, flags);
+              IDE_RETURN (g_steal_pointer (&launcher));
+            }
         }
     }
 
@@ -302,6 +315,20 @@ ide_lsp_service_real_configure_client (IdeLspService *self,
   g_assert_not_reached ();
 }
 
+static void
+ide_lsp_service_real_prepare_run_context (IdeLspService *self,
+                                          IdePipeline   *pipeline,
+                                          IdeRunContext *run_context)
+{
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_LSP_SERVICE (self));
+  g_assert (!pipeline || IDE_IS_PIPELINE (pipeline));
+  g_assert (IDE_IS_RUN_CONTEXT (run_context));
+
+  IDE_EXIT;
+}
+
 static void
 ide_lsp_service_real_configure_launcher (IdeLspService         *self,
                                          IdePipeline           *pipeline,
@@ -340,6 +367,7 @@ ide_lsp_service_class_init (IdeLspServiceClass *klass)
   service_class->configure_client = ide_lsp_service_real_configure_client;
   service_class->configure_launcher = ide_lsp_service_real_configure_launcher;
   service_class->configure_supervisor = ide_lsp_service_real_configure_supervisor;
+  service_class->prepare_run_context = ide_lsp_service_real_prepare_run_context;
 
   /**
    * IdeLspService:client:
diff --git a/src/libide/lsp/ide-lsp-service.h b/src/libide/lsp/ide-lsp-service.h
index 631c1d42b..06add0154 100644
--- a/src/libide/lsp/ide-lsp-service.h
+++ b/src/libide/lsp/ide-lsp-service.h
@@ -50,6 +50,9 @@ struct _IdeLspServiceClass
                                                   IdeSubprocessSupervisor *supervisor);
   void                   (*configure_client)     (IdeLspService           *self,
                                                   IdeLspClient            *client);
+  void                   (*prepare_run_context)  (IdeLspService           *service,
+                                                  IdePipeline             *pipeline,
+                                                  IdeRunContext           *run_context);
 };
 
 IDE_AVAILABLE_IN_ALL


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