[gnome-builder: 89/139] gnome-code-assistance: port to new libide-code



commit d58e3128d07817088a37bd08a48bdd13aeac41b1
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 17:25:15 2019 -0800

    gnome-code-assistance: port to new libide-code

 src/plugins/gnome-code-assistance/gca-plugin.c     | 13 ++---
 .../gnome-code-assistance.gresource.xml            |  2 +-
 .../gnome-code-assistance.plugin                   | 10 ++--
 .../ide-gca-diagnostic-provider.c                  | 67 +++++++++-------------
 .../ide-gca-diagnostic-provider.h                  |  2 +-
 .../ide-gca-preferences-addin.c                    |  2 +-
 .../gnome-code-assistance/ide-gca-service.c        | 17 ++++--
 .../gnome-code-assistance/ide-gca-service.h        | 19 +++---
 src/plugins/gnome-code-assistance/meson.build      | 28 ++++-----
 9 files changed, 73 insertions(+), 87 deletions(-)
---
diff --git a/src/plugins/gnome-code-assistance/gca-plugin.c b/src/plugins/gnome-code-assistance/gca-plugin.c
index cca849e9f..6e883b760 100644
--- a/src/plugins/gnome-code-assistance/gca-plugin.c
+++ b/src/plugins/gnome-code-assistance/gca-plugin.c
@@ -19,23 +19,18 @@
  */
 
 #include <libpeas/peas.h>
-#include <ide.h>
+#include <libide-code.h>
+#include <libide-gui.h>
 
 #include "ide-gca-diagnostic-provider.h"
 #include "ide-gca-preferences-addin.h"
-#include "ide-gca-service.h"
 
-void
-ide_gca_register_types (PeasObjectModule *module)
+_IDE_EXTERN void
+_ide_gca_register_types (PeasObjectModule *module)
 {
-  peas_object_module_register_extension_type (module,
-                                              IDE_TYPE_SERVICE,
-                                              IDE_TYPE_GCA_SERVICE);
-
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_DIAGNOSTIC_PROVIDER,
                                               IDE_TYPE_GCA_DIAGNOSTIC_PROVIDER);
-
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_PREFERENCES_ADDIN,
                                               IDE_TYPE_GCA_PREFERENCES_ADDIN);
diff --git a/src/plugins/gnome-code-assistance/gnome-code-assistance.gresource.xml 
b/src/plugins/gnome-code-assistance/gnome-code-assistance.gresource.xml
index bb5165856..5d180eaf2 100644
--- a/src/plugins/gnome-code-assistance/gnome-code-assistance.gresource.xml
+++ b/src/plugins/gnome-code-assistance/gnome-code-assistance.gresource.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <gresource prefix="/org/gnome/builder/plugins">
+  <gresource prefix="/plugins/gnome-code-assistance">
     <file>gnome-code-assistance.plugin</file>
   </gresource>
 </gresources>
diff --git a/src/plugins/gnome-code-assistance/gnome-code-assistance.plugin 
b/src/plugins/gnome-code-assistance/gnome-code-assistance.plugin
index cff1ab921..326b8b55c 100644
--- a/src/plugins/gnome-code-assistance/gnome-code-assistance.plugin
+++ b/src/plugins/gnome-code-assistance/gnome-code-assistance.plugin
@@ -1,9 +1,9 @@
 [Plugin]
-Module=gnome-code-assistance-plugin
-Name=GNOME Code Assistance
-Description=Provides integration with gnome-code-assistance
 Authors=Christian Hergert <christian hergert me>
-Copyright=Copyright © 2015 Christian Hergert
 Builtin=true
+Copyright=Copyright © 2015 Christian Hergert
+Description=Provides integration with gnome-code-assistance
+Embedded=_ide_gca_register_types
+Module=gnome-code-assistance
+Name=GNOME Code Assistance
 X-Diagnostic-Provider-Languages=css,html,js,json,python,python3,ruby,scss,sh,xml,yaml
-Embedded=ide_gca_register_types
diff --git a/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c 
b/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c
index ddd48e9be..cbfc6cf19 100644
--- a/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c
+++ b/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c
@@ -38,7 +38,7 @@ typedef struct
 {
   IdeTask        *task; /* Integrity check backpointer */
   IdeUnsavedFile *unsaved_file;
-  IdeFile        *file;
+  GFile          *file;
   gchar          *language_id;
 } DiagnoseState;
 
