[gnome-builder/wip/slaf/xml-pack: 234/254] xml-pack: get the node path in the completion provider
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/slaf/xml-pack: 234/254] xml-pack: get the node path in the completion provider
- Date: Thu, 13 Jul 2017 09:08:52 +0000 (UTC)
commit 7046a5641fecafbb29b1ec071760560f40f3d165
Author: Sebastien Lafargue <slafargue gnome org>
Date: Sat May 20 19:56:09 2017 +0200
xml-pack: get the node path in the completion provider
plugins/xml-pack/ide-xml-completion-provider.c | 39 +++++++++++++++++++++++-
1 files changed, 38 insertions(+), 1 deletions(-)
---
diff --git a/plugins/xml-pack/ide-xml-completion-provider.c b/plugins/xml-pack/ide-xml-completion-provider.c
index e82ff2d..6f4ab6a 100644
--- a/plugins/xml-pack/ide-xml-completion-provider.c
+++ b/plugins/xml-pack/ide-xml-completion-provider.c
@@ -21,6 +21,7 @@
#include <libpeas/peas.h>
#include "ide-xml-completion-provider.h"
+#include "ide-xml-path.h"
#include "ide-xml-position.h"
#include "ide-xml-service.h"
@@ -66,6 +67,31 @@ populate_state_free (PopulateState *state)
g_object_unref (state->buffer);
}
+static IdeXmlPath *
+get_path (IdeXmlSymbolNode *node,
+ IdeXmlSymbolNode *root_node)
+{
+ IdeXmlPath *path;
+ IdeXmlSymbolNode *current = node;
+
+ g_assert (IDE_IS_XML_SYMBOL_NODE (node));
+ g_assert (IDE_IS_XML_SYMBOL_NODE (root_node));
+
+ path = ide_xml_path_new ();
+ while (current != NULL && current != root_node)
+ {
+ ide_xml_path_prepend_node (path, current);
+ current = ide_xml_symbol_node_get_parent (current);
+ }
+
+ if (current == root_node)
+ ide_xml_path_prepend_node (path, current);
+ else
+ g_warning ("partial path, we don't reach the root node");
+
+ return path;
+}
+
static void
populate_cb (GObject *object,
GAsyncResult *result,
@@ -75,6 +101,10 @@ populate_cb (GObject *object,
PopulateState *state = (PopulateState *)user_data;
IdeXmlCompletionProvider *self = state->self;
g_autoptr (IdeXmlPosition) position = NULL;
+ IdeXmlSymbolNode *root_node, *node;
+ IdeXmlAnalysis *analysis;
+ IdeXmlPositionKind kind;
+ IdeXmlPath *path;
GtkSourceCompletionItem *item;
g_autofree gchar *text = NULL;
g_autofree gchar *label = NULL;
@@ -85,6 +115,13 @@ populate_cb (GObject *object,
g_assert (IDE_IS_XML_SERVICE (service));
position = ide_xml_service_get_position_from_cursor_finish (service, result, &error);
+ analysis = ide_xml_position_get_analysis (position);
+ root_node = ide_xml_analysis_get_root_node (analysis);
+ node = ide_xml_position_get_node (position);
+ kind = ide_xml_position_get_kind (position);
+
+ path = get_path (node, root_node);
+
text = g_strdup ("xml item text");
label = g_strdup ("xml item label");
item = g_object_new (GTK_SOURCE_TYPE_COMPLETION_ITEM,
@@ -92,8 +129,8 @@ populate_cb (GObject *object,
"label", label,
NULL);
- /* TODO: show position content for debug */
ide_xml_position_print (position);
+ ide_xml_path_dump (path);
results = g_list_prepend (results, item);
gtk_source_completion_context_add_proposals (state->completion_context,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]