[gnome-builder/wip/extensions] symbol-resolver: use extension points to access symbol resolvers



commit c6a89607c85c00baacb52ac5b21640d08dc8119f
Author: Christian Hergert <christian hergert me>
Date:   Sat Jun 27 01:15:22 2015 -0700

    symbol-resolver: use extension points to access symbol resolvers
    
    Instead of using IdeLanguage, access symbol-resolvers via their named
    extension point. One less thing for IdeLanguage, which is one less thing
    preventing us from removing that class.

 libide/c/ide-c-language.c         |   23 -----------------
 libide/ide-buffer.c               |   49 +++++++++++++++++++++++++------------
 libide/ide-language.c             |   33 -------------------------
 libide/ide-language.h             |    2 -
 libide/ide.c                      |   11 ++++++++
 libide/ide.h                      |    1 +
 plugins/symbol-tree/symbol-tree.c |   26 ++++++++++++++++++-
 7 files changed, 69 insertions(+), 76 deletions(-)
---
diff --git a/libide/c/ide-c-language.c b/libide/c/ide-c-language.c
index 20187f2..d63a6a2 100644
--- a/libide/c/ide-c-language.c
+++ b/libide/c/ide-c-language.c
@@ -25,7 +25,6 @@
 #include "ide-c-language.h"
 #include "ide-clang-completion-provider.h"
 #include "ide-clang-diagnostic-provider.h"
-#include "ide-clang-symbol-resolver.h"
 #include "ide-diagnostician.h"
 #include "ide-extension-point.h"
 #include "ide-internal.h"
@@ -35,7 +34,6 @@ typedef struct
   IdeDiagnostician  *diagnostician;
   IdeIndenter       *indenter;
   IdeRefactory      *refactory;
-  IdeSymbolResolver *symbol_resolver;
 } IdeCLanguagePrivate;
 
 static void _g_initable_iface_init (GInitableIface *iface);
@@ -92,17 +90,6 @@ ide_c_language_get_refactory (IdeLanguage *language)
   return priv->refactory;
 }
 
-static IdeSymbolResolver *
-ide_c_language_get_symbol_resolver (IdeLanguage *language)
-{
-  IdeCLanguage *self = (IdeCLanguage *)language;
-  IdeCLanguagePrivate *priv = ide_c_language_get_instance_private (self);
-
-  g_return_val_if_fail (IDE_IS_C_LANGUAGE (self), NULL);
-
-  return priv->symbol_resolver;
-}
-
 static const gchar *
 ide_c_language_get_name (IdeLanguage *self)
 {
@@ -118,7 +105,6 @@ ide_c_language_dispose (GObject *object)
   g_clear_object (&priv->diagnostician);
   g_clear_object (&priv->indenter);
   g_clear_object (&priv->refactory);
-  g_clear_object (&priv->symbol_resolver);
 
   G_OBJECT_CLASS (ide_c_language_parent_class)->dispose (object);
 }
@@ -133,7 +119,6 @@ ide_c_language_class_init (IdeCLanguageClass *klass)
   language_class->get_diagnostician = ide_c_language_get_diagnostician;
   language_class->get_indenter = ide_c_language_get_indenter;
   language_class->get_refactory = ide_c_language_get_refactory;
-  language_class->get_symbol_resolver = ide_c_language_get_symbol_resolver;
   language_class->get_name = ide_c_language_get_name;
 
   object_class->dispose = ide_c_language_dispose;
@@ -194,14 +179,6 @@ ide_c_language_initiable_init (GInitable     *initable,
        * TODO: Refactory design (rename local, extract method, etc).
        */
 
-      /*
-       * Create our symbol resolver to help discover symbols within a file
-       * as well as what symbol is at "location X".
-       */
-      priv->symbol_resolver = g_object_new (IDE_TYPE_CLANG_SYMBOL_RESOLVER,
-                                            "context", context,
-                                            NULL);
-
       return TRUE;
     }
 
diff --git a/libide/ide-buffer.c b/libide/ide-buffer.c
index 1b88dc1..0f3559b 100644
--- a/libide/ide-buffer.c
+++ b/libide/ide-buffer.c
@@ -71,6 +71,7 @@ typedef struct
 
   EggSignalGroup         *file_signals;
   EggSignalGroup         *highlighter_extension_signals;
+  EggSignalGroup         *symbol_extension_signals;
 
   GFileMonitor           *file_monitor;
 
@@ -572,6 +573,9 @@ ide_buffer_reload_highlighter (IdeBuffer *self)
 
   g_assert (IDE_IS_BUFFER (self));
 
+  if (priv->file == NULL)
+    return;
+
   language = ide_file_get_language (priv->file);
 
   if (language != NULL)