@@ -107,7 +107,7 @@ variant_to_diagnostics (DiagnoseState *state,
 
   g_assert (variant);
 
-  ar = g_ptr_array_new_with_free_func ((GDestroyNotify)ide_diagnostic_unref);
+  ar = g_ptr_array_new_with_free_func (g_object_unref);
 
   g_variant_iter_init (&iter, variant);
 
@@ -145,10 +145,9 @@ variant_to_diagnostics (DiagnoseState *state,
 
       while (g_variant_iter_next (c, "(x(xx)(xx))", &x1, &x2, &x3, &x4, &x5))
         {
-          IdeSourceRange *range;
-          IdeSourceLocation *begin;
-          IdeSourceLocation *end;
-          IdeFile *file = NULL;
+          g_autoptr(IdeRange) range = NULL;
+          g_autoptr(IdeLocation) begin = NULL;
+          g_autoptr(IdeLocation) end = NULL;
 
           /*
            * FIXME:
@@ -156,22 +155,18 @@ variant_to_diagnostics (DiagnoseState *state,
            * Not always true, but we can cheat for now and claim it is within
            * the file we just parsed.
            */
-          file = state->file;
 
-          begin = ide_source_location_new (file, x2 - 1, x3 - 1, 0);
-          end = ide_source_location_new (file, x4 - 1, x5 - 1, 0);
+          begin = ide_location_new (state->file, x2 - 1, x3 - 1);
+          end = ide_location_new (state->file, x4 - 1, x5 - 1);
 
-          range = ide_source_range_new (begin, end);
-          ide_diagnostic_take_range (diag, range);
-
-          ide_source_location_unref (begin);
-          ide_source_location_unref (end);
+          range = ide_range_new (begin, end);
+          ide_diagnostic_take_range (diag, g_steal_pointer (&range));
         }
 
       g_ptr_array_add (ar, g_steal_pointer (&diag));
     }
 
-  return ide_diagnostics_new (IDE_PTR_ARRAY_STEAL_FULL (&ar));
+  return ide_diagnostics_new_from_array (ar);
 }
 
 static void
@@ -203,8 +198,7 @@ diagnostics_cb (GObject      *object,
 
   diagnostics = variant_to_diagnostics (state, var);
 
-  ide_task_return_pointer (task, diagnostics,
-                           (GDestroyNotify)ide_diagnostics_unref);
+  ide_task_return_pointer (task, diagnostics, g_object_unref);
 
   IDE_EXIT;
 }
