[gnome-builder/wip/chergert/layout: 70/118] symbol-resolver: add API to find nearest scope



commit 45244f3ba808b9fa9f0be14870b03e24a808afab
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jul 1 18:51:23 2017 -0700

    symbol-resolver: add API to find nearest scope
    
    This is a simple method for symbol resolvers to tell us the
    current scope based on a given cursor position. They may want
    to use the UnsavedFiles to get access to the updated buffer
    content but are not required to do so.

 libide/symbols/ide-symbol-resolver.c            |   89 +++++++++++++++++
 libide/symbols/ide-symbol-resolver.h            |  120 +++++++++++++----------
 plugins/vala-pack/ide-vala-symbol-resolver.vala |    7 ++
 3 files changed, 164 insertions(+), 52 deletions(-)
---
diff --git a/libide/symbols/ide-symbol-resolver.c b/libide/symbols/ide-symbol-resolver.c
index ce23f85..778e6b2 100644
--- a/libide/symbols/ide-symbol-resolver.c
+++ b/libide/symbols/ide-symbol-resolver.c
@@ -92,12 +92,45 @@ ide_symbol_resolver_real_find_references_finish (IdeSymbolResolver  *self,
 }
 
 static void
+ide_symbol_resolver_real_find_nearest_scope_async (IdeSymbolResolver   *self,
+                                                IdeSourceLocation   *location,
+                                                GCancellable        *cancellable,
+                                                GAsyncReadyCallback  callback,
+                                                gpointer             user_data)
+{
+  g_assert (IDE_IS_SYMBOL_RESOLVER (self));
+  g_assert (location != NULL);
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  g_task_report_new_error (self,
+                           callback,
+                           user_data,
+                           ide_symbol_resolver_real_find_nearest_scope_async,
+                           G_IO_ERROR,
+                           G_IO_ERROR_NOT_SUPPORTED,
+                           "Finding nearest scope is not supported for this language");
+}
+
+static IdeSymbol *
+ide_symbol_resolver_real_find_nearest_scope_finish (IdeSymbolResolver  *self,
+                                                 GAsyncResult       *result,
+                                                 GError            **error)
+{
+  g_assert (IDE_IS_SYMBOL_RESOLVER (self));
+  g_assert (G_IS_TASK (result));
+
+  return g_task_propagate_pointer (G_TASK (result), error);
+}
+
+static void
 ide_symbol_resolver_default_init (IdeSymbolResolverInterface *iface)
 {
   iface->get_symbol_tree_async = ide_symbol_resolver_real_get_symbol_tree_async;
   iface->get_symbol_tree_finish = ide_symbol_resolver_real_get_symbol_tree_finish;
   iface->find_references_async = ide_symbol_resolver_real_find_references_async;
   iface->find_references_finish = ide_symbol_resolver_real_find_references_finish;
+  iface->find_nearest_scope_async = ide_symbol_resolver_real_find_nearest_scope_async;
+  iface->find_nearest_scope_finish = ide_symbol_resolver_real_find_nearest_scope_finish;
 }
 
 /**
@@ -235,3 +268,59 @@ ide_symbol_resolver_find_references_finish (IdeSymbolResolver  *self,
 
   return IDE_SYMBOL_RESOLVER_GET_IFACE (self)->find_references_finish (self, result, error);
 }
+
+/**
+ * ide_symbol_resolver_find_nearest_scope_async:
+ * @self: a #IdeSymbolResolver
+ * @location: an #IdeSourceLocation
+ * @cancellable: (nullable): A #GCancellable or %NULL
+ * @callback: (scope async) (closure user_data): an async callback
+ * @user_data: user data for @callback
+ *
+ * This function asynchronously requests to locate the containing
+ * scope for a given source location.
+ *
+ * See ide_symbol_resolver_find_nearest_scope_finish() for how to
+ * complete the operation.
+ *
+ * Since: 3.26
+ */
+void
+ide_symbol_resolver_find_nearest_scope_async (IdeSymbolResolver    *self,
+                                              IdeSourceLocation    *location,
+                                              GCancellable         *cancellable,
+                                              GAsyncReadyCallback   callback,
+                                              gpointer              user_data)
+{
+  g_return_if_fail (IDE_IS_SYMBOL_RESOLVER (self));
+  g_return_if_fail (location != NULL);
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  IDE_SYMBOL_RESOLVER_GET_IFACE (self)->find_nearest_scope_async (self, location, cancellable, callback, 
user_data);
+}
+
+/**
+ * ide_symbol_resolver_find_nearest_scope_finish:
+ * @self: a #IdeSymbolResolver
+ * @result: a #GAsyncResult
+ * @error: a location for a #GError or %NULL
+ *
+ * This function completes an asynchronous operation to locate the containing
+ * scope for a given source location.
+ *
+ * See ide_symbol_resolver_find_nearest_scope_async() for more information.
+ *
+ * Returns: (transfer full) (nullable): An #IdeSymbol or %NULL
+ *
+ * Since: 3.26
+ */
+IdeSymbol *
+ide_symbol_resolver_find_nearest_scope_finish (IdeSymbolResolver  *self,
+                                               GAsyncResult       *result,
+                                               GError            **error)
+{
+  g_return_val_if_fail (IDE_IS_SYMBOL_RESOLVER (self), NULL);
+  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
+
+  return IDE_SYMBOL_RESOLVER_GET_IFACE (self)->find_nearest_scope_finish (self, result, error);
+}
diff --git a/libide/symbols/ide-symbol-resolver.h b/libide/symbols/ide-symbol-resolver.h
index 9a95d48..c638918 100644
--- a/libide/symbols/ide-symbol-resolver.h
+++ b/libide/symbols/ide-symbol-resolver.h
@@ -32,60 +32,76 @@ struct _IdeSymbolResolverInterface
 {
   GTypeInterface parent_interface;
 
-  void           (*lookup_symbol_async)    (IdeSymbolResolver    *self,
-                                            IdeSourceLocation    *location,
-                                            GCancellable         *cancellable,
-                                            GAsyncReadyCallback   callback,
-                                            gpointer              user_data);
-  IdeSymbol     *(*lookup_symbol_finish)   (IdeSymbolResolver    *self,
-                                            GAsyncResult         *result,
-                                            GError              **error);
-  void           (*get_symbol_tree_async)  (IdeSymbolResolver    *self,
-                                            GFile                *file,
-                                            IdeBuffer            *buffer,
-                                            GCancellable         *cancellable,
-                                            GAsyncReadyCallback   callback,
-                                            gpointer              user_data);
-  IdeSymbolTree *(*get_symbol_tree_finish) (IdeSymbolResolver    *self,
-                                            GAsyncResult         *result,
-                                            GError              **error);
-  void           (*load)                   (IdeSymbolResolver    *self);
-  void           (*find_references_async)  (IdeSymbolResolver    *self,
-                                            IdeSourceLocation    *location,
-                                            GCancellable         *cancellable,
-                                            GAsyncReadyCallback   callback,
-                                            gpointer              user_data);
-  GPtrArray     *(*find_references_finish) (IdeSymbolResolver    *self,
-                                            GAsyncResult         *result,
-                                            GError              **error);
+  void           (*lookup_symbol_async)      (IdeSymbolResolver    *self,
+                                              IdeSourceLocation    *location,
+                                              GCancellable         *cancellable,
+                                              GAsyncReadyCallback   callback,
+                                              gpointer              user_data);
+  IdeSymbol     *(*lookup_symbol_finish)     (IdeSymbolResolver    *self,
+                                              GAsyncResult         *result,
+                                              GError              **error);
+  void           (*get_symbol_tree_async)    (IdeSymbolResolver    *self,
+                                              GFile                *file,
+                                              IdeBuffer            *buffer,
+                                              GCancellable         *cancellable,
+                                              GAsyncReadyCallback   callback,
+                                              gpointer              user_data);
+  IdeSymbolTree *(*get_symbol_tree_finish)   (IdeSymbolResolver    *self,
+                                              GAsyncResult         *result,
+                                              GError              **error);
+  void           (*load)                     (IdeSymbolResolver    *self);
+  void           (*find_references_async)    (IdeSymbolResolver    *self,
+                                              IdeSourceLocation    *location,
+                                              GCancellable         *cancellable,
+                                              GAsyncReadyCallback   callback,
+                                              gpointer              user_data);
+  GPtrArray     *(*find_references_finish)   (IdeSymbolResolver    *self,
+                                              GAsyncResult         *result,
+                                              GError              **error);
+  void           (*find_nearest_scope_async) (IdeSymbolResolver    *self,
+                                              IdeSourceLocation    *location,
+                                              GCancellable         *cancellable,
+                                              GAsyncReadyCallback   callback,
+                                              gpointer              user_data);
+  IdeSymbol     *(*find_nearest_scope_finish) (IdeSymbolResolver    *self,
+                                              GAsyncResult         *result,
+                                              GError              **error);
 };
 
