[gnome-builder: 62/139] c-pack: port to libide-editor
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder: 62/139] c-pack: port to libide-editor
- Date: Thu, 10 Jan 2019 04:22:32 +0000 (UTC)
commit fade53bf404fed71becc77bed4fa1fc094608c0e
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 9 17:04:38 2019 -0800
c-pack: port to libide-editor
This ports the c-pack plugin to the new libide-editor design and moves
the unit tests to be contained within the plugin directory.
src/plugins/c-pack/c-pack-plugin.c | 22 ++++--
src/plugins/c-pack/c-pack.gresource.xml | 2 +-
src/plugins/c-pack/c-pack.plugin | 15 ++--
src/plugins/c-pack/cpack-completion-item.c | 2 +-
src/plugins/c-pack/cpack-completion-item.h | 2 +-
src/plugins/c-pack/cpack-completion-provider.c | 11 +++
src/plugins/c-pack/cpack-completion-provider.h | 2 +-
src/plugins/c-pack/cpack-completion-results.h | 2 +-
...itor-view-addin.c => cpack-editor-page-addin.c} | 50 +++++++-------
...itor-view-addin.h => cpack-editor-page-addin.h} | 8 +--
src/plugins/c-pack/hdr-format.c | 11 ++-
src/plugins/c-pack/ide-c-indenter.c | 3 +-
src/plugins/c-pack/ide-c-indenter.h | 2 +-
src/plugins/c-pack/meson.build | 40 +++++++----
src/plugins/c-pack/test-cpack.c | 80 ++++++++++++++++++++++
src/plugins/c-pack/test-hdr-format.c | 47 +++++++++++++
16 files changed, 235 insertions(+), 64 deletions(-)
---
diff --git a/src/plugins/c-pack/c-pack-plugin.c b/src/plugins/c-pack/c-pack-plugin.c
index 80598351e..82bd8b2d2 100644
--- a/src/plugins/c-pack/c-pack-plugin.c
+++ b/src/plugins/c-pack/c-pack-plugin.c
@@ -18,16 +18,26 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
+#define G_LOG_DOMAIN "c-pack-plugin"
+
+#include <libide-editor.h>
+#include <libide-sourceview.h>
#include <libpeas/peas.h>
#include "ide-c-indenter.h"
#include "cpack-completion-provider.h"
-#include "cpack-editor-view-addin.h"
+#include "cpack-editor-page-addin.h"
-void
-ide_c_pack_register_types (PeasObjectModule *module)
+_IDE_EXTERN void
+_ide_c_pack_register_types (PeasObjectModule *module)
{
- peas_object_module_register_extension_type (module, IDE_TYPE_INDENTER, IDE_TYPE_C_INDENTER);
- peas_object_module_register_extension_type (module, IDE_TYPE_EDITOR_VIEW_ADDIN,
CPACK_TYPE_EDITOR_VIEW_ADDIN);
- peas_object_module_register_extension_type (module, IDE_TYPE_COMPLETION_PROVIDER,
CPACK_TYPE_COMPLETION_PROVIDER);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_INDENTER,
+ IDE_TYPE_C_INDENTER);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_EDITOR_PAGE_ADDIN,
+ CPACK_TYPE_EDITOR_PAGE_ADDIN);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_COMPLETION_PROVIDER,
+ CPACK_TYPE_COMPLETION_PROVIDER);
}
diff --git a/src/plugins/c-pack/c-pack.gresource.xml b/src/plugins/c-pack/c-pack.gresource.xml
index b7417949b..9cda0e405 100644
--- a/src/plugins/c-pack/c-pack.gresource.xml
+++ b/src/plugins/c-pack/c-pack.gresource.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
- <gresource prefix="/org/gnome/builder/plugins">
+ <gresource prefix="/plugins/c-pack">
<file>c-pack.plugin</file>
</gresource>
</gresources>
diff --git a/src/plugins/c-pack/c-pack.plugin b/src/plugins/c-pack/c-pack.plugin
index e8e0a0585..c99764211 100644
--- a/src/plugins/c-pack/c-pack.plugin
+++ b/src/plugins/c-pack/c-pack.plugin
@@ -1,11 +1,12 @@
[Plugin]
-Module=c-pack-plugin
-Name=C Language Enablement
-Description=Provides language support for the C programming language.
Authors=Christian Hergert <christian hergert me>
-Copyright=Copyright © 2015 Christian Hergert
Builtin=true
-X-Indenter-Languages=c,chdr
-X-Indenter-Languages-Priority=0
+Copyright=Copyright © 2015-2018 Christian Hergert
+Depends=editor;
+Description=Provides language support for the C programming language.
+Embedded=_ide_c_pack_register_types
+Module=c-pack
+Name=C Language Enablement
X-Completion-Provider-Languages=c,chdr,cpp,cpphdr
-Embedded=ide_c_pack_register_types
+X-Indenter-Languages-Priority=0
+X-Indenter-Languages=c,chdr
diff --git a/src/plugins/c-pack/cpack-completion-item.c b/src/plugins/c-pack/cpack-completion-item.c
index 86d5c952f..0d064e7dc 100644
--- a/src/plugins/c-pack/cpack-completion-item.c
+++ b/src/plugins/c-pack/cpack-completion-item.c
@@ -22,7 +22,7 @@
#include "config.h"
-#include <ide.h>
+#include <libide-sourceview.h>
#include "cpack-completion-item.h"
diff --git a/src/plugins/c-pack/cpack-completion-item.h b/src/plugins/c-pack/cpack-completion-item.h
index f064968f1..6252b9558 100644
--- a/src/plugins/c-pack/cpack-completion-item.h
+++ b/src/plugins/c-pack/cpack-completion-item.h
@@ -20,7 +20,7 @@
#pragma once
-#include <glib-object.h>
+#include <libide-sourceview.h>
G_BEGIN_DECLS
diff --git a/src/plugins/c-pack/cpack-completion-provider.c b/src/plugins/c-pack/cpack-completion-provider.c
index ed7313963..a2bb5325a 100644
--- a/src/plugins/c-pack/cpack-completion-provider.c
+++ b/src/plugins/c-pack/cpack-completion-provider.c
@@ -22,6 +22,8 @@
#include "config.h"
+#include <libide-sourceview.h>
+
#include "cpack-completion-item.h"
#include "cpack-completion-provider.h"
#include "cpack-completion-results.h"
@@ -46,6 +48,7 @@ cpack_completion_provider_init (CpackCompletionProvider *self)
{
}
+#if 0
static void
cpack_completion_provider_populate_cb (GObject *object,
GAsyncResult *result,
@@ -103,6 +106,7 @@ cpack_completion_provider_get_build_flags_cb (GObject *object,
cpack_completion_provider_populate_cb,
g_object_ref (task));
}
+#endif
static void
cpack_completion_provider_populate_async (IdeCompletionProvider *provider,
@@ -157,6 +161,12 @@ query_filesystem:
g_assert (IDE_IS_BUFFER (buffer));
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "TODO need access to build flags");
+
+#if 0
/*
* First step is to get our list of include paths from the CFLAGS for the
* file. After that, we can start looking for matches on the file-system
@@ -167,6 +177,7 @@ query_filesystem:
cancellable,
cpack_completion_provider_get_build_flags_cb,
g_steal_pointer (&task));
+#endif
}
static GListModel *
diff --git a/src/plugins/c-pack/cpack-completion-provider.h b/src/plugins/c-pack/cpack-completion-provider.h
index f70670347..283ba12a2 100644
--- a/src/plugins/c-pack/cpack-completion-provider.h
+++ b/src/plugins/c-pack/cpack-completion-provider.h
@@ -20,7 +20,7 @@
#pragma once
-#include <ide.h>
+#include <libide-core.h>
G_BEGIN_DECLS
diff --git a/src/plugins/c-pack/cpack-completion-results.h b/src/plugins/c-pack/cpack-completion-results.h
index a56c34303..9872dca1a 100644
--- a/src/plugins/c-pack/cpack-completion-results.h
+++ b/src/plugins/c-pack/cpack-completion-results.h
@@ -20,7 +20,7 @@
#pragma once
-#include <ide.h>
+#include <libide-sourceview.h>
G_BEGIN_DECLS
diff --git a/src/plugins/c-pack/cpack-editor-view-addin.c b/src/plugins/c-pack/cpack-editor-page-addin.c
similarity index 67%
rename from src/plugins/c-pack/cpack-editor-view-addin.c
rename to src/plugins/c-pack/cpack-editor-page-addin.c
index e98d57fa6..02577abee 100644
--- a/src/plugins/c-pack/cpack-editor-view-addin.c
+++ b/src/plugins/c-pack/cpack-editor-page-addin.c
@@ -1,4 +1,4 @@
-/* cpack-editor-view-addin.c
+/* cpack-editor-page-addin.c
*
* Copyright 2018-2019 Christian Hergert <chergert redhat com>
*
@@ -18,12 +18,16 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
-#define G_LOG_DOMAIN "cpack-editor-view-addin"
+#define G_LOG_DOMAIN "cpack-editor-page-addin"
-#include "cpack-editor-view-addin.h"
+#include "config.h"
+
+#include <libide-editor.h>
+
+#include "cpack-editor-page-addin.h"
#include "hdr-format.h"
-struct _CpackEditorViewAddin
+struct _CpackEditorPageAddin
{
GObject parent_instance;
};
@@ -33,17 +37,17 @@ format_decls_cb (GSimpleAction *action,
GVariant *param,
gpointer user_data)
{
- IdeEditorView *view = user_data;
+ IdeEditorPage *view = user_data;
g_autofree gchar *input = NULL;
g_autofree gchar *output = NULL;
IdeBuffer *buffer;
IdeSourceView *sourceview;
GtkTextIter begin, end;
- g_assert (IDE_IS_EDITOR_VIEW (view));
+ g_assert (IDE_IS_EDITOR_PAGE (view));
- buffer = ide_editor_view_get_buffer (view);
- sourceview = ide_editor_view_get_view (view);
+ buffer = ide_editor_page_get_buffer (view);
+ sourceview = ide_editor_page_get_view (view);
/* We require a selection */
if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), &begin, &end))
@@ -67,13 +71,13 @@ static GActionEntry entries[] = {
};
static void
-cpack_editor_view_addin_load (IdeEditorViewAddin *addin,
- IdeEditorView *view)
+cpack_editor_page_addin_load (IdeEditorPageAddin *addin,
+ IdeEditorPage *view)
{
g_autoptr(GActionMap) group = NULL;
- g_assert (CPACK_IS_EDITOR_VIEW_ADDIN (addin));
- g_assert (IDE_IS_EDITOR_VIEW (view));
+ g_assert (CPACK_IS_EDITOR_PAGE_ADDIN (addin));
+ g_assert (IDE_IS_EDITOR_PAGE (view));
group = G_ACTION_MAP (g_simple_action_group_new ());
g_action_map_add_action_entries (group, entries, G_N_ELEMENTS (entries), view);
@@ -81,31 +85,31 @@ cpack_editor_view_addin_load (IdeEditorViewAddin *addin,
}
static void
-cpack_editor_view_addin_unload (IdeEditorViewAddin *addin,
- IdeEditorView *view)
+cpack_editor_page_addin_unload (IdeEditorPageAddin *addin,
+ IdeEditorPage *view)
{
- g_assert (CPACK_IS_EDITOR_VIEW_ADDIN (addin));
- g_assert (IDE_IS_EDITOR_VIEW (view));
+ g_assert (CPACK_IS_EDITOR_PAGE_ADDIN (addin));
+ g_assert (IDE_IS_EDITOR_PAGE (view));
gtk_widget_insert_action_group (GTK_WIDGET (view), "cpack", NULL);
}
static void
-iface_init (IdeEditorViewAddinInterface *iface)
+iface_init (IdeEditorPageAddinInterface *iface)
{
- iface->load = cpack_editor_view_addin_load;
- iface->unload = cpack_editor_view_addin_unload;
+ iface->load = cpack_editor_page_addin_load;
+ iface->unload = cpack_editor_page_addin_unload;
}
-G_DEFINE_TYPE_WITH_CODE (CpackEditorViewAddin, cpack_editor_view_addin, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_VIEW_ADDIN, iface_init))
+G_DEFINE_TYPE_WITH_CODE (CpackEditorPageAddin, cpack_editor_page_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_PAGE_ADDIN, iface_init))
static void
-cpack_editor_view_addin_class_init (CpackEditorViewAddinClass *klass)
+cpack_editor_page_addin_class_init (CpackEditorPageAddinClass *klass)
{
}
static void
-cpack_editor_view_addin_init (CpackEditorViewAddin *self)
+cpack_editor_page_addin_init (CpackEditorPageAddin *self)
{
}
diff --git a/src/plugins/c-pack/cpack-editor-view-addin.h b/src/plugins/c-pack/cpack-editor-page-addin.h
similarity index 78%
rename from src/plugins/c-pack/cpack-editor-view-addin.h
rename to src/plugins/c-pack/cpack-editor-page-addin.h
index 485b8f37d..58f136870 100644
--- a/src/plugins/c-pack/cpack-editor-view-addin.h
+++ b/src/plugins/c-pack/cpack-editor-page-addin.h
@@ -1,4 +1,4 @@
-/* cpack-editor-view-addin.h
+/* cpack-editor-page-addin.h
*
* Copyright 2018-2019 Christian Hergert <chergert redhat com>
*
@@ -20,12 +20,12 @@
#pragma once
-#include <ide.h>
+#include <glib-object.h>
G_BEGIN_DECLS
-#define CPACK_TYPE_EDITOR_VIEW_ADDIN (cpack_editor_view_addin_get_type())
+#define CPACK_TYPE_EDITOR_PAGE_ADDIN (cpack_editor_page_addin_get_type())
-G_DECLARE_FINAL_TYPE (CpackEditorViewAddin, cpack_editor_view_addin, CPACK, EDITOR_VIEW_ADDIN, GObject)
+G_DECLARE_FINAL_TYPE (CpackEditorPageAddin, cpack_editor_page_addin, CPACK, EDITOR_PAGE_ADDIN, GObject)
G_END_DECLS
diff --git a/src/plugins/c-pack/hdr-format.c b/src/plugins/c-pack/hdr-format.c
index 33aa8cd5c..397e930ff 100644
--- a/src/plugins/c-pack/hdr-format.c
+++ b/src/plugins/c-pack/hdr-format.c
@@ -20,8 +20,7 @@
#define G_LOG_DOMAIN "hdr-format"
-#include <glib.h>
-#include <ide.h>
+#include <gtksourceview/gtksource.h>
#include <string.h>
#include "c-parse-helper.h"
@@ -211,7 +210,7 @@ push_chunk (GArray *ar,
str = pos;
chunk.return_type = g_strstrip (g_steal_pointer (&return_type));
-
+
if (!(ident = getword (str, &pos)))
goto failure;
if (*ident != '_' && !g_ascii_isalpha (*ident))
@@ -409,6 +408,12 @@ hdr_format_string (const gchar *data,
break;
}
+ if (p->type == NULL)
+ {
+ g_warning ("Unexpected NULL value for type");
+ continue;
+ }
+
g_string_append (out, p->type);
for (guint j = strlen (p->type); j < long_ptype; j++)
diff --git a/src/plugins/c-pack/ide-c-indenter.c b/src/plugins/c-pack/ide-c-indenter.c
index 5f2d73fac..c0e8ef46e 100644
--- a/src/plugins/c-pack/ide-c-indenter.c
+++ b/src/plugins/c-pack/ide-c-indenter.c
@@ -22,6 +22,7 @@
#include <glib/gi18n.h>
#include <libpeas/peas.h>
+#include <libide-sourceview.h>
#include "c-parse-helper.h"
#include "ide-c-indenter.h"
@@ -1358,7 +1359,7 @@ ide_c_indenter_format (IdeIndenter *indenter,
ret = c_indenter_indent (c, view, buffer, begin);
*begin = begin_copy;
- if (!dzl_str_empty0 (ret))
+ if (!ide_str_empty0 (ret))
{
/*
* If we have additional space after where our new indentation
diff --git a/src/plugins/c-pack/ide-c-indenter.h b/src/plugins/c-pack/ide-c-indenter.h
index fa9632e0e..774cc4864 100644
--- a/src/plugins/c-pack/ide-c-indenter.h
+++ b/src/plugins/c-pack/ide-c-indenter.h
@@ -20,7 +20,7 @@
#pragma once
-#include <ide.h>
+#include <libide-core.h>
G_BEGIN_DECLS
diff --git a/src/plugins/c-pack/meson.build b/src/plugins/c-pack/meson.build
index a97560126..a1f60fc9f 100644
--- a/src/plugins/c-pack/meson.build
+++ b/src/plugins/c-pack/meson.build
@@ -1,23 +1,35 @@
-if get_option('with_c_pack')
+if get_option('plugin_c_pack')
-c_pack_resources = gnome.compile_resources(
- 'c-pack-resources',
- 'c-pack.gresource.xml',
- c_name: 'ide_c',
-)
-
-c_pack_sources = [
+plugins_sources += files([
'c-pack-plugin.c',
'c-parse-helper.c',
- 'hdr-format.c',
- 'ide-c-indenter.c',
'cpack-completion-item.c',
'cpack-completion-provider.c',
'cpack-completion-results.c',
- 'cpack-editor-view-addin.c',
-]
+ 'cpack-editor-page-addin.c',
+ 'hdr-format.c',
+ 'ide-c-indenter.c',
+])
-gnome_builder_plugins_sources += files(c_pack_sources)
-gnome_builder_plugins_sources += c_pack_resources[0]
+plugin_c_pack_resources = gnome.compile_resources(
+ 'c-pack-resources',
+ 'c-pack.gresource.xml',
+ c_name: 'ide_c',
+)
+
+plugins_sources += plugin_c_pack_resources[0]
+
+test_cpack = executable('test-cpack',
+ 'test-cpack.c', 'c-parse-helper.c',
+ c_args: test_cflags,
+ dependencies: [ libide_projects_dep ],
+)
+test('test-cpack', test_cpack, env: test_env)
+
+test_hdr_format = executable('test-hdr-format',
+ 'test-hdr-format.c', 'c-parse-helper.c',
+ c_args: test_cflags,
+ dependencies: [ libide_sourceview_dep ],
+)
endif
diff --git a/src/plugins/c-pack/test-cpack.c b/src/plugins/c-pack/test-cpack.c
new file mode 100644
index 000000000..41ca6cebc
--- /dev/null
+++ b/src/plugins/c-pack/test-cpack.c
@@ -0,0 +1,80 @@
+/* test-cpack.c
+ *
+ * Copyright 2014-2019 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/>.
+ */
+
+#include "c-parse-helper.h"
+
+static void
+test_parse_parameters1 (void)
+{
+ gsize i;
+ GSList *ret;
+ GSList *iter;
+
+ static const struct
+ {
+ const gchar *type;
+ guint n_star;
+ const gchar *name;
+ guint ellipsis;
+ } result[]=
+ {
+ { "Item", 1, "a", 0 },
+ { "Item", 2, "b", 0 },
+ { "gpointer", 0, "u", 0 },
+ { "GError", 2, "error", 0 },
+ { NULL, 0, NULL, 1}
+ };
+
+ ret = parse_parameters ("Item *a , Item **b, gpointer u, GError ** error, ...");
+ g_assert_cmpint (5, ==, g_slist_length (ret));
+
+ for (i = 0, iter = ret; i < G_N_ELEMENTS (result); i++, iter = iter->next)
+ {
+ Parameter *p;
+
+ p = iter->data;
+ g_assert_cmpstr (p->type, ==, result[i].type);
+ g_assert_cmpint (p->n_star, ==, result[i].n_star);
+ g_assert_cmpstr (p->name, ==, result[i].name);
+ g_assert_cmpint (p->ellipsis, ==, result[i].ellipsis);
+ }
+
+ g_assert (!iter);
+
+ g_slist_foreach (ret, (GFunc)parameter_free, NULL);
+ g_slist_free (ret);
+}
+
+static void
+test_parse_parameters2 (void)
+{
+ GSList *ret;
+
+ ret = parse_parameters ("abc, def, ghi");
+ g_assert (!ret);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/Parser/C/parse_parameters1", test_parse_parameters1);
+ g_test_add_func ("/Parser/C/parse_parameters2", test_parse_parameters2);
+ return g_test_run ();
+}
diff --git a/src/plugins/c-pack/test-hdr-format.c b/src/plugins/c-pack/test-hdr-format.c
new file mode 100644
index 000000000..83295e70a
--- /dev/null
+++ b/src/plugins/c-pack/test-hdr-format.c
@@ -0,0 +1,47 @@
+/* test-hdr-format.c
+ *
+ * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ */
+
+#include "hdr-format.c"
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ g_autofree gchar *contents = NULL;
+ g_autofree gchar *ret = NULL;
+ g_autoptr(GError) error = NULL;
+ gsize len;
+
+ if (argc < 2)
+ {
+ g_printerr ("usage: %s FILENAME\n", argv[0]);
+ return 1;
+ }
+
+ if (!g_file_get_contents (argv[1], &contents, &len, &error))
+ {
+ g_printerr ("%s\n", error->message);
+ return 1;
+ }
+
+ ret = hdr_format_string (contents, len);
+
+ g_print ("%s\n", ret);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]