@@ -274,8 +268,9 @@ parse_cb (GObject      *object,
     {
       if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN))
         {
-          ide_task_return_pointer (task, ide_diagnostics_new (NULL),
-                                   (GDestroyNotify)ide_diagnostics_unref);
+          ide_task_return_pointer (task,
+                                   ide_diagnostics_new (),
+                                   g_object_unref);
         }
       else
         {
@@ -347,7 +342,6 @@ get_proxy_cb (GObject      *object,
   const gchar *temp_path;
   GcaService *proxy;
   GVariant *cursor = NULL;
-  GFile *gfile;
 
   IDE_ENTRY;
 
@@ -365,8 +359,7 @@ get_proxy_cb (GObject      *object,
       IDE_GOTO (cleanup);
     }
 
-  gfile = ide_file_get_file (state->file);
-  temp_path = path = g_file_get_path (gfile);
+  temp_path = path = g_file_get_path (state->file);
 
   if (!path)
     {
@@ -411,8 +404,9 @@ cleanup:
 
 static void
 ide_gca_diagnostic_provider_diagnose_async (IdeDiagnosticProvider *provider,
-                                            IdeFile               *file,
-                                            IdeBuffer             *buffer,
+                                            GFile                 *file,
+                                            GBytes                *contents,
+                                            const gchar           *language_id,
                                             GCancellable          *cancellable,
                                             GAsyncReadyCallback    callback,
                                             gpointer               user_data)
@@ -421,22 +415,15 @@ ide_gca_diagnostic_provider_diagnose_async (IdeDiagnosticProvider *provider,
   g_autoptr(IdeTask) task = NULL;
   IdeGcaService *service;
   DiagnoseState *state;
-  GtkSourceLanguage *language;
-  IdeContext *context;
   IdeUnsavedFiles *files;
-  const gchar *language_id = NULL;
-  GFile *gfile;
+  IdeContext *context;
 
   IDE_ENTRY;
 
   g_return_if_fail (IDE_IS_GCA_DIAGNOSTIC_PROVIDER (self));
 
   task = ide_task_new (self, cancellable, callback, user_data);
-
-  language = ide_file_get_language (file);
-
-  if (language != NULL)
-    language_id = gtk_source_language_get_id (language);
+  ide_task_set_source_tag (task, ide_gca_diagnostic_provider_diagnose_async);
 
   if (language_id == NULL)
     {
@@ -448,20 +435,22 @@ ide_gca_diagnostic_provider_diagnose_async (IdeDiagnosticProvider *provider,
     }
 
   context = ide_object_get_context (IDE_OBJECT (provider));
-  service = ide_context_get_service_typed (context, IDE_TYPE_GCA_SERVICE);
-  files = ide_context_get_unsaved_files (context);
-  gfile = ide_file_get_file (file);
+  service = ide_gca_service_from_context (context);
+  files = ide_unsaved_files_from_context (context);
 
   state = g_slice_new0 (DiagnoseState);
   state->task = task;
   state->language_id = g_strdup (language_id);
   state->file = g_object_ref (file);
-  state->unsaved_file = ide_unsaved_files_get_unsaved_file (files, gfile);
+  state->unsaved_file = ide_unsaved_files_get_unsaved_file (files, file);
 
   ide_task_set_task_data (task, state, diagnose_state_free);
 
-  ide_gca_service_get_proxy_async (service, language_id, cancellable,
-                                   get_proxy_cb, g_object_ref (task));
+  ide_gca_service_get_proxy_async (service,
+                                   language_id,
+                                   cancellable,
+                                   get_proxy_cb,
+                                   g_steal_pointer (&task));
 
   IDE_EXIT;
 }
diff --git a/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.h 
b/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.h
index e97bf8b5b..13f9b4082 100644
--- a/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.h
+++ b/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.h
@@ -20,7 +20,7 @@
 
 #pragma once
 
-#include <ide.h>
+#include <libide-code.h>
 
 G_BEGIN_DECLS
 
diff --git a/src/plugins/gnome-code-assistance/ide-gca-preferences-addin.c 
b/src/plugins/gnome-code-assistance/ide-gca-preferences-addin.c
index 2b0e216e9..58c97f3df 100644
--- a/src/plugins/gnome-code-assistance/ide-gca-preferences-addin.c
+++ b/src/plugins/gnome-code-assistance/ide-gca-preferences-addin.c
@@ -19,7 +19,7 @@
  */
 
 #include <glib/gi18n.h>
-#include <ide.h>
+#include <libide-gui.h>
 
 #include "ide-gca-preferences-addin.h"
 
diff --git a/src/plugins/gnome-code-assistance/ide-gca-service.c 
b/src/plugins/gnome-code-assistance/ide-gca-service.c
index 5ad371760..11f8574d5 100644
--- a/src/plugins/gnome-code-assistance/ide-gca-service.c
+++ b/src/plugins/gnome-code-assistance/ide-gca-service.c
@@ -22,6 +22,7 @@
 
 #include <dazzle.h>
 #include <glib/gi18n.h>
+#include <libide-threading.h>
 
 #include "ide-gca-service.h"
 
@@ -35,8 +36,7 @@ struct _IdeGcaService
   gulong           bus_closed_handler;
 };
 
-G_DEFINE_TYPE_EXTENDED (IdeGcaService, ide_gca_service, IDE_TYPE_OBJECT, 0,
-                        G_IMPLEMENT_INTERFACE (IDE_TYPE_SERVICE, NULL))
+G_DEFINE_TYPE (IdeGcaService, ide_gca_service, IDE_TYPE_OBJECT)
 
 static void
 on_bus_closed (GDBusConnection *bus,
@@ -218,8 +218,6 @@ ide_gca_service_get_proxy_async (IdeGcaService       *self,
  * Completes an asynchronous request to load a Gca proxy.
  *
  * Returns: (transfer full): a #GcaService or %NULL upon failure.
- *
- * Since: 3.32
  */
 GcaService *
 ide_gca_service_get_proxy_finish (IdeGcaService  *self,
@@ -264,3 +262,14 @@ ide_gca_service_init (IdeGcaService *self)
   self->proxy_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
                                              g_free, g_object_unref);
 }
+
+IdeGcaService *
+ide_gca_service_from_context (IdeContext *context)
+{
+  g_autoptr(IdeGcaService) self = NULL;
+
+  g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
+
+  self = ide_object_ensure_child_typed (IDE_OBJECT (context), IDE_TYPE_GCA_SERVICE);
+  return ide_context_peek_child_typed (context, IDE_TYPE_GCA_SERVICE);
+}
diff --git a/src/plugins/gnome-code-assistance/ide-gca-service.h 
b/src/plugins/gnome-code-assistance/ide-gca-service.h
index 01308fc85..7ce7ddab6 100644
--- a/src/plugins/gnome-code-assistance/ide-gca-service.h
+++ b/src/plugins/gnome-code-assistance/ide-gca-service.h
@@ -20,7 +20,7 @@
 
 #pragma once
 
-#include <ide.h>
+#include <libide-core.h>
 
 #include "gca-service.h"
 
@@ -30,13 +30,14 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (IdeGcaService, ide_gca_service, IDE, GCA_SERVICE, IdeObject)
 
-void        ide_gca_service_get_proxy_async  (IdeGcaService        *self,
-                                              const gchar          *language_id,
-                                              GCancellable         *cancellable,
-                                              GAsyncReadyCallback   callback,
-                                              gpointer              user_data);
-GcaService *ide_gca_service_get_proxy_finish (IdeGcaService        *self,
-                                              GAsyncResult         *result,
-                                              GError              **error);
+IdeGcaService *ide_gca_service_from_context     (IdeContext           *context);
+void           ide_gca_service_get_proxy_async  (IdeGcaService        *self,
+                                                 const gchar          *language_id,
+                                                 GCancellable         *cancellable,
+                                                 GAsyncReadyCallback   callback,
+                                                 gpointer              user_data);
+GcaService    *ide_gca_service_get_proxy_finish (IdeGcaService        *self,
+                                                 GAsyncResult         *result,
+                                                 GError              **error);
 
 G_END_DECLS
diff --git a/src/plugins/gnome-code-assistance/meson.build b/src/plugins/gnome-code-assistance/meson.build
index fee9b7a1d..a7d86fa14 100644
--- a/src/plugins/gnome-code-assistance/meson.build
+++ b/src/plugins/gnome-code-assistance/meson.build
@@ -1,31 +1,23 @@
-if get_option('with_gnome_code_assistance')
+if get_option('plugin_gnome_code_assistance')
 
-gca_resources = gnome.compile_resources(
-  'gca-resources',
-  'gnome-code-assistance.gresource.xml',
-  c_name: 'ide_gca',
-)
+install_data('org.gnome.builder.gnome-code-assistance.gschema.xml', install_dir: schema_dir)
 
-gca_sources = [
+plugins_sources += files([
   'gca-diagnostics.c',
-  'gca-diagnostics.h',
   'gca-service.c',
-  'gca-service.h',
   'gca-structs.c',
-  'gca-structs.h',
   'gca-plugin.c',
   'ide-gca-diagnostic-provider.c',
-  'ide-gca-diagnostic-provider.h',
   'ide-gca-preferences-addin.c',
-  'ide-gca-preferences-addin.h',
   'ide-gca-service.c',
-  'ide-gca-service.h',
-]
+])
 
-gnome_builder_plugins_sources += files(gca_sources)
-gnome_builder_plugins_sources += gca_resources[0]
+plugin_gnome_code_assistance_resources = gnome.compile_resources(
+  'gnome-code-assistance-resources',
+  'gnome-code-assistance.gresource.xml',
+  c_name: 'gbp_gnome_code_assistance',
+)
 
-install_data('org.gnome.builder.gnome-code-assistance.gschema.xml',
-  install_dir: schema_dir)
+plugins_sources += plugin_gnome_code_assistance_resources[0]
 
 endif


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