-void           ide_symbol_resolver_load                   (IdeSymbolResolver    *self);
-void           ide_symbol_resolver_lookup_symbol_async    (IdeSymbolResolver    *self,
-                                                           IdeSourceLocation    *location,
-                                                           GCancellable         *cancellable,
-                                                           GAsyncReadyCallback   callback,
-                                                           gpointer              user_data);
-IdeSymbol     *ide_symbol_resolver_lookup_symbol_finish   (IdeSymbolResolver    *self,
-                                                           GAsyncResult         *result,
-                                                           GError              **error);
-void           ide_symbol_resolver_get_symbol_tree_async  (IdeSymbolResolver    *self,
-                                                           GFile                *file,
-                                                           IdeBuffer            *buffer,
-                                                           GCancellable         *cancellable,
-                                                           GAsyncReadyCallback   callback,
-                                                           gpointer              user_data);
-IdeSymbolTree *ide_symbol_resolver_get_symbol_tree_finish (IdeSymbolResolver    *self,
-                                                           GAsyncResult         *result,
-                                                           GError              **error);
-void           ide_symbol_resolver_find_references_async  (IdeSymbolResolver    *self,
-                                                           IdeSourceLocation    *location,
-                                                           GCancellable         *cancellable,
-                                                           GAsyncReadyCallback   callback,
-                                                           gpointer              user_data);
-GPtrArray     *ide_symbol_resolver_find_references_finish (IdeSymbolResolver    *self,
-                                                           GAsyncResult         *result,
-                                                           GError              **error);
+void           ide_symbol_resolver_load                      (IdeSymbolResolver    *self);
+void           ide_symbol_resolver_lookup_symbol_async       (IdeSymbolResolver    *self,
+                                                              IdeSourceLocation    *location,
+                                                              GCancellable         *cancellable,
+                                                              GAsyncReadyCallback   callback,
+                                                              gpointer              user_data);
+IdeSymbol     *ide_symbol_resolver_lookup_symbol_finish      (IdeSymbolResolver    *self,
+                                                              GAsyncResult         *result,
+                                                              GError              **error);
+void           ide_symbol_resolver_get_symbol_tree_async     (IdeSymbolResolver    *self,
+                                                              GFile                *file,
+                                                              IdeBuffer            *buffer,
+                                                              GCancellable         *cancellable,
+                                                              GAsyncReadyCallback   callback,
+                                                              gpointer              user_data);
+IdeSymbolTree *ide_symbol_resolver_get_symbol_tree_finish    (IdeSymbolResolver    *self,
+                                                              GAsyncResult         *result,
+                                                              GError              **error);
+void           ide_symbol_resolver_find_references_async     (IdeSymbolResolver    *self,
+                                                              IdeSourceLocation    *location,
+                                                              GCancellable         *cancellable,
+                                                              GAsyncReadyCallback   callback,
+                                                              gpointer              user_data);
+GPtrArray     *ide_symbol_resolver_find_references_finish    (IdeSymbolResolver    *self,
+                                                              GAsyncResult         *result,
+                                                              GError              **error);
+void           ide_symbol_resolver_find_nearest_scope_async  (IdeSymbolResolver    *self,
+                                                              IdeSourceLocation    *location,
+                                                              GCancellable         *cancellable,
+                                                              GAsyncReadyCallback   callback,
+                                                              gpointer              user_data);
+IdeSymbol     *ide_symbol_resolver_find_nearest_scope_finish (IdeSymbolResolver    *self,
+                                                              GAsyncResult         *result,
+                                                              GError              **error);
 
 G_END_DECLS
 
diff --git a/plugins/vala-pack/ide-vala-symbol-resolver.vala b/plugins/vala-pack/ide-vala-symbol-resolver.vala
index 621e480..982a9b7 100644
--- a/plugins/vala-pack/ide-vala-symbol-resolver.vala
+++ b/plugins/vala-pack/ide-vala-symbol-resolver.vala
@@ -118,6 +118,13 @@ namespace Ide
                {
                        return new GLib.GenericArray<weak Ide.SourceRange> ();
                }
+
+               public async Ide.Symbol? find_nearest_scope_async (Ide.SourceLocation location,
+                                                                  GLib.Cancellable? cancellable)
+                       throws GLib.Error
+               {
+                       throw new GLib.IOError.NOT_SUPPORTED ("finding nearest scope is not yet supported");
+               }
        }
 }
 


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