[gnome-builder] sourceview: as stub implementation of goto-symbol



commit 2fdff02460a5f935352ebb2f7a08fa943ffea771
Author: Christian Hergert <christian hergert me>
Date:   Fri Mar 27 03:25:50 2015 -0700

    sourceview: as stub implementation of goto-symbol
    
    In vim (with ctags), ctrl+] jumps to the definition. This does that as well
    except we don't actually load the new location yet (just print it to
    console until we have necessary plumbing in place).

 data/keybindings/vim.css |    3 ++
 libide/ide-source-view.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++
 libide/ide-source-view.h |    1 +
 3 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index d6169e7..912a2eb 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -297,6 +297,9 @@
   /* macro recording! */
   bind "q" { "set-mode" ("vim-normal-q", transient) };
 
+  /* goto definition (or follow-link, really) */
+  bind "<ctrl>bracketright" { "goto-definition" () };
+
   /* submode for bracket */
   bind "bracketleft" { "set-mode" ("vim-normal-bracket", transient) };
 
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index d4c53ab..00339c6 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -55,6 +55,7 @@
 #include "ide-source-view-capture.h"
 #include "ide-source-view-mode.h"
 #include "ide-source-view-movements.h"
+#include "ide-symbol.h"
 
 #include "modeline-parser.h"
 
@@ -206,6 +207,7 @@ enum {
   DELETE_SELECTION,
   END_MACRO,
   END_USER_ACTION,
+  GOTO_DEFINITION,
   HIDE_COMPLETION,
   INDENT_SELECTION,
   INSERT_AT_CURSOR_AND_INDENT,
@@ -4399,6 +4401,53 @@ in_replay:
 }
 
 static void
+ide_source_view_goto_definition_symbol_cb (GObject      *object,
+                                           GAsyncResult *result,
+                                           gpointer      user_data)
+{
+  IdeBuffer *buffer = (IdeBuffer *)object;
+  g_autoptr(IdeSourceView) self = user_data;
+  g_autoptr(IdeSymbol) symbol = NULL;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (IDE_IS_BUFFER (buffer));
+  g_assert (IDE_IS_SOURCE_VIEW (self));
+
+  symbol = ide_buffer_get_symbol_at_location_finish (buffer, result, &error);
+
+  if (symbol == NULL)
+    {
+      g_warning ("%s", error->message);
+      return;
+    }
+
+  g_print ("Symbol: %s\n", ide_symbol_get_name (symbol));
+}
+
+static void
+ide_source_view_real_goto_definition (IdeSourceView *self)
+{
+  IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
+
+  g_assert (IDE_IS_SOURCE_VIEW (self));
+
+  if (priv->buffer != NULL)
+    {
+      GtkTextMark *insert;
+      GtkTextIter iter;
+
+      insert = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (priv->buffer));
+      gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->buffer), &iter, insert);
+
+      ide_buffer_get_symbol_at_location_async (priv->buffer,
+                                               &iter,
+                                               NULL,
+                                               ide_source_view_goto_definition_symbol_cb,
+                                               g_object_ref (self));
+    }
+}
+
+static void
 ide_source_view_real_hide_completion (IdeSourceView *self)
 {
   GtkSourceCompletion *completion;
@@ -4966,6 +5015,7 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
   klass->cycle_completion = ide_source_view_real_cycle_completion;
   klass->delete_selection = ide_source_view_real_delete_selection;
   klass->end_macro = ide_source_view_real_end_macro;
+  klass->goto_definition = ide_source_view_real_goto_definition;
   klass->hide_completion = ide_source_view_real_hide_completion;
   klass->indent_selection = ide_source_view_real_indent_selection;
   klass->insert_at_cursor_and_indent = ide_source_view_real_insert_at_cursor_and_indent;
@@ -5340,6 +5390,16 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
                                 G_TYPE_NONE,
                                 0);
 
+  gSignals [GOTO_DEFINITION] =
+    g_signal_new ("goto-definition",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                  G_STRUCT_OFFSET (IdeSourceViewClass, goto_definition),
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE,
+                  0);
+
   gSignals [HIDE_COMPLETION] =
     g_signal_new ("hide-completion",
                   G_TYPE_FROM_CLASS (klass),
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index 0704fb5..f9aeb69 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -219,6 +219,7 @@ struct _IdeSourceViewClass
                                        GtkDirectionType         direction);
   void (*delete_selection)            (IdeSourceView           *self);
   void (*end_macro)                   (IdeSourceView           *self);
+  void (*goto_definition)             (IdeSourceView           *self);
   void (*hide_completion)             (IdeSourceView           *self);
   void (*indent_selection)            (IdeSourceView           *self,
                                        gint                     level);


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