[gnome-builder/wip/code-assistance: 3/5] code-assist: add plumbing for code-assist module.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/code-assistance: 3/5] code-assist: add plumbing for code-assist module.
- Date: Mon, 20 Oct 2014 22:34:22 +0000 (UTC)
commit 3db950dc31a39741d7e62c2f910a0fa9a461c0cc
Author: Christian Hergert <christian hergert me>
Date: Sat Oct 18 13:32:44 2014 -0700
code-assist: add plumbing for code-assist module.
src/code-assistant/gb-source-code-assistant.c | 284 -------------------------
src/code-assistant/gb-source-code-assistant.h | 56 -----
src/editor/gb-editor-code-assistant.c | 109 ++++++++++
src/editor/gb-editor-code-assistant.h | 31 +++
src/editor/gb-editor-tab-private.h | 7 +
src/editor/gb-editor-tab.c | 31 +++-
src/gnome-builder.mk | 5 +-
7 files changed, 179 insertions(+), 344 deletions(-)
---
diff --git a/src/editor/gb-editor-code-assistant.c b/src/editor/gb-editor-code-assistant.c
new file mode 100644
index 0000000..71e03f4
--- /dev/null
+++ b/src/editor/gb-editor-code-assistant.c
@@ -0,0 +1,109 @@
+/* gb-editor-code-assistant.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "code-assistant"
+
+#include "gb-editor-code-assistant.h"
+#include "gb-editor-tab-private.h"
+#include "gb-log.h"
+#include "gca-service.h"
+
+static void
+gb_editor_code_assistant_buffer_changed (GbEditorDocument *document,
+ GbEditorTab *tab)
+{
+ g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+ g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+
+}
+
+/**
+ * gb_editor_code_assistant_init:
+ *
+ * Initializes the code assistant based on the open file, source language,
+ * and document buffer.
+ *
+ * This will hook to the gnome-code-assistance service to provide warnings
+ * if possible.
+ */
+void
+gb_editor_code_assistant_init (GbEditorTab *tab)
+{
+ GbEditorTabPrivate *priv;
+ GtkSourceLanguage *language;
+ const gchar *lang_id;
+ gchar *name;
+ gchar *path;
+
+ ENTRY;
+
+ g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+ g_return_if_fail (!tab->priv->gca_service);
+
+ priv = tab->priv;
+
+ language = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (priv->document));
+ if (!language)
+ EXIT;
+
+ lang_id = gtk_source_language_get_id (language);
+ name = g_strdup_printf ("org.gnome.CodeAssist.v1.%s", lang_id);
+ path = g_strdup_printf ("/org/gnome/CodeAssist/v1/%s", lang_id);
+
+ priv->gca_service =
+ gca_service_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ name, path, NULL, NULL);
+
+ g_free (name);
+ g_free (path);
+
+ if (!priv->gca_service)
+ {
+ g_message ("No code assistance found for language \"%s\"", lang_id);
+ EXIT;
+ }
+
+ priv->gca_buffer_changed_handler =
+ g_signal_connect (priv->document, "changed",
+ G_CALLBACK (gb_editor_code_assistant_buffer_changed),
+ tab);
+}
+
+void
+gb_editor_code_assistant_destroy (GbEditorTab *tab)
+{
+ GbEditorTabPrivate *priv;
+
+ ENTRY;
+
+ g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+ priv = tab->priv;
+
+ g_clear_object (&priv->gca_service);
+
+ if (priv->gca_buffer_changed_handler)
+ {
+ g_signal_handler_disconnect (priv->document,
+ priv->gca_buffer_changed_handler);
+ priv->gca_buffer_changed_handler = 0;
+ }
+
+ EXIT;
+}
diff --git a/src/editor/gb-editor-code-assistant.h b/src/editor/gb-editor-code-assistant.h
new file mode 100644
index 0000000..aa65e5e
--- /dev/null
+++ b/src/editor/gb-editor-code-assistant.h
@@ -0,0 +1,31 @@
+/* gb-editor-code-assistant.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GB_EDITOR_CODE_ASSISTANT_H
+#define GB_EDITOR_CODE_ASSISTANT_H
+
+#include "gb-editor-tab.h"
+
+G_BEGIN_DECLS
+
+void gb_editor_code_assistant_init (GbEditorTab *editor_tab);
+void gb_editor_code_assistant_destroy (GbEditorTab *editor_tab);
+
+G_END_DECLS
+
+#endif /* GB_EDITOR_CODE_ASSISTANT_H */
diff --git a/src/editor/gb-editor-tab-private.h b/src/editor/gb-editor-tab-private.h
index 2854b3e..65ce8fa 100644
--- a/src/editor/gb-editor-tab-private.h
+++ b/src/editor/gb-editor-tab-private.h
@@ -31,6 +31,7 @@
#include "gb-source-change-monitor.h"
#include "gb-source-search-highlighter.h"
#include "gb-source-view.h"
+#include "gca-service.h"
#include "gd-tagged-entry.h"
#include "nautilus-floating-bar.h"
@@ -101,6 +102,12 @@ struct _GbEditorTabPrivate
GtkSourceFile *file;
/*
+ * Code Assistance.
+ */
+ GcaService *gca_service;
+ gulong gca_buffer_changed_handler;
+
+ /*
* Animation for save progress.
*/
GbAnimation *save_animation;
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index 0947f04..c6541ee 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -21,6 +21,7 @@
#include <glib/gi18n.h>
#include <gtksourceview/completion-providers/words/gtksourcecompletionwords.h>
+#include "gb-editor-code-assistant.h"
#include "gb-editor-file-mark.h"
#include "gb-editor-file-marks.h"
#include "gb-editor-tab.h"
@@ -433,6 +434,23 @@ gb_editor_tab_cursor_moved (GbEditorTab *tab,
}
static void
+gb_editor_tab_language_changed (GbEditorTab *tab,
+ GParamSpec *pspec,
+ GtkSourceBuffer *buffer)
+{
+ GtkSourceLanguage *language;
+
+ g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+ g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
+
+ language = gtk_source_buffer_get_language (buffer);
+
+ gb_editor_code_assistant_destroy (tab);
+ if (language)
+ gb_editor_code_assistant_init (tab);
+}
+
+static void
gb_editor_tab_modified_changed (GbEditorTab *tab,
GtkTextBuffer *buffer)
{
@@ -1054,6 +1072,8 @@ transform_file_to_language (GBinding *binding,
language = gtk_source_language_manager_guess_language (manager, filename,
content_type);
+ gb_editor_code_assistant_destroy (tab);
+
/* TODO: This shouldn't be set here, this function shouldn't have
* side effects. But easy to plumb it until we clean this up.
*/
@@ -1066,6 +1086,9 @@ transform_file_to_language (GBinding *binding,
settings = gb_editor_settings_new_for_language (lang_id);
gb_editor_tab_set_settings (tab, settings);
g_object_unref (settings);
+
+
+ gb_editor_code_assistant_init (tab);
}
g_free (filename);
@@ -1170,6 +1193,10 @@ gb_editor_tab_constructed (GObject *object)
g_signal_connect_swapped (priv->document,
+ "notify::language",
+ G_CALLBACK (gb_editor_tab_language_changed),
+ tab);
+ g_signal_connect_swapped (priv->document,
"modified-changed",
G_CALLBACK (gb_editor_tab_modified_changed),
tab);
@@ -1408,10 +1435,11 @@ gb_editor_tab_dispose (GObject *object)
g_assert (GB_IS_EDITOR_TAB (tab));
+ gb_editor_code_assistant_destroy (tab);
+
gb_editor_tab_disconnect_settings (tab);
g_clear_object (&tab->priv->change_monitor);
- g_clear_object (&tab->priv->document);
g_clear_object (&tab->priv->search_entry_tag);
g_clear_object (&tab->priv->file);
g_clear_object (&tab->priv->search_highlighter);
@@ -1419,6 +1447,7 @@ gb_editor_tab_dispose (GObject *object)
g_clear_object (&tab->priv->search_context);
g_clear_object (&tab->priv->settings);
g_clear_object (&tab->priv->words_provider);
+ g_clear_object (&tab->priv->document);
G_OBJECT_CLASS (gb_editor_tab_parent_class)->dispose (object);
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 166db51..32dde7c 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -15,8 +15,6 @@ libgnome_builder_la_SOURCES = \
src/auto-indent/gb-source-auto-indenter-c.h \
src/auto-indent/gb-source-auto-indenter-xml.c \
src/auto-indent/gb-source-auto-indenter-xml.h \
- src/code-assistant/gb-source-code-assistant.c \
- src/code-assistant/gb-source-code-assistant.h \
src/commands/gb-command.c \
src/commands/gb-command.h \
src/commands/gb-command-bar.c \
@@ -43,6 +41,8 @@ libgnome_builder_la_SOURCES = \
src/devhelp/gb-devhelp-workspace.h \
src/editor/c-parse-helper.c \
src/editor/c-parse-helper.h \
+ src/editor/gb-editor-code-assistant.c \
+ src/editor/gb-editor-code-assistant.h \
src/editor/gb-editor-commands.c \
src/editor/gb-editor-commands.h \
src/editor/gb-editor-document.c \
@@ -181,7 +181,6 @@ libgnome_builder_la_CFLAGS = \
-I$(top_srcdir)/src/animation \
-I$(top_srcdir)/src/app \
-I$(top_srcdir)/src/auto-indent \
- -I$(top_srcdir)/src/code-assistant \
-I$(top_srcdir)/src/commands \
-I$(top_srcdir)/src/devhelp \
-I$(top_srcdir)/src/editor \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]