@@ -601,19 +605,35 @@ ide_buffer_reload_symbol_resolver (IdeBuffer *self)
 {
   IdeBufferPrivate *priv = ide_buffer_get_instance_private (self);
   IdeSymbolResolver *symbol_resolver = NULL;
+  IdeExtensionPoint *point = NULL;
+  IdeLanguage *language;
 
   g_assert (IDE_IS_BUFFER (self));
 
-  if (priv->file != NULL)
+  if (priv->file == NULL)
+    return;
+
+  language = ide_file_get_language (priv->file);
+
+  if (language != NULL)
     {
-      IdeLanguage *language;
+      const gchar *lang_id;
+      gchar *name;
 
-      language = ide_file_get_language (priv->file);
-      if (language != NULL)
-        symbol_resolver = ide_language_get_symbol_resolver (language);
+      lang_id = ide_language_get_id (language);
+      name = g_strdup_printf ("org.gnome.builder.symbol-resolver.%s", lang_id);
+      point = ide_extension_point_lookup (name);
+      symbol_resolver = ide_extension_point_create (name,
+                                                    "context", priv->context,
+                                                    NULL);
+      g_free (name);
     }
 
   g_set_object (&priv->symbol_resolver, symbol_resolver);
+
+  egg_signal_group_set_target (priv->symbol_extension_signals, point);
+
+  g_clear_object (&symbol_resolver);
 }
 
 static void
@@ -966,16 +986,6 @@ ide_buffer_constructed (GObject *object)
 }
 
 static void
-ide_buffer__highlighter_extension_changed (IdeBuffer         *self,
-                                           IdeExtensionPoint *point)
-{
-  g_assert (IDE_IS_BUFFER (self));
-  g_assert (IDE_IS_EXTENSION_POINT (point));
-
-  ide_buffer_reload_highlighter (self);
-}
-
-static void
 ide_buffer_dispose (GObject *object)
 {
   IdeBuffer *self = (IdeBuffer *)object;
@@ -1299,7 +1309,14 @@ ide_buffer_init (IdeBuffer *self)
   priv->highlighter_extension_signals = egg_signal_group_new (IDE_TYPE_EXTENSION_POINT);
   egg_signal_group_connect_object (priv->highlighter_extension_signals,
                                    "changed",
-                                   G_CALLBACK (ide_buffer__highlighter_extension_changed),
+                                   G_CALLBACK (ide_buffer_reload_highlighter),
+                                   self,
+                                   G_CONNECT_SWAPPED);
+
+  priv->symbol_extension_signals = egg_signal_group_new (IDE_TYPE_EXTENSION_POINT);
+  egg_signal_group_connect_object (priv->symbol_extension_signals,
+                                   "changed",
+                                   G_CALLBACK (ide_buffer_reload_symbol_resolver),
                                    self,
                                    G_CONNECT_SWAPPED);
 
diff --git a/libide/ide-language.c b/libide/ide-language.c
index cbaf901..3dff789 100644
--- a/libide/ide-language.c
+++ b/libide/ide-language.c
@@ -26,7 +26,6 @@
 #include "ide-internal.h"
 #include "ide-language.h"
 #include "ide-refactory.h"
-#include "ide-symbol-resolver.h"
 
 typedef struct
 {
@@ -42,7 +41,6 @@ enum {
   PROP_ID,
   PROP_NAME,
   PROP_REFACTORY,
-  PROP_SYMBOL_RESOLVER,
   LAST_PROP
 };
 
@@ -212,26 +210,6 @@ ide_language_get_refactory (IdeLanguage *self)
 }
 
 /**
- * ide_language_get_symbol_resolver:
- *
- * Fetches the #IdeSymbolResolver for @language.
- *
- * If @language does not provide an #IdeSymbolResolver, then %NULL is returned.
- *
- * Returns: (transfer none) (nullable): An #IdeSymbolResolver or %NULL.
- */
-IdeSymbolResolver *
-ide_language_get_symbol_resolver (IdeLanguage *self)
-{
-  g_return_val_if_fail (IDE_IS_LANGUAGE (self), NULL);
-
-  if (IDE_LANGUAGE_GET_CLASS (self)->get_symbol_resolver)
-    return IDE_LANGUAGE_GET_CLASS (self)->get_symbol_resolver (self);
-
-  return NULL;
-}
-
-/**
  * ide_language_get_id:
  *
  * Fetches the unique identifier for the language.
@@ -308,10 +286,6 @@ ide_language_get_property (GObject    *object,
       g_value_set_object (value, ide_language_get_refactory (self));
       break;
 
-    case PROP_SYMBOL_RESOLVER:
-      g_value_set_object (value, ide_language_get_symbol_resolver (self));
-      break;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -384,13 +358,6 @@ ide_language_class_init (IdeLanguageClass *klass)
                          IDE_TYPE_REFACTORY,
                          (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
-  gParamSpecs [PROP_SYMBOL_RESOLVER] =
-    g_param_spec_object ("symbol-resolver",
-                         _("Symbol Resolver"),
-                         _("The symbol resolver for the language."),
-                         IDE_TYPE_SYMBOL_RESOLVER,
-                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
   g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
 }
 
diff --git a/libide/ide-language.h b/libide/ide-language.h
index c7193a8..00c8ba7 100644
--- a/libide/ide-language.h
+++ b/libide/ide-language.h
@@ -39,7 +39,6 @@ struct _IdeLanguageClass
   const gchar       *(*get_name)                 (IdeLanguage *self);
   IdeRefactory      *(*get_refactory)            (IdeLanguage *self);
   GtkSourceLanguage *(*get_source_language)      (IdeLanguage *self);
-  IdeSymbolResolver *(*get_symbol_resolver)      (IdeLanguage *self);
   GList             *(*get_completion_providers) (IdeLanguage *self);
 };
 
@@ -48,7 +47,6 @@ const gchar       *ide_language_get_id                   (IdeLanguage *self);
 IdeIndenter       *ide_language_get_indenter             (IdeLanguage *self);
 const gchar       *ide_language_get_name                 (IdeLanguage *self);
 IdeRefactory      *ide_language_get_refactory            (IdeLanguage *self);
-IdeSymbolResolver *ide_language_get_symbol_resolver      (IdeLanguage *self);
 GtkSourceLanguage *ide_language_get_source_language      (IdeLanguage *self);
 GList             *ide_language_get_completion_providers (IdeLanguage *self);
 
diff --git a/libide/ide.c b/libide/ide.c
index 508f94e..98b8bea 100644
--- a/libide/ide.c
+++ b/libide/ide.c
@@ -29,6 +29,7 @@
 #include "ide-c-language.h"
 #include "ide-clang-highlighter.h"
 #include "ide-clang-service.h"
+#include "ide-clang-symbol-resolver.h"
 #include "ide-ctags-highlighter.h"
 #include "ide-ctags-service.h"
 #include "ide-device-provider.h"
@@ -135,6 +136,16 @@ ide_init_ctor (void)
       g_free (name);
     }
 
+  ide_extension_point_implement ("org.gnome.builder.symbol-resolver.c",
+                                 IDE_TYPE_CLANG_SYMBOL_RESOLVER,
+                                 0);
+  ide_extension_point_implement ("org.gnome.builder.symbol-resolver.cpp",
+                                 IDE_TYPE_CLANG_SYMBOL_RESOLVER,
+                                 0);
+  ide_extension_point_implement ("org.gnome.builder.symbol-resolver.chdr",
+                                 IDE_TYPE_CLANG_SYMBOL_RESOLVER,
+                                 0);
+
   g_io_extension_point_implement (IDE_BUILD_SYSTEM_EXTENSION_POINT,
                                   IDE_TYPE_AUTOTOOLS_BUILD_SYSTEM,
                                   IDE_BUILD_SYSTEM_EXTENSION_POINT".autotools",
diff --git a/libide/ide.h b/libide/ide.h
index b5e6a17..f2b2b53 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -47,6 +47,7 @@ G_BEGIN_DECLS
 #include "ide-enums.h"
 #include "ide-executable.h"
 #include "ide-executer.h"
+#include "ide-extension-point.h"
 #include "ide-file.h"
 #include "ide-file-settings.h"
 #include "ide-global.h"
diff --git a/plugins/symbol-tree/symbol-tree.c b/plugins/symbol-tree/symbol-tree.c
index 866a720..54d3c8d 100644
--- a/plugins/symbol-tree/symbol-tree.c
+++ b/plugins/symbol-tree/symbol-tree.c
@@ -156,6 +156,28 @@ get_symbol_tree_cb (GObject      *object,
     g_task_return_pointer (task, g_object_ref (symbol_tree), g_object_unref);
 }
 
+static IdeSymbolResolver *
+get_symbol_resolver (IdeLanguage *language)
+{
+  IdeSymbolResolver *ret;
+  IdeContext *context;
+  const gchar *lang_id;
+  gchar *name;
+
+  g_assert (IDE_IS_LANGUAGE (language));
+
+  context = ide_object_get_context (IDE_OBJECT (language));
+
+  lang_id = ide_language_get_id (language);
+  name = g_strdup_printf ("org.gnome.builder.symbol-resolver.%s", lang_id);
+  ret = ide_extension_point_create (name,
+                                    "context", context,
+                                    NULL);
+  g_free (name);
+
+  return ret;
+}
+
 static void
 populate_cache_cb (EggTaskCache  *cache,
                    gconstpointer  key,
@@ -165,7 +187,7 @@ populate_cache_cb (EggTaskCache  *cache,
   GbEditorDocument *document = (GbEditorDocument *)key;
   IdeLanguage *language;
   IdeFile *file;
-  IdeSymbolResolver *resolver;
+  g_autoptr(IdeSymbolResolver) resolver = NULL;
 
   g_assert (EGG_IS_TASK_CACHE (cache));
   g_assert (GB_IS_EDITOR_DOCUMENT (document));
@@ -173,7 +195,7 @@ populate_cache_cb (EggTaskCache  *cache,
 
   if ((file = ide_buffer_get_file (IDE_BUFFER (document))) &&
       (language = ide_file_get_language (file)) &&
-      (resolver = ide_language_get_symbol_resolver (language)))
+      (resolver = get_symbol_resolver (language)))
     {
       ide_symbol_resolver_get_symbol_tree_async (resolver,
                                                  ide_file_get_file (file